LadspaControlDialog.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * LadspaControlDialog.cpp - dialog for displaying and editing control port
  3. * values for LADSPA plugins
  4. *
  5. * Copyright (c) 2006-2008 Danny McRae <khjklujn/at/users.sourceforge.net>
  6. * Copyright (c) 2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  7. *
  8. * This file is part of LMMS - https://lmms.io
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program (see COPYING); if not, write to the
  22. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  23. * Boston, MA 02110-1301 USA.
  24. *
  25. */
  26. #include <cmath>
  27. #include <QGroupBox>
  28. #include <QLayout>
  29. #include "LadspaEffect.h"
  30. #include "LadspaControlDialog.h"
  31. #include "LadspaControlView.h"
  32. #include "LedCheckbox.h"
  33. LadspaControlDialog::LadspaControlDialog( LadspaControls * _ctl ) :
  34. EffectControlDialog( _ctl ),
  35. m_effectLayout( NULL ),
  36. m_stereoLink( NULL )
  37. {
  38. QVBoxLayout * mainLay = new QVBoxLayout( this );
  39. m_effectLayout = new QHBoxLayout();
  40. mainLay->addLayout( m_effectLayout );
  41. updateEffectView( _ctl );
  42. if( _ctl->m_processors > 1 )
  43. {
  44. mainLay->addSpacing( 3 );
  45. QHBoxLayout * center = new QHBoxLayout();
  46. mainLay->addLayout( center );
  47. m_stereoLink = new LedCheckBox( tr( "Link Channels" ), this );
  48. m_stereoLink->setModel( &_ctl->m_stereoLinkModel );
  49. center->addWidget( m_stereoLink );
  50. }
  51. }
  52. LadspaControlDialog::~LadspaControlDialog()
  53. {
  54. }
  55. void LadspaControlDialog::updateEffectView( LadspaControls * _ctl )
  56. {
  57. QList<QGroupBox *> list = findChildren<QGroupBox *>();
  58. for( QList<QGroupBox *>::iterator it = list.begin(); it != list.end();
  59. ++it )
  60. {
  61. delete *it;
  62. }
  63. m_effectControls = _ctl;
  64. const int cols = static_cast<int>( sqrt(
  65. static_cast<double>( _ctl->m_controlCount /
  66. _ctl->m_processors ) ) );
  67. for( ch_cnt_t proc = 0; proc < _ctl->m_processors; proc++ )
  68. {
  69. control_list_t & controls = _ctl->m_controls[proc];
  70. int row = 0;
  71. int col = 0;
  72. buffer_data_t last_port = NONE;
  73. QGroupBox * grouper;
  74. if( _ctl->m_processors > 1 )
  75. {
  76. grouper = new QGroupBox( tr( "Channel " ) +
  77. QString::number( proc + 1 ),
  78. this );
  79. }
  80. else
  81. {
  82. grouper = new QGroupBox( this );
  83. }
  84. QGridLayout * gl = new QGridLayout( grouper );
  85. grouper->setLayout( gl );
  86. grouper->setAlignment( Qt::Vertical );
  87. for( control_list_t::iterator it = controls.begin();
  88. it != controls.end(); ++it )
  89. {
  90. if( (*it)->port()->proc == proc )
  91. {
  92. buffer_data_t this_port = (*it)->port()->data_type;
  93. if( last_port != NONE &&
  94. ( this_port == TOGGLED || this_port == ENUM ) &&
  95. ( last_port != TOGGLED && last_port != ENUM ) )
  96. {
  97. ++row;
  98. col = 0;
  99. }
  100. gl->addWidget( new LadspaControlView( grouper, *it ), row, col );
  101. if( ++col == cols )
  102. {
  103. ++row;
  104. col = 0;
  105. }
  106. last_port = (*it)->port()->data_type;
  107. }
  108. }
  109. m_effectLayout->addWidget( grouper );
  110. }
  111. if( _ctl->m_processors > 1 && m_stereoLink != NULL )
  112. {
  113. m_stereoLink->setModel( &_ctl->m_stereoLinkModel );
  114. }
  115. connect( _ctl, SIGNAL( effectModelChanged( LadspaControls * ) ),
  116. this, SLOT( updateEffectView( LadspaControls * ) ),
  117. Qt::DirectConnection );
  118. }