Non reinvents the DAW. Powerful enough to form a complete studio, fast and light enough to run on low-end hardware like the eeePC or Raspberry Pi, and so reliable that it can be used live https://non.tuxfamily.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
6.4KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2010 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include "Meter_Indicator_Module.H"
  19. #include <stdio.h>
  20. #include <FL/Fl.H>
  21. #include <FL/Fl_Value_Slider.H>
  22. #include <FL/Fl_Box.H>
  23. #include <FL/fl_draw.H>
  24. #include <FL/Fl_Counter.H>
  25. #include <FL/Fl_Light_Button.H>
  26. #include "FL/Fl_Dial.H"
  27. #include "FL/Fl_Labelpad_Group.H"
  28. #include "FL/Fl_Scalepack.H"
  29. #include "Engine/Engine.H"
  30. #include "Chain.H"
  31. #include "DPM.H"
  32. #include "FL/test_press.H"
  33. const float CONTROL_UPDATE_FREQ = 0.1f;
  34. Meter_Indicator_Module::Meter_Indicator_Module ( bool is_default )
  35. : Module ( is_default, 50, 100, name() )
  36. {
  37. box( FL_FLAT_BOX );
  38. color( FL_GREEN );
  39. _pad = true;
  40. control_value = 0;
  41. add_port( Port( this, Port::INPUT, Port::CONTROL ) );
  42. dpm_pack = new Fl_Scalepack( x(), y(), w(), h() );
  43. dpm_pack->type( FL_HORIZONTAL );
  44. end();
  45. control_value = new float[1];
  46. *control_value = -70.0f;
  47. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  48. clear_visible_focus();
  49. Fl::add_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  50. }
  51. Meter_Indicator_Module::~Meter_Indicator_Module ( )
  52. {
  53. if ( control_value )
  54. {
  55. delete[] control_value;
  56. control_value = NULL;
  57. }
  58. Fl::remove_timeout( update_cb, this );
  59. log_destroy();
  60. }
  61. void
  62. Meter_Indicator_Module::get ( Log_Entry &e ) const
  63. {
  64. Port *p = control_input[0].connected_port();
  65. Module *m = p->module();
  66. e.add( ":module", m );
  67. e.add( ":port", m->control_output_port_index( p ) );
  68. Module::get( e );
  69. }
  70. void
  71. Meter_Indicator_Module::set ( Log_Entry &e )
  72. {
  73. Module::set( e );
  74. int port = -1;
  75. Module *module = NULL;
  76. for ( int i = 0; i < e.size(); ++i )
  77. {
  78. const char *s, *v;
  79. e.get( i, &s, &v );
  80. if ( ! strcmp( s, ":port" ) )
  81. {
  82. port = atoi( v );
  83. }
  84. else if ( ! strcmp( s, ":module" ) )
  85. {
  86. int i;
  87. sscanf( v, "%X", &i );
  88. Module *t = (Module*)Loggable::find( i );
  89. assert( t );
  90. module = t;
  91. }
  92. }
  93. if ( port >= 0 && module )
  94. control_input[0].connect_to( &module->control_output[port] );
  95. }
  96. void
  97. Meter_Indicator_Module::update_cb ( void *v )
  98. {
  99. ((Meter_Indicator_Module*)v)->update_cb();
  100. }
  101. void
  102. Meter_Indicator_Module::update_cb ( void )
  103. {
  104. Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
  105. if ( control_input[0].connected() )
  106. {
  107. // A little hack to detect that the connected module's number
  108. // of control outs has changed.
  109. Port *p = control_input[0].connected_port();
  110. if ( dpm_pack->children() != p->hints.dimensions )
  111. {
  112. /* engine->lock(); */
  113. dpm_pack->clear();
  114. control_value = new float[p->hints.dimensions];
  115. for ( int i = p->hints.dimensions; i--; )
  116. {
  117. DPM *dpm = new DPM( x(), y(), w(), h() );
  118. dpm->type( FL_VERTICAL );
  119. dpm_pack->add( dpm );
  120. control_value[i] = -70.0f;
  121. dpm->value( -70.0f );
  122. }
  123. // redraw();
  124. /* engine->unlock(); */
  125. }
  126. else
  127. {
  128. for ( int i = 0; i < dpm_pack->children(); ++i )
  129. {
  130. ((DPM*)dpm_pack->child( i ))->value( control_value[i] );
  131. }
  132. }
  133. }
  134. }
  135. void
  136. Meter_Indicator_Module::connect_to ( Port *p )
  137. {
  138. control_input[0].connect_to( p );
  139. /* DPM *o = new DPM( 10, 10, 10, 10 ); */
  140. /* o->type( FL_VERTICAL ); */
  141. /* dpm_pack->add( o ); */
  142. redraw();
  143. }
  144. int
  145. Meter_Indicator_Module::handle ( int m )
  146. {
  147. switch ( m )
  148. {
  149. case FL_PUSH:
  150. {
  151. if ( Fl::event_button1() )
  152. {
  153. /* don't let Module::handle eat our click */
  154. return Fl_Group::handle( m );
  155. }
  156. }
  157. }
  158. return Module::handle( m );
  159. }
  160. void
  161. Meter_Indicator_Module::handle_control_changed ( Port *p )
  162. {
  163. THREAD_ASSERT( UI );
  164. /* The engine is already locked by the UI thread at this point in
  165. the call-graph, so we can be sure that process() won't be
  166. executed concurrently. */
  167. if ( p->connected() )
  168. {
  169. p = p->connected_port();
  170. if ( dpm_pack->children() != p->hints.dimensions )
  171. {
  172. dpm_pack->clear();
  173. control_value = new float[p->hints.dimensions];
  174. for ( int i = p->hints.dimensions; i--; )
  175. {
  176. DPM *dpm = new DPM( x(), y(), w(), h() );
  177. dpm->type( FL_VERTICAL );
  178. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
  179. dpm_pack->add( dpm );
  180. dpm_pack->redraw();
  181. control_value[i] = -70.0f;
  182. dpm->value( -70.0f );
  183. }
  184. redraw();
  185. }
  186. }
  187. }
  188. /**********/
  189. /* Engine */
  190. /**********/
  191. void
  192. Meter_Indicator_Module::process ( nframes_t )
  193. {
  194. if ( control_input[0].connected() )
  195. {
  196. Port *p = control_input[0].connected_port();
  197. for ( int i = 0; i < p->hints.dimensions; ++i )
  198. {
  199. control_value[i] = ((float*)control_input[0].buffer())[i];
  200. }
  201. }
  202. }