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.

236 lines
5.6KB

  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. /* This is the main mixer group. It contains and manages Mixer_Strips. */
  19. #include "Mixer.H"
  20. #include "Mixer_Strip.H"
  21. #include <FL/Fl_Pack.H>
  22. #include <FL/Fl_Scroll.H>
  23. #include "Engine/Engine.H"
  24. #include <string.h>
  25. #include "debug.h"
  26. const double STATUS_UPDATE_FREQ = 0.2f;
  27. static Fl_Pack *mixer_strips;
  28. #include "util/debug.h"
  29. static void update_cb( void *v ) {
  30. Fl::repeat_timeout( STATUS_UPDATE_FREQ, update_cb, v );
  31. ((Mixer*)v)->update();
  32. }
  33. Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) :
  34. Fl_Group( X, Y, W, H, L )
  35. {
  36. box( FL_NO_BOX );
  37. labelsize( 96 );
  38. {
  39. Fl_Scroll *o = scroll = new Fl_Scroll( X, Y, W, H );
  40. o->box( FL_NO_BOX );
  41. o->type( Fl_Scroll::HORIZONTAL_ALWAYS );
  42. {
  43. Fl_Pack *o = mixer_strips = new Fl_Pack( X, Y, W, H - 18 );
  44. label( "Non-Mixer" );
  45. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE) );
  46. o->box( FL_NO_BOX );
  47. o->type( Fl_Pack::HORIZONTAL );
  48. o->spacing( 2 );
  49. o->end();
  50. Fl_Group::current()->resizable( o );
  51. }
  52. o->end();
  53. Fl_Group::current()->resizable( o );
  54. }
  55. end();
  56. // Fl::add_timeout( STATUS_UPDATE_FREQ, update_cb, this );
  57. MESSAGE( "Scanning for plugins..." );
  58. }
  59. Mixer::~Mixer ( )
  60. {
  61. /* FIXME: teardown */
  62. }
  63. void Mixer::resize ( int X, int Y, int W, int H )
  64. {
  65. Fl_Group::resize( X, Y, W, H );
  66. mixer_strips->resize( X, Y, W, H - 18 );
  67. scroll->resize( X, Y, W, H );
  68. }
  69. void Mixer::add ( Mixer_Strip *ms )
  70. {
  71. MESSAGE( "Add mixer strip \"%s\"", ms->name() );
  72. engine->lock();
  73. mixer_strips->add( ms );
  74. // mixer_strips->insert( *ms, 0 );
  75. engine->unlock();
  76. scroll->redraw();
  77. // redraw();
  78. }
  79. void Mixer::remove ( Mixer_Strip *ms )
  80. {
  81. MESSAGE( "Remove mixer strip \"%s\"", ms->name() );
  82. engine->lock();
  83. mixer_strips->remove( ms );
  84. engine->unlock();
  85. delete ms;
  86. parent()->redraw();
  87. }
  88. bool
  89. Mixer::contains ( Mixer_Strip *ms )
  90. {
  91. return ms->parent() == mixer_strips;
  92. }
  93. void Mixer::update ( void )
  94. {
  95. THREAD_ASSERT( UI );
  96. for ( int i = mixer_strips->children(); i--; )
  97. {
  98. ((Mixer_Strip*)mixer_strips->child( i ))->update();
  99. }
  100. // redraw();
  101. }
  102. void
  103. Mixer::process ( unsigned int nframes )
  104. {
  105. THREAD_ASSERT( RT );
  106. for ( int i = mixer_strips->children(); i--; )
  107. {
  108. ((Mixer_Strip*)mixer_strips->child( i ))->process( nframes );
  109. }
  110. }
  111. /** retrun a pointer to the track named /name/, or NULL if no track is named /name/ */
  112. Mixer_Strip *
  113. Mixer::track_by_name ( const char *name )
  114. {
  115. for ( int i = mixer_strips->children(); i-- ; )
  116. {
  117. Mixer_Strip *t = (Mixer_Strip*)mixer_strips->child( i );
  118. if ( ! strcmp( name, t->name() ) )
  119. return t;
  120. }
  121. return NULL;
  122. }
  123. /** return a malloc'd string representing a unique name for a new track */
  124. char *
  125. Mixer::get_unique_track_name ( const char *name )
  126. {
  127. char pat[256];
  128. strcpy( pat, name );
  129. for ( int i = 1; track_by_name( pat ); ++i )
  130. snprintf( pat, sizeof( pat ), "%s.%d", name, i );
  131. return strdup( pat );
  132. }
  133. void
  134. Mixer::snapshot ( void )
  135. {
  136. for ( int i = 0; i < mixer_strips->children(); ++i )
  137. ((Mixer_Strip*)mixer_strips->child( i ))->log_create();
  138. }
  139. void
  140. Mixer::new_strip ( void )
  141. {
  142. engine->lock();
  143. add( new Mixer_Strip( get_unique_track_name( "Unnamed" ), 1 ) );
  144. engine->unlock();
  145. // scroll->size( mixer_strips->w(), scroll->h() );
  146. }
  147. int
  148. Mixer::handle ( int m )
  149. {
  150. int r = Fl_Group::handle( m );
  151. switch ( m )
  152. {
  153. case FL_ENTER:
  154. case FL_LEAVE:
  155. return 1;
  156. case FL_SHORTCUT:
  157. {
  158. if ( Fl::event_key() == 'a' )
  159. {
  160. new_strip();
  161. return 1;
  162. }
  163. else if ( Fl::event_ctrl() && Fl::event_key() == 's' )
  164. {
  165. MESSAGE( "Saving state" );
  166. Loggable::snapshot_callback( &Mixer::snapshot, this );
  167. Loggable::snapshot( "save.mix" );
  168. return 1;
  169. }
  170. else
  171. return r;
  172. break;
  173. }
  174. default:
  175. return r;
  176. break;
  177. }
  178. // return 0;
  179. return r;
  180. }