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.

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