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.

177 lines
4.0KB

  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. song.dirty( false );
  56. pattern_c->grid( NULL );
  57. phrase_c->grid( NULL );
  58. playlist->reset();
  59. playlist->insert( 0, 1 );
  60. pattern_c->grid( new pattern );
  61. phrase_c->grid( new phrase );
  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. pattern_c->grid( NULL );
  78. phrase_c->grid( NULL );
  79. if ( ! playlist->load( name ) )
  80. {
  81. WARNING( "failed to load song file" );
  82. return false;
  83. }
  84. pattern_c->grid( pattern::pattern_by_number( 1 ) );
  85. phrase_c->grid( phrase::phrase_by_number( 1 ) );
  86. song.filename = strdup( name );
  87. // TODO: signal song loaded.
  88. return true;
  89. }
  90. bool
  91. save_song ( const char *name )
  92. {
  93. playlist->save( name );
  94. song.filename = strdup( name );
  95. song.dirty( false );
  96. return true;
  97. }
  98. int
  99. main ( int argc, char **argv )
  100. {
  101. config.follow_playhead = true;
  102. config.record_mode = MERGE;
  103. song.play_mode = PATTERN;
  104. song.random.feel = 8;
  105. song.random.probability = 0.33;
  106. asprintf( &config.user_config_dir, "%s/%s", getenv( "HOME" ), USER_CONFIG_DIR );
  107. mkdir( config.user_config_dir, 0777 );
  108. printf( "%s %s -- %s\n", APP_TITLE, VERSION, COPYRIGHT );
  109. playlist = new sequence;
  110. pattern_c = new Canvas;
  111. phrase_c = new Canvas;
  112. trigger_c = new Canvas;
  113. init_song();
  114. if ( ! lash.init( &argc, &argv ) )
  115. WARNING( "error initializing LASH" );
  116. if ( argc > 1 )
  117. {
  118. /* maybe a filename on the commandline */
  119. load_song( argv[1] );
  120. }
  121. if ( ! midi_init() )
  122. ASSERTION( "Could not initialize MIDI system! (is Jack running and with MIDI ports enabled?)" );
  123. MESSAGE( "Initializing GUI" );
  124. init_colors();
  125. ui = new UI;
  126. ui->run();
  127. return 0;
  128. }