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.

293 lines
9.3KB

  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 <cstring>
  19. /* system */
  20. #include <sys/types.h>
  21. #include <unistd.h>
  22. #include "../non.H"
  23. #include "draw.H"
  24. #include "../common.h"
  25. #include "ui.H"
  26. extern UI *ui;
  27. void
  28. async_exec ( const char *cmd )
  29. {
  30. if ( fork() )
  31. {
  32. printf( "Executed command \"%s\"\n", cmd );
  33. return;
  34. }
  35. system( cmd );
  36. exit(0);
  37. }
  38. int
  39. canvas_input_callback ( O_Canvas *widget, Canvas *c, int m )
  40. {
  41. static int lmb_down;
  42. // MESSAGE( "Hello, my name is %s", widget->parent()->label() );
  43. int ow, oh;
  44. int x, y;
  45. int processed = 1;
  46. x = Fl::event_x();
  47. y = Fl::event_y();
  48. ow = c->grid()->viewport.w;
  49. oh = c->grid()->viewport.h;
  50. switch ( m )
  51. {
  52. case FL_KEYBOARD:
  53. {
  54. /* if ( Fl::event_state() & FL_ALT || Fl::event_state() & FL_CTRL ) */
  55. /* // this is more than a simple keypress. */
  56. /* return 0; */
  57. if ( Fl::event_state() & FL_CTRL )
  58. {
  59. switch ( Fl::event_key() )
  60. {
  61. case FL_Delete:
  62. c->delete_time();
  63. break;
  64. case FL_Insert:
  65. c->insert_time();
  66. break;
  67. case FL_Right:
  68. c->pan( TO_NEXT_NOTE, 0 );
  69. break;
  70. case FL_Left:
  71. c->pan( TO_PREV_NOTE, 0 );
  72. break;
  73. default:
  74. return 0;
  75. }
  76. }
  77. else
  78. if ( Fl::event_state() & FL_ALT )
  79. return 0;
  80. switch ( Fl::event_key() )
  81. {
  82. case FL_Left:
  83. c->pan( LEFT, 1 );
  84. break;
  85. case FL_Right:
  86. c->pan( RIGHT, 1 );
  87. break;
  88. case FL_Up:
  89. c->pan( UP, 1 );
  90. break;
  91. case FL_Down:
  92. c->pan( DOWN, 1 );
  93. break;
  94. case FL_Delete:
  95. if ( Fl::event_state() & FL_SHIFT )
  96. c->grid()->clear();
  97. else
  98. c->grid()->delete_selected();
  99. break;
  100. default:
  101. /* have to do this to get shifted keys */
  102. switch ( *Fl::event_text() )
  103. {
  104. case 'f':
  105. c->pan( TO_PLAYHEAD, 0 );
  106. break;
  107. case 'r':
  108. c->select_range();
  109. break;
  110. case 'q':
  111. c->grid()->select_none();
  112. break;
  113. case '1':
  114. c->h_zoom( 2.0f );
  115. break;
  116. case '2':
  117. c->h_zoom( 0.5f );
  118. break;
  119. case '3':
  120. c->v_zoom( 2.0f );
  121. break;
  122. case '4':
  123. c->v_zoom( 0.5f );
  124. break;
  125. case ' ':
  126. transport.toggle();
  127. break;
  128. case '[':
  129. {
  130. Grid *g = NULL;
  131. #define IS_PATTERN (widget->parent() == ui->pattern_tab)
  132. #define IS_PHRASE (widget->parent() == ui->phrase_tab)
  133. #define IS_SEQUENCE (widget->parent() == ui->sequence_tab)
  134. /* is there no nicer way to do this shit in c++? */
  135. g = c->grid()->by_number( c->grid()->number() - 1 );
  136. if ( g )
  137. {
  138. c->grid( g );
  139. processed = 2;
  140. }
  141. break;
  142. }
  143. case ']':
  144. {
  145. Grid *g = NULL;
  146. /* is there no nicer way to do this shit in c++? */
  147. g = c->grid()->by_number( c->grid()->number() + 1 );
  148. if ( g )
  149. {
  150. c->grid( g );
  151. processed = 2;
  152. }
  153. break;
  154. }
  155. case '<':
  156. c->move_selected( LEFT, 1 );
  157. break;
  158. case '>':
  159. c->move_selected( RIGHT, 1 );
  160. break;
  161. case ',':
  162. c->move_selected( UP, 1 );
  163. break;
  164. case '.':
  165. c->move_selected( DOWN, 1 );
  166. break;
  167. case 'C':
  168. c->crop();
  169. break;
  170. case 'c':
  171. {
  172. c->grid( c->grid()->create() );
  173. ui->update_sequence_widgets();
  174. break;
  175. }
  176. case 'd':
  177. {
  178. MESSAGE( "duplicating thing" );
  179. c->grid( c->grid()->clone() );
  180. // number of phrases may have changed.
  181. ui->update_sequence_widgets();
  182. break;
  183. }
  184. case 'D':
  185. c->duplicate_range();
  186. break;
  187. case 't':
  188. c->grid()->trim();
  189. break;
  190. case 'm':
  191. c->grid()->mode( c->grid()->mode() == MUTE ? PLAY : MUTE );
  192. break;
  193. case 's':
  194. c->grid()->mode( c->grid()->mode() == SOLO ? PLAY : SOLO );
  195. break;
  196. default:
  197. processed = 0;
  198. break;
  199. }
  200. break;
  201. }
  202. break;
  203. }
  204. case FL_PUSH:
  205. {
  206. switch ( Fl::event_button() )
  207. {
  208. case 1:
  209. lmb_down = true;
  210. if ( IS_PATTERN && Fl::event_state() & FL_CTRL )
  211. c->randomize_row( y );
  212. else
  213. c->set( x, y );
  214. break;
  215. case 3:
  216. c->unset( x, y );
  217. break;
  218. case 2:
  219. c->select( x, y );
  220. break;
  221. default:
  222. processed = 0;
  223. }
  224. break;
  225. }
  226. case FL_RELEASE:
  227. break;
  228. case FL_DRAG:
  229. break;
  230. /* case FL_DRAG: */
  231. /* { */
  232. /* if ( ! lmb_down ) */
  233. /* break; */
  234. /* // c->grid()->move( x, y, nx ); */
  235. /* break; */
  236. /* } */
  237. case FL_MOUSEWHEEL:
  238. {
  239. if ( Fl::event_state() & FL_CTRL )
  240. c->adj_length( x, y, (0 - Fl::event_dy()) );
  241. else
  242. c->adj_color( x, y, (0 - Fl::event_dy()) * 5 );
  243. break;
  244. }
  245. default:
  246. processed = 0;
  247. }
  248. int nw, nh;
  249. nw = c->grid()->viewport.w;
  250. nh = c->grid()->viewport.h;
  251. // layout of canvas changed... requires clearing.
  252. if ( oh != nh || ow != nw )
  253. return 3;
  254. return processed;
  255. }