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.

200 lines
4.9KB

  1. /**********************************************************************************/
  2. /* Copyright (C) 2007,2008 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. #include <stdlib.h>
  19. #include <unistd.h>
  20. #include <sys/types.h>
  21. #include <sys/stat.h>
  22. #include "non.H"
  23. // #include "gui/input.H"
  24. #include "gui/ui.H"
  25. #include "jack.H"
  26. #include "lash.H"
  27. #include "pattern.H"
  28. #include "phrase.H"
  29. Canvas *pattern_c, *phrase_c, *trigger_c;
  30. sequence *playlist;
  31. global_settings config;
  32. song_settings song;
  33. Lash lash;
  34. /* default to pattern mode */
  35. UI *ui;
  36. void
  37. quit ( void )
  38. {
  39. /* clean up, only for valgrind's sake */
  40. delete ui;
  41. delete pattern_c;
  42. delete phrase_c;
  43. delete trigger_c;
  44. midi_all_sound_off();
  45. // wait for it...
  46. sleep( 1 );
  47. midi_shutdown();
  48. MESSAGE( "Your fun is over" );
  49. exit( 0 );
  50. }
  51. void
  52. init_song ( void )
  53. {
  54. song.filename = NULL;
  55. pattern_c->grid( NULL );
  56. phrase_c->grid( NULL );
  57. playlist->reset();
  58. playlist->insert( 0, 1 );
  59. pattern_c->grid( new pattern );
  60. phrase_c->grid( new phrase );
  61. song.dirty( false );
  62. }
  63. void
  64. handle_midi_input ( void )
  65. {
  66. midievent *e;
  67. while ( ( e = midi_input_event( PERFORMANCE ) ) )
  68. {
  69. pattern::record_event( e );
  70. delete e;
  71. }
  72. }
  73. bool
  74. load_song ( const char *name )
  75. {
  76. MESSAGE( "loading song \"%s\"", name );
  77. Grid *pattern_grid = pattern_c->grid();
  78. Grid *phrase_grid = phrase_c->grid();
  79. pattern_c->grid( NULL );
  80. phrase_c->grid( NULL );
  81. if ( ! playlist->load( name ) )
  82. {
  83. WARNING( "failed to load song file" );
  84. goto failed;
  85. }
  86. pattern_c->grid( pattern::pattern_by_number( 1 ) );
  87. phrase_c->grid( phrase::phrase_by_number( 1 ) );
  88. song.filename = strdup( name );
  89. song.dirty( false );
  90. return true;
  91. failed:
  92. pattern_c->grid( pattern_grid );
  93. phrase_c->grid( phrase_grid );
  94. return false;
  95. }
  96. bool
  97. save_song ( const char *name )
  98. {
  99. playlist->save( name );
  100. song.filename = strdup( name );
  101. song.dirty( false );
  102. return true;
  103. }
  104. int
  105. main ( int argc, char **argv )
  106. {
  107. config.follow_playhead = true;
  108. config.record_mode = MERGE;
  109. song.play_mode = PATTERN;
  110. song.random.feel = 8;
  111. song.random.probability = 0.33;
  112. asprintf( &config.user_config_dir, "%s/%s", getenv( "HOME" ), USER_CONFIG_DIR );
  113. mkdir( config.user_config_dir, 0777 );
  114. printf( "%s %s -- %s\n", APP_TITLE, VERSION, COPYRIGHT );
  115. playlist = new sequence;
  116. pattern_c = new Canvas;
  117. phrase_c = new Canvas;
  118. trigger_c = new Canvas;
  119. init_song();
  120. pattern::signal_create_destroy.connect( mem_fun( phrase_c, &Canvas::v_zoom_fit ) );
  121. pattern::signal_create_destroy.connect( mem_fun( song, &song_settings::set_dirty ) );
  122. phrase::signal_create_destroy.connect( mem_fun( song, &song_settings::set_dirty ) );
  123. if ( ! lash.init( &argc, &argv ) )
  124. WARNING( "error initializing LASH" );
  125. if ( argc > 1 )
  126. {
  127. /* maybe a filename on the commandline */
  128. if ( ! load_song( argv[ 1 ] ) )
  129. ASSERTION( "Could not load song \"%s\" specified on command line", argv[ 1 ] );
  130. }
  131. if ( ! midi_init() )
  132. ASSERTION( "Could not initialize MIDI system! (is Jack running and with MIDI ports enabled?)" );
  133. if ( ! transport.valid )
  134. if ( transport.master )
  135. ASSERTION( "The version of JACK you are using does not appear to be capable of passing BBT positional information." );
  136. else
  137. ASSERTION( "Either the version of JACK you are using does pass BBT information, or the current timebase master does not provide it." );
  138. song.dirty( false );
  139. MESSAGE( "Initializing GUI" );
  140. init_colors();
  141. ui = new UI;
  142. ui->run();
  143. return 0;
  144. }