Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
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.

195 lines
5.1KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2009 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 "Module.H"
  19. #include <FL/fl_draw.H>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <stdio.h>
  23. #include "Module_Parameter_Editor.H"
  24. Module::~Module ( )
  25. {
  26. for ( unsigned int i = 0; i < audio_input.size(); ++i )
  27. audio_input[i].disconnect();
  28. for ( unsigned int i = 0; i < audio_output.size(); ++i )
  29. audio_output[i].disconnect();
  30. for ( unsigned int i = 0; i < control_input.size(); ++i )
  31. control_input[i].disconnect();
  32. for ( unsigned int i = 0; i < control_output.size(); ++i )
  33. control_output[i].disconnect();
  34. audio_input.clear();
  35. audio_output.clear();
  36. control_input.clear();
  37. control_output.clear();
  38. }
  39. /* return a string serializing this module's parameter settings. The
  40. format is 1.0:2.0:... Where 1.0 is the value of the first control
  41. input, 2.0 is the value of the second control input etc.
  42. */
  43. char *
  44. Module::describe_inputs ( void ) const
  45. {
  46. char *s = new char[1024];
  47. s[0] = 0;
  48. char *sp = s;
  49. if ( control_input.size() )
  50. {
  51. for ( unsigned int i = 0; i < control_input.size(); ++i )
  52. sp += snprintf( sp, 1024 - (sp - s),"%f:", control_input[i].control_value() );
  53. *(sp - 1) = '\0';
  54. }
  55. return s;
  56. }
  57. void
  58. Module::draw_box ( void )
  59. {
  60. fl_color( FL_WHITE );
  61. int tw, th, tx, ty;
  62. tw = w();
  63. th = h();
  64. ty = y();
  65. tx = x();
  66. // bbox( tx, ty, tw, th );
  67. fl_push_clip( tx, ty, tw, th );
  68. int spacing = w() / instances();
  69. for ( int i = instances(); i--; )
  70. {
  71. fl_draw_box( box(), tx + (spacing * i), ty, tw / instances(), th, Fl::belowmouse() == this ? fl_lighter( color() ) : color() );
  72. }
  73. if ( audio_input.size() && audio_output.size() )
  74. {
  75. /* maybe draw control indicators */
  76. if ( control_input.size() )
  77. fl_draw_box( FL_ROUNDED_BOX, tx + 4, ty + 4, 5, 5, is_being_controlled() ? FL_YELLOW : fl_inactive( FL_YELLOW ) );
  78. if ( control_output.size() )
  79. fl_draw_box( FL_ROUNDED_BOX, tx + tw - 8, ty + 4, 5, 5, is_controlling() ? FL_YELLOW : fl_inactive( FL_YELLOW ) );
  80. }
  81. fl_pop_clip();
  82. // box( FL_NO_BOX );
  83. Fl_Group::draw_children();
  84. }
  85. void
  86. Module::draw_label ( void )
  87. {
  88. int tw, th, tx, ty;
  89. bbox( tx, ty, tw, th );
  90. const char *lp = label();
  91. int l = strlen( label() );
  92. fl_color( FL_FOREGROUND_COLOR );
  93. char *s = NULL;
  94. if ( l > 10 )
  95. {
  96. s = new char[l];
  97. char *sp = s;
  98. for ( ; *lp; ++lp )
  99. switch ( *lp )
  100. {
  101. case 'i': case 'e': case 'o': case 'u': case 'a':
  102. break;
  103. default:
  104. *(sp++) = *lp;
  105. }
  106. *sp = '\0';
  107. }
  108. if ( l > 20 )
  109. fl_font( FL_HELVETICA, 10 );
  110. else
  111. fl_font( FL_HELVETICA, 14 );
  112. fl_draw( s ? s : lp, tx, ty, tw, th, (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE) );
  113. if ( s )
  114. delete[] s;
  115. }
  116. #include "FL/test_press.H"
  117. int
  118. Module::handle ( int m )
  119. {
  120. switch ( m )
  121. {
  122. case FL_PUSH:
  123. {
  124. if ( test_press( FL_BUTTON1 ) )
  125. {
  126. if ( _editor )
  127. {
  128. _editor->show();
  129. }
  130. else if ( ncontrol_inputs() )
  131. {
  132. DMESSAGE( "Opening module parameters for \"%s\"", label() );
  133. _editor = new Module_Parameter_Editor( this );
  134. _editor->show();
  135. do { Fl::wait(); }
  136. while ( _editor->shown() );
  137. DMESSAGE( "Module parameters for \"%s\" closed",label() );
  138. delete _editor;
  139. _editor = NULL;
  140. }
  141. return 1;
  142. }
  143. break;
  144. }
  145. }
  146. return Fl_Group::handle( m );
  147. }