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.

307 lines
7.2KB

  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. if (! strcmp( picked, "&Project/&Quit") )
  63. {
  64. quit();
  65. }
  66. else if ( !strcmp( picked, "&Mixer/&Add Strip" ) )
  67. {
  68. new_strip();
  69. }
  70. }
  71. void Mixer::cb_menu(Fl_Widget* o, void* v) {
  72. ((Mixer*)(v))->cb_menu(o);
  73. }
  74. Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) :
  75. Fl_Group( X, Y, W, H, L )
  76. {
  77. box( FL_NO_BOX );
  78. labelsize( 96 );
  79. { Fl_Menu_Bar *o = new Fl_Menu_Bar( X, Y, W, 24 );
  80. o->add( "&Project/&New" );
  81. o->add( "&Project/&Open" );
  82. o->add( "&Project/&Save", FL_CTRL + 's', 0, 0 );
  83. o->add( "&Project/&Quit", FL_CTRL + 'q', 0, 0 );
  84. o->add( "&Mixer/&Add Strip", 'a', 0, 0 );
  85. o->add( "&Options" );
  86. o->callback( cb_menu, this );
  87. }
  88. { Fl_Scroll *o = scroll = new Fl_Scroll( X, Y + 24, W, H - 24 );
  89. o->box( FL_NO_BOX );
  90. o->type( Fl_Scroll::HORIZONTAL_ALWAYS );
  91. {
  92. Fl_Pack *o = mixer_strips = new Fl_Pack( X, Y + 24, W, H - 18 - 24 );
  93. label( "Non-Mixer" );
  94. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE) );
  95. o->box( FL_NO_BOX );
  96. o->type( Fl_Pack::HORIZONTAL );
  97. o->spacing( 2 );
  98. o->end();
  99. Fl_Group::current()->resizable( o );
  100. }
  101. o->end();
  102. Fl_Group::current()->resizable( o );
  103. }
  104. end();
  105. // Fl::add_timeout( STATUS_UPDATE_FREQ, update_cb, this );
  106. MESSAGE( "Scanning for plugins..." );
  107. }
  108. Mixer::~Mixer ( )
  109. {
  110. /* FIXME: teardown */
  111. DMESSAGE( "Destroying mixer" );
  112. }
  113. void Mixer::resize ( int X, int Y, int W, int H )
  114. {
  115. Fl_Group::resize( X, Y, W, H );
  116. mixer_strips->resize( X, Y + 24, W, H - 18 - 24 );
  117. scroll->resize( X, Y + 24, W, H - 24 );
  118. }
  119. void Mixer::add ( Mixer_Strip *ms )
  120. {
  121. MESSAGE( "Add mixer strip \"%s\"", ms->name() );
  122. mixer_strips->add( ms );
  123. scroll->redraw();
  124. }
  125. void
  126. Mixer::quit ( void )
  127. {
  128. /* TODO: save project? */
  129. while ( Fl::first_window() ) Fl::first_window()->hide();
  130. }
  131. void
  132. Mixer::insert ( Mixer_Strip *ms, Mixer_Strip *before )
  133. {
  134. mixer_strips->remove( ms );
  135. mixer_strips->insert( *ms, before );
  136. scroll->redraw();
  137. }
  138. void
  139. Mixer::insert ( Mixer_Strip *ms, int i )
  140. {
  141. Mixer_Strip *before = (Mixer_Strip*)mixer_strips->child( i );
  142. insert( ms, before);
  143. }
  144. void
  145. Mixer::move_left ( Mixer_Strip *ms )
  146. {
  147. int i = mixer_strips->find( ms );
  148. if ( i > 0 )
  149. insert( ms, i - 1 );
  150. }
  151. void
  152. Mixer::move_right ( Mixer_Strip *ms )
  153. {
  154. int i = mixer_strips->find( ms );
  155. if ( i < mixer_strips->children() - 1 )
  156. insert( ms, i + 2 );
  157. }
  158. void Mixer::remove ( Mixer_Strip *ms )
  159. {
  160. MESSAGE( "Remove mixer strip \"%s\"", ms->name() );
  161. mixer_strips->remove( ms );
  162. delete ms;
  163. parent()->redraw();
  164. }
  165. bool
  166. Mixer::contains ( Mixer_Strip *ms )
  167. {
  168. return ms->parent() == mixer_strips;
  169. }
  170. void Mixer::update ( void )
  171. {
  172. THREAD_ASSERT( UI );
  173. for ( int i = mixer_strips->children(); i--; )
  174. {
  175. ((Mixer_Strip*)mixer_strips->child( i ))->update();
  176. }
  177. // redraw();
  178. }
  179. /** retrun a pointer to the track named /name/, or NULL if no track is named /name/ */
  180. Mixer_Strip *
  181. Mixer::track_by_name ( const char *name )
  182. {
  183. for ( int i = mixer_strips->children(); i-- ; )
  184. {
  185. Mixer_Strip *t = (Mixer_Strip*)mixer_strips->child( i );
  186. if ( ! strcmp( name, t->name() ) )
  187. return t;
  188. }
  189. return NULL;
  190. }
  191. /** return a malloc'd string representing a unique name for a new track */
  192. char *
  193. Mixer::get_unique_track_name ( const char *name )
  194. {
  195. char pat[256];
  196. strcpy( pat, name );
  197. for ( int i = 1; track_by_name( pat ); ++i )
  198. snprintf( pat, sizeof( pat ), "%s.%d", name, i );
  199. return strdup( pat );
  200. }
  201. void
  202. Mixer::snapshot ( void )
  203. {
  204. for ( int i = 0; i < mixer_strips->children(); ++i )
  205. ((Mixer_Strip*)mixer_strips->child( i ))->log_children();
  206. }
  207. void
  208. Mixer::new_strip ( void )
  209. {
  210. add( new Mixer_Strip( get_unique_track_name( "Unnamed" ), 1 ) );
  211. }
  212. bool
  213. Mixer::save ( void )
  214. {
  215. MESSAGE( "Saving state" );
  216. Loggable::snapshot_callback( &Mixer::snapshot, this );
  217. Loggable::snapshot( "snapshot" );
  218. return true;
  219. }
  220. int
  221. Mixer::handle ( int m )
  222. {
  223. int r = Fl_Group::handle( m );
  224. switch ( m )
  225. {
  226. case FL_ENTER:
  227. case FL_LEAVE:
  228. return 1;
  229. default:
  230. return r;
  231. break;
  232. }
  233. // return 0;
  234. return r;
  235. }