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.

169 lines
3.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 "non.H"
  21. // #include "gui/input.H"
  22. #include "gui/ui.H"
  23. #include "jack.H"
  24. #include "lash.H"
  25. #include "pattern.H"
  26. #include "phrase.H"
  27. Canvas *pattern_c, *phrase_c, *trigger_c;
  28. sequence *playlist;
  29. global_settings config;
  30. song_settings song;
  31. Lash lash;
  32. /* default to pattern mode */
  33. UI *ui;
  34. void
  35. quit ( void )
  36. {
  37. /* clean up, only for valgrind's sake */
  38. delete ui;
  39. delete pattern_c;
  40. delete phrase_c;
  41. delete trigger_c;
  42. midi_all_sound_off();
  43. // wait for it...
  44. sleep( 1 );
  45. midi_shutdown();
  46. MESSAGE( "Your fun is over" );
  47. exit( 0 );
  48. }
  49. void
  50. init_song ( void )
  51. {
  52. song.filename = NULL;
  53. song.dirty = false;
  54. pattern_c->grid( NULL );
  55. phrase_c->grid( NULL );
  56. playlist->reset();
  57. playlist->insert( 0, 1 );
  58. pattern_c->grid( new pattern );
  59. phrase_c->grid( new phrase );
  60. }
  61. void
  62. handle_midi_input ( void )
  63. {
  64. midievent *e;
  65. while ( ( e = midi_input_event( PERFORMANCE ) ) )
  66. {
  67. pattern::record_event( e );
  68. delete e;
  69. }
  70. }
  71. bool
  72. load_song ( const char *name )
  73. {
  74. MESSAGE( "loading song \"%s\"", name );
  75. pattern_c->grid( NULL );
  76. phrase_c->grid( NULL );
  77. if ( ! playlist->load( name ) )
  78. {
  79. WARNING( "failed to load song file" );
  80. return false;
  81. }
  82. pattern_c->grid( pattern::pattern_by_number( 1 ) );
  83. phrase_c->grid( phrase::phrase_by_number( 1 ) );
  84. song.filename = strdup( name );
  85. // TODO: signal song loaded.
  86. return true;
  87. }
  88. bool
  89. save_song ( const char *name )
  90. {
  91. playlist->save( name );
  92. song.filename = strdup( name );
  93. song.dirty = false;
  94. return true;
  95. }
  96. int
  97. main ( int argc, char **argv )
  98. {
  99. config.follow_playhead = true;
  100. config.record_mode = MERGE;
  101. song.play_mode = PATTERN;
  102. song.random.feel = 8;
  103. song.random.probability = 0.33;
  104. printf( "%s %s -- %s\n", APP_TITLE, VERSION, COPYRIGHT );
  105. playlist = new sequence;
  106. pattern_c = new Canvas;
  107. phrase_c = new Canvas;
  108. trigger_c = new Canvas;
  109. init_song();
  110. if ( ! lash.init( &argc, &argv ) )
  111. WARNING( "error initializing LASH" );
  112. if ( argc > 1 )
  113. {
  114. /* maybe a filename on the commandline */
  115. load_song( argv[1] );
  116. }
  117. if ( ! midi_init() )
  118. ASSERTION( "Could not initialize MIDI system! (is Jack running and with MIDI ports enabled?)" );
  119. MESSAGE( "Initializing GUI" );
  120. init_colors();
  121. ui = new UI;
  122. ui->run();
  123. return 0;
  124. }