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.

339 lines
7.7KB

  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. }
  112. void Mixer::resize ( int X, int Y, int W, int H )
  113. {
  114. Fl_Group::resize( X, Y, W, H );
  115. mixer_strips->resize( X, Y + 24, W, H - 18 - 24 );
  116. scroll->resize( X, Y + 24, W, H - 24 );
  117. }
  118. void Mixer::add ( Mixer_Strip *ms )
  119. {
  120. MESSAGE( "Add mixer strip \"%s\"", ms->name() );
  121. engine->lock();
  122. mixer_strips->add( ms );
  123. // mixer_strips->insert( *ms, 0 );
  124. engine->unlock();
  125. scroll->redraw();
  126. // redraw();
  127. }
  128. void
  129. Mixer::quit ( void )
  130. {
  131. /* TODO: save project? */
  132. while ( Fl::first_window() ) Fl::first_window()->hide();
  133. }
  134. void
  135. Mixer::insert ( Mixer_Strip *ms, Mixer_Strip *before )
  136. {
  137. engine->lock();
  138. mixer_strips->remove( ms );
  139. mixer_strips->insert( *ms, before );
  140. engine->unlock();
  141. scroll->redraw();
  142. }
  143. void
  144. Mixer::insert ( Mixer_Strip *ms, int i )
  145. {
  146. Mixer_Strip *before = (Mixer_Strip*)mixer_strips->child( i );
  147. insert( ms, before);
  148. }
  149. void
  150. Mixer::move_left ( Mixer_Strip *ms )
  151. {
  152. int i = mixer_strips->find( ms );
  153. if ( i > 0 )
  154. insert( ms, i - 1 );
  155. }
  156. void
  157. Mixer::move_right ( Mixer_Strip *ms )
  158. {
  159. int i = mixer_strips->find( ms );
  160. if ( i < mixer_strips->children() - 1 )
  161. insert( ms, i + 2 );
  162. }
  163. void Mixer::remove ( Mixer_Strip *ms )
  164. {
  165. MESSAGE( "Remove mixer strip \"%s\"", ms->name() );
  166. engine->lock();
  167. mixer_strips->remove( ms );
  168. engine->unlock();
  169. delete ms;
  170. parent()->redraw();
  171. }
  172. bool
  173. Mixer::contains ( Mixer_Strip *ms )
  174. {
  175. return ms->parent() == mixer_strips;
  176. }
  177. void Mixer::update ( void )
  178. {
  179. THREAD_ASSERT( UI );
  180. for ( int i = mixer_strips->children(); i--; )
  181. {
  182. ((Mixer_Strip*)mixer_strips->child( i ))->update();
  183. }
  184. // redraw();
  185. }
  186. void
  187. Mixer::process ( unsigned int nframes )
  188. {
  189. THREAD_ASSERT( RT );
  190. for ( int i = mixer_strips->children(); i--; )
  191. {
  192. ((Mixer_Strip*)mixer_strips->child( i ))->process( nframes );
  193. }
  194. }
  195. /** retrun a pointer to the track named /name/, or NULL if no track is named /name/ */
  196. Mixer_Strip *
  197. Mixer::track_by_name ( const char *name )
  198. {
  199. for ( int i = mixer_strips->children(); i-- ; )
  200. {
  201. Mixer_Strip *t = (Mixer_Strip*)mixer_strips->child( i );
  202. if ( ! strcmp( name, t->name() ) )
  203. return t;
  204. }
  205. return NULL;
  206. }
  207. /** return a malloc'd string representing a unique name for a new track */
  208. char *
  209. Mixer::get_unique_track_name ( const char *name )
  210. {
  211. char pat[256];
  212. strcpy( pat, name );
  213. for ( int i = 1; track_by_name( pat ); ++i )
  214. snprintf( pat, sizeof( pat ), "%s.%d", name, i );
  215. return strdup( pat );
  216. }
  217. void
  218. Mixer::snapshot ( void )
  219. {
  220. for ( int i = 0; i < mixer_strips->children(); ++i )
  221. ((Mixer_Strip*)mixer_strips->child( i ))->log_children();
  222. }
  223. void
  224. Mixer::new_strip ( void )
  225. {
  226. engine->lock();
  227. add( new Mixer_Strip( get_unique_track_name( "Unnamed" ), 1 ) );
  228. engine->unlock();
  229. // scroll->size( mixer_strips->w(), scroll->h() );
  230. }
  231. bool
  232. Mixer::save ( void )
  233. {
  234. MESSAGE( "Saving state" );
  235. Loggable::snapshot_callback( &Mixer::snapshot, this );
  236. Loggable::snapshot( "snapshot" );
  237. return true;
  238. }
  239. int
  240. Mixer::handle ( int m )
  241. {
  242. int r = Fl_Group::handle( m );
  243. switch ( m )
  244. {
  245. case FL_ENTER:
  246. case FL_LEAVE:
  247. return 1;
  248. default:
  249. return r;
  250. break;
  251. }
  252. // return 0;
  253. return r;
  254. }