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.

230 lines
5.9KB

  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 <FL/Fl.H>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <math.h>
  23. #include <FL/fl_draw.H>
  24. #include "Module.H"
  25. #include "Spatialization_Console.H"
  26. #include "Controller_Module.H"
  27. #include "Chain.H"
  28. #include "Panner.H"
  29. #include "Mixer_Strip.H"
  30. #include "Mixer.H"
  31. #include "debug.h"
  32. #include <FL/Fl_Menu_Bar.H>
  33. Spatialization_Console::Spatialization_Console ( void ) : Fl_Double_Window( 850, 850 )
  34. {
  35. _resized = false;
  36. label( "Spatialization Console" );
  37. labelfont( FL_HELVETICA );
  38. labelsize( 14 );
  39. int padding = 48;
  40. int S = 802;
  41. if ( fl_display )
  42. /* don't open the display in noui mode... */
  43. {
  44. int sx, sy, sw, sh;
  45. Fl::screen_xywh( sx, sy, sw, sh );
  46. if ( sw < 850 || sh < 850 )
  47. {
  48. /* if screen isn't big enough, use smaller version of control */
  49. S = 502;
  50. }
  51. }
  52. panner = new Panner( 25,25, S, S );
  53. panner->callback( cb_panner_value_handle, this );
  54. panner->when( FL_WHEN_CHANGED );
  55. size( S + padding, S + padding );
  56. callback( cb_window, this );
  57. end();
  58. make_controls();
  59. mixer->spatialization_console = this;
  60. }
  61. Spatialization_Console::~Spatialization_Console ( )
  62. {
  63. // controls_by_port.clear();
  64. mixer->spatialization_console = NULL;
  65. }
  66. void
  67. Spatialization_Console::get ( Log_Entry &e ) const
  68. {
  69. e.add( ":range", panner->range() );
  70. e.add( ":projection", panner->projection() );
  71. e.add( ":shown", ((const Fl_Double_Window*)this)->shown() );
  72. }
  73. void
  74. Spatialization_Console::set ( Log_Entry &e )
  75. {
  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, ":range" ) ) )
  81. panner->range( atoi( v ) );
  82. if ( ! ( strcmp( s, ":projection" ) ) )
  83. panner->projection( atoi( v ) );
  84. else if ( ! ( strcmp( s, ":shown" ) ) )
  85. {
  86. if ( atoi( v ) )
  87. {
  88. if ( fl_display )
  89. {
  90. show();
  91. }
  92. }
  93. else
  94. hide();
  95. }
  96. }
  97. }
  98. void
  99. Spatialization_Console::cb_window ( Fl_Widget *w, void *v )
  100. {
  101. ((Spatialization_Console*)v)->cb_window(w);
  102. }
  103. void
  104. Spatialization_Console::cb_window ( Fl_Widget *w )
  105. {
  106. w->hide();
  107. mixer->update_menu();
  108. }
  109. void
  110. Spatialization_Console::make_controls ( void )
  111. {
  112. panner->clear_points();
  113. for ( int i = 0; i < mixer->nstrips(); i++ )
  114. {
  115. Mixer_Strip *o = mixer->track_by_number( i );
  116. if ( o->spatializer() )
  117. {
  118. Panner::Point p;
  119. p.color = o->color();
  120. p.userdata = o->spatializer();
  121. p.label = o->name();
  122. if ( o->spatializer()->is_controlling() )
  123. {
  124. p.visible = true;
  125. p.azimuth( o->spatializer()->control_output[0].control_value() );
  126. p.elevation( o->spatializer()->control_output[1].control_value() );
  127. if ( o->spatializer()->control_output[2].connected() )
  128. {
  129. p.radius_enabled = true;
  130. p.radius( o->spatializer()->control_output[2].control_value() );
  131. }
  132. }
  133. else
  134. p.visible = false;
  135. panner->add_point(p);
  136. }
  137. }
  138. panner->redraw();
  139. }
  140. void
  141. Spatialization_Console::cb_panner_value_handle ( Fl_Widget *w, void *v )
  142. {
  143. // callback_data *cd = (callback_data*)v;
  144. Spatialization_Console *sc = (Spatialization_Console*)v;
  145. Panner::Point *p = sc->panner->pushed();
  146. Controller_Module *cm = (Controller_Module*)p->userdata;
  147. cm->control_output[0].control_value( p->azimuth() );
  148. cm->control_output[1].control_value( p->elevation() );
  149. if ( p->radius_enabled )
  150. cm->control_output[2].control_value( p->radius() );
  151. }
  152. /* Display changes initiated via automation or from other parts of the GUI */
  153. void
  154. Spatialization_Console::handle_control_changed ( Controller_Module *m )
  155. {
  156. if ( Fl::pushed() == panner )
  157. return;
  158. for ( int i = 0; i < panner->points(); i++ )
  159. {
  160. Panner::Point *p = panner->point(i);
  161. if ( p->userdata == m )
  162. {
  163. p->azimuth( m->control_output[0].control_value() );
  164. p->elevation( m->control_output[1].control_value() );
  165. if ( p->radius_enabled )
  166. p->radius( m->control_output[2].control_value() );
  167. if ( panner->visible_r() )
  168. panner->redraw();
  169. break;
  170. }
  171. }
  172. }
  173. void
  174. Spatialization_Console::update ( void )
  175. {
  176. make_controls();
  177. }