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.

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