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.

375 lines
8.8KB

  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 "FL/Fl_Flowpack.H"
  28. #include "Project.H"
  29. #include <string.h>
  30. #include "debug.h"
  31. const double STATUS_UPDATE_FREQ = 0.2f;
  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, "&Project/&Quit") )
  63. {
  64. quit();
  65. }
  66. else if ( !strcmp( picked, "&Mixer/&Add Strip" ) )
  67. {
  68. new_strip();
  69. }
  70. else if ( !strcmp( picked, "&Mixer/Add &N Strips" ) )
  71. {
  72. const char *s = fl_input( "Enter number of strips to add" );
  73. if ( s )
  74. {
  75. for ( int i = atoi( s ); i > 0; i-- )
  76. new_strip();
  77. }
  78. }
  79. else if (! strcmp( picked, "&Mixer/&Rows/One") )
  80. {
  81. rows( 1 );
  82. }
  83. else if (! strcmp( picked, "&Mixer/&Rows/Two") )
  84. {
  85. rows( 2 );
  86. }
  87. else if (! strcmp( picked, "&Mixer/&Rows/Three") )
  88. {
  89. rows( 3 );
  90. }
  91. }
  92. void Mixer::cb_menu(Fl_Widget* o, void* v) {
  93. ((Mixer*)(v))->cb_menu(o);
  94. }
  95. Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) :
  96. Fl_Group( X, Y, W, H, L )
  97. {
  98. _rows = 1;
  99. box( FL_NO_BOX );
  100. labelsize( 96 );
  101. { Fl_Menu_Bar *o = new Fl_Menu_Bar( X, Y, W, 24 );
  102. o->add( "&Project/&New" );
  103. o->add( "&Project/&Open" );
  104. o->add( "&Project/&Save", FL_CTRL + 's', 0, 0 );
  105. o->add( "&Project/&Quit", FL_CTRL + 'q', 0, 0 );
  106. o->add( "&Mixer/&Add Strip", 'a', 0, 0 );
  107. o->add( "&Mixer/Add &N Strips" );
  108. o->add( "&Mixer/&Rows/One", '1', 0, 0 );
  109. o->add( "&Mixer/&Rows/Two", '2', 0, 0 );
  110. o->add( "&Mixer/&Rows/Three", '3', 0, 0 );
  111. o->add( "_&Options" );
  112. o->add( "&Help/&Manual" );
  113. o->add( "&Help/&About" );
  114. o->callback( cb_menu, this );
  115. }
  116. { Fl_Scroll *o = scroll = new Fl_Scroll( X, Y + 24, W, H - 24 );
  117. o->box( FL_NO_BOX );
  118. // o->type( Fl_Scroll::HORIZONTAL_ALWAYS );
  119. // o->box( Fl_Scroll::BOTH );
  120. {
  121. Fl_Flowpack *o = mixer_strips = new Fl_Flowpack( X, Y + 24, W, H - 18 - 24 );
  122. label( "Non-Mixer" );
  123. align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE) );
  124. o->box( FL_NO_BOX );
  125. o->type( Fl_Pack::HORIZONTAL );
  126. o->hspacing( 2 );
  127. o->vspacing( 2 );
  128. o->end();
  129. Fl_Group::current()->resizable( o );
  130. }
  131. o->end();
  132. Fl_Group::current()->resizable( o );
  133. }
  134. end();
  135. // Fl::add_timeout( STATUS_UPDATE_FREQ, update_cb, this );
  136. MESSAGE( "Scanning for plugins..." );
  137. }
  138. Mixer::~Mixer ( )
  139. {
  140. /* FIXME: teardown */
  141. DMESSAGE( "Destroying mixer" );
  142. }
  143. void Mixer::resize ( int X, int Y, int W, int H )
  144. {
  145. Fl_Group::resize( X, Y, W, H );
  146. mixer_strips->resize( X, Y + 24, W, H - 18 - 24 );
  147. scroll->resize( X, Y + 24, W, H - 24 );
  148. rows( _rows );
  149. }
  150. void Mixer::add ( Mixer_Strip *ms )
  151. {
  152. MESSAGE( "Add mixer strip \"%s\"", ms->name() );
  153. mixer_strips->add( ms );
  154. rows( _rows );
  155. scroll->redraw();
  156. }
  157. void
  158. Mixer::quit ( void )
  159. {
  160. /* TODO: save project? */
  161. while ( Fl::first_window() ) Fl::first_window()->hide();
  162. }
  163. void
  164. Mixer::insert ( Mixer_Strip *ms, Mixer_Strip *before )
  165. {
  166. mixer_strips->remove( ms );
  167. mixer_strips->insert( *ms, before );
  168. scroll->redraw();
  169. }
  170. void
  171. Mixer::insert ( Mixer_Strip *ms, int i )
  172. {
  173. Mixer_Strip *before = (Mixer_Strip*)mixer_strips->child( i );
  174. insert( ms, before);
  175. }
  176. void
  177. Mixer::move_left ( Mixer_Strip *ms )
  178. {
  179. int i = mixer_strips->find( ms );
  180. if ( i > 0 )
  181. insert( ms, i - 1 );
  182. }
  183. void
  184. Mixer::move_right ( Mixer_Strip *ms )
  185. {
  186. int i = mixer_strips->find( ms );
  187. if ( i < mixer_strips->children() - 1 )
  188. insert( ms, i + 2 );
  189. }
  190. void Mixer::remove ( Mixer_Strip *ms )
  191. {
  192. MESSAGE( "Remove mixer strip \"%s\"", ms->name() );
  193. mixer_strips->remove( ms );
  194. delete ms;
  195. parent()->redraw();
  196. }
  197. bool
  198. Mixer::contains ( Mixer_Strip *ms )
  199. {
  200. return ms->parent() == mixer_strips;
  201. }
  202. void
  203. Mixer::rows ( int n )
  204. {
  205. int sh;
  206. if ( n > 1 )
  207. sh = (scroll->h() / n) - (mixer_strips->vspacing() * (n - 1));
  208. else
  209. sh = (scroll->h() - 18) / n;
  210. if ( sh < Mixer_Strip::min_h() )
  211. return;
  212. int tw = 0;
  213. for ( int i = 0; i < mixer_strips->children(); ++i )
  214. {
  215. Mixer_Strip *t = (Mixer_Strip*)mixer_strips->child( i );
  216. t->size( t->w(), sh );
  217. tw += t->w() + mixer_strips->hspacing();
  218. }
  219. if ( n > 1 )
  220. mixer_strips->size( scroll->w() - 18, mixer_strips->h() );
  221. else
  222. mixer_strips->size( tw, mixer_strips->h() );
  223. _rows = n;
  224. scroll->redraw();
  225. }
  226. void Mixer::update ( void )
  227. {
  228. THREAD_ASSERT( UI );
  229. for ( int i = mixer_strips->children(); i--; )
  230. {
  231. ((Mixer_Strip*)mixer_strips->child( i ))->update();
  232. }
  233. // redraw();
  234. }
  235. /** retrun a pointer to the track named /name/, or NULL if no track is named /name/ */
  236. Mixer_Strip *
  237. Mixer::track_by_name ( const char *name )
  238. {
  239. for ( int i = mixer_strips->children(); i-- ; )
  240. {
  241. Mixer_Strip *t = (Mixer_Strip*)mixer_strips->child( i );
  242. if ( ! strcmp( name, t->name() ) )
  243. return t;
  244. }
  245. return NULL;
  246. }
  247. /** return a malloc'd string representing a unique name for a new track */
  248. char *
  249. Mixer::get_unique_track_name ( const char *name )
  250. {
  251. char pat[256];
  252. strcpy( pat, name );
  253. for ( int i = 1; track_by_name( pat ); ++i )
  254. snprintf( pat, sizeof( pat ), "%s.%d", name, i );
  255. return strdup( pat );
  256. }
  257. void
  258. Mixer::snapshot ( void )
  259. {
  260. for ( int i = 0; i < mixer_strips->children(); ++i )
  261. ((Mixer_Strip*)mixer_strips->child( i ))->log_children();
  262. }
  263. void
  264. Mixer::new_strip ( void )
  265. {
  266. add( new Mixer_Strip( get_unique_track_name( "Unnamed" ), 1 ) );
  267. }
  268. bool
  269. Mixer::save ( void )
  270. {
  271. MESSAGE( "Saving state" );
  272. Loggable::snapshot_callback( &Mixer::snapshot, this );
  273. Loggable::snapshot( "snapshot" );
  274. return true;
  275. }
  276. int
  277. Mixer::handle ( int m )
  278. {
  279. int r = Fl_Group::handle( m );
  280. switch ( m )
  281. {
  282. case FL_ENTER:
  283. case FL_LEAVE:
  284. return 1;
  285. default:
  286. return r;
  287. break;
  288. }
  289. // return 0;
  290. return r;
  291. }