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.

359 lines
8.3KB

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