LadspaControls.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * LadspaControls.cpp - model for LADSPA plugin controls
  3. *
  4. * Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #include <QDomElement>
  25. #include "LadspaEffect.h"
  26. LadspaControls::LadspaControls( LadspaEffect * _eff ) :
  27. EffectControls( _eff ),
  28. m_effect( _eff ),
  29. m_processors( _eff->processorCount() ),
  30. m_noLink( false ),
  31. m_stereoLinkModel( true, this )
  32. {
  33. connect( &m_stereoLinkModel, SIGNAL( dataChanged() ),
  34. this, SLOT( updateLinkStatesFromGlobal() ),
  35. Qt::DirectConnection );
  36. multi_proc_t controls = m_effect->getPortControls();
  37. m_controlCount = controls.count();
  38. for( ch_cnt_t proc = 0; proc < m_processors; proc++ )
  39. {
  40. control_list_t p;
  41. const bool linked_control = ( m_processors > 1 && proc == 0 );
  42. for( multi_proc_t::Iterator it = controls.begin(); it != controls.end(); it++ )
  43. {
  44. if( (*it)->proc == proc )
  45. {
  46. (*it)->control = new LadspaControl( this, *it,
  47. linked_control );
  48. p.append( (*it)->control );
  49. if( linked_control )
  50. {
  51. connect( (*it)->control, SIGNAL( linkChanged( int, bool ) ),
  52. this, SLOT( linkPort( int, bool ) ),
  53. Qt::DirectConnection );
  54. }
  55. }
  56. }
  57. m_controls.append( p );
  58. }
  59. // now link all controls
  60. if( m_processors > 1 )
  61. {
  62. for( multi_proc_t::Iterator it = controls.begin();
  63. it != controls.end(); it++ )
  64. {
  65. if( (*it)->proc == 0 )
  66. {
  67. linkPort( ( *it )->control_id, true );
  68. }
  69. }
  70. }
  71. }
  72. LadspaControls::~LadspaControls()
  73. {
  74. for( ch_cnt_t proc = 0; proc < m_processors; proc++ )
  75. {
  76. m_controls[proc].clear();
  77. }
  78. m_controls.clear();
  79. }
  80. void LadspaControls::saveSettings( QDomDocument & _doc, QDomElement & _this )
  81. {
  82. if( m_processors > 1 )
  83. {
  84. _this.setAttribute( "link", m_stereoLinkModel.value() );
  85. }
  86. multi_proc_t controls = m_effect->getPortControls();
  87. _this.setAttribute( "ports", controls.count() );
  88. for( multi_proc_t::Iterator it = controls.begin();
  89. it != controls.end(); it++ )
  90. {
  91. QString n = "port" + QString::number( (*it)->proc ) +
  92. QString::number( (*it)->port_id );
  93. (*it)->control->saveSettings( _doc, _this, n );
  94. }
  95. }
  96. void LadspaControls::loadSettings( const QDomElement & _this )
  97. {
  98. if( m_processors > 1 )
  99. {
  100. m_stereoLinkModel.setValue( _this.attribute( "link" ).toInt() );
  101. }
  102. multi_proc_t controls = m_effect->getPortControls();
  103. for( multi_proc_t::Iterator it = controls.begin();
  104. it != controls.end(); it++ )
  105. {
  106. QString n = "port" + QString::number( (*it)->proc ) +
  107. QString::number( (*it)->port_id );
  108. (*it)->control->loadSettings( _this, n );
  109. }
  110. }
  111. void LadspaControls::linkPort( int _port, bool _state )
  112. {
  113. LadspaControl * first = m_controls[0][_port];
  114. if( _state )
  115. {
  116. for( ch_cnt_t proc = 1; proc < m_processors; proc++ )
  117. {
  118. first->linkControls( m_controls[proc][_port] );
  119. }
  120. }
  121. else
  122. {
  123. for( ch_cnt_t proc = 1; proc < m_processors; proc++ )
  124. {
  125. first->unlinkControls( m_controls[proc][_port] );
  126. }
  127. m_noLink = true;
  128. m_stereoLinkModel.setValue( false );
  129. }
  130. }
  131. void LadspaControls::updateLinkStatesFromGlobal()
  132. {
  133. if( m_stereoLinkModel.value() )
  134. {
  135. for( int port = 0; port < m_controlCount / m_processors; port++ )
  136. {
  137. m_controls[0][port]->setLink( true );
  138. }
  139. }
  140. else if( !m_noLink )
  141. {
  142. for( int port = 0; port < m_controlCount / m_processors; port++ )
  143. {
  144. m_controls[0][port]->setLink( false );
  145. }
  146. }
  147. // if global channel link state has changed, always ignore link
  148. // status of individual ports in the future
  149. m_noLink = false;
  150. }