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.

262 lines
7.1KB

  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. #pragma once
  19. #include "event.H"
  20. #include "event_list.H"
  21. #include "dash.H"
  22. #include "const.h"
  23. #include "instrument.H"
  24. class smf;
  25. #include "debug.h"
  26. const int MAX_UNDO = 10;
  27. #include <list>
  28. #include <sigc++/sigc++.h>
  29. using namespace sigc;
  30. using std::list;
  31. /* patterns and phrases use this structure */
  32. class Canvas;
  33. /* everything that must be lock-free. This whole structure gets copied and swapped
  34. for each write method */
  35. struct data {
  36. tick_t length;
  37. int state;
  38. event_list events;
  39. data( void )
  40. {
  41. length = 0;
  42. state = 0;
  43. }
  44. data( const data &rhs )
  45. {
  46. events = rhs.events;
  47. length = rhs.length;
  48. state = rhs.state;
  49. }
  50. /* data() { MESSAGE( "allocating new editable data" ); } */
  51. // ~data() { MESSAGE( "deleting old undo data, freeing at least %d bytes.", events.size() * sizeof ( event ) + sizeof ( list <event> )); }
  52. };
  53. struct Viewport {
  54. #define format "%d:%d:%d:%d"
  55. int x, y, w, h;
  56. Viewport ( void )
  57. {
  58. x = y = w = h = 0;
  59. }
  60. char *
  61. dump ( void ) const
  62. {
  63. char *s;
  64. asprintf( &s, format, x, y, w, h );
  65. return s;
  66. }
  67. void
  68. read( const char *s )
  69. {
  70. sscanf( s, format, &x, &y, &w, &h );
  71. }
  72. #undef format
  73. };
  74. class Grid : public trackable
  75. {
  76. protected:
  77. unsigned int _height;
  78. char *_notes;
  79. char *_name;
  80. int _number;
  81. int _draw_shape;
  82. unsigned int _bpb; /* beats per bar */
  83. unsigned int _ppqn; /* pulses per quarter note (beat) */
  84. /* Used by playback thread. When a pattern or phrase is triggered,
  85. these fields are filled in appropriately */
  86. mutable tick_t _start; /* absolute start tick of loop */
  87. mutable tick_t _end; /* absolute end tick of loop */
  88. volatile mutable tick_t _index; /* playhead, relative to start -- primarily used to draw the playhead */
  89. volatile mutable bool _playing; /* true if currently playing */
  90. volatile int _mode; /* mute, solo */
  91. // FIXME: shouldn't this be "volatile"?
  92. // const volatile data *_rd; /* read only data used by RT thread */
  93. const data * volatile _rd;
  94. data *_rw; /* temporary writable copy used by UI thread */
  95. list <data *> _history;
  96. void _remove_marked ( void );
  97. event * _event ( int x, int y, bool write ) const;
  98. bool _delete ( int x, int y );
  99. bool _get ( struct dash *d, int x, int y ) const;
  100. void _link ( void );
  101. void _relink ( void );
  102. void _fix_length ( void );
  103. private:
  104. int _locked;
  105. public:
  106. signal <void> signal_events_change;
  107. signal <void> signal_settings_change;
  108. Viewport viewport; /* used by the Canvas */
  109. Grid ( void );
  110. // FIXME: needs to be virtual?
  111. ~Grid ( void );
  112. Grid ( const Grid &rhs );
  113. int y_to_note ( int y ) const;
  114. int note_to_y ( int n ) const;
  115. tick_t x_to_ts ( uint x ) const;
  116. uint ts_to_x ( tick_t ts ) const;
  117. virtual Grid * create ( void ) = 0;
  118. virtual Grid * clone ( void ) = 0;
  119. virtual void draw_row_names ( Canvas *c ) const = 0;
  120. virtual const char * row_name ( int r ) const = 0;
  121. virtual Grid * by_number ( int n ) const = 0;
  122. virtual void put ( int x, int y, tick_t l );
  123. void lock ( void );
  124. void unlock ( void );
  125. void clear ( void );
  126. int get ( struct dash *d, int x, int y ) const;
  127. void del ( int x, int y );
  128. void adj_velocity ( int x, int y, int n );
  129. void adj_duration ( int x, int y, int l );
  130. void move ( int x, int y, int nx, int ny );
  131. void record_event ( event *e );
  132. tick_t index ( void ) const;
  133. bool playing ( void ) const;
  134. int height ( void ) const;
  135. void height ( int h );
  136. tick_t length ( void ) const;
  137. void length ( tick_t l );
  138. int bars ( void ) const;
  139. int beats ( void ) const;
  140. void trim ( void );
  141. void expand ( void );
  142. int division ( void ) const;
  143. int subdivision ( void ) const;
  144. int ppqn ( void ) const;
  145. int number ( void ) const;
  146. void name ( char *s );
  147. const char * name ( void ) const;
  148. void notes ( char *s );
  149. char * notes ( void ) const;
  150. virtual void mode ( int m );
  151. virtual int mode ( void ) const;
  152. int draw_shape ( void ) const;
  153. int next_note_x ( int x ) const;
  154. int prev_note_x ( int x ) const;
  155. void fit ( void );
  156. void delete_selected ( void );
  157. void move_selected ( int l );
  158. void crop ( int l, int r );
  159. void select ( int x, int y, bool b );
  160. void insert_time ( int x, int r );
  161. void select ( int start, int end );
  162. void delete_time ( int start, int end );
  163. void select_none ( void );
  164. void resolution ( unsigned int n );
  165. int resolution ( void ) const;
  166. void dump ( smf *f, int channel, bool translate ) const;
  167. void draw ( Canvas *c, int bx, int by, int bw, int bh );
  168. void print ( void ) const;
  169. event_list * events ( void ) const;
  170. void events ( const event_list * el );
  171. };
  172. inline int
  173. Grid::y_to_note ( int y ) const
  174. {
  175. return 127 - y;
  176. }
  177. inline int
  178. Grid::note_to_y ( int n ) const
  179. {
  180. return 127 - n;
  181. }
  182. inline tick_t
  183. Grid::x_to_ts ( unsigned int x ) const
  184. {
  185. return (x * PPQN) / _ppqn;
  186. // return x * (PPQN / _ppqn);
  187. }
  188. inline unsigned int
  189. Grid::ts_to_x ( tick_t ts ) const
  190. {
  191. return (ts * _ppqn) / PPQN;
  192. // return ts / (PPQN / _ppqn);
  193. }