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.

231 lines
5.4KB

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