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.

184 lines
5.4KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 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. /* these are all the objects whose state must be recorded, this
  19. includes tracks, regions, etc. Relevant interfaces must be fully compatible
  20. with those in the Timeline program. */
  21. #include "Audio_File.H"
  22. #include "Loggable.H"
  23. typedef unsigned long nframes_t;
  24. class Track_Widget
  25. {
  26. protected:
  27. nframes_t _offset;
  28. nframes_t _start;
  29. nframes_t _end;
  30. bool _selected;
  31. };
  32. /* macros to simplify serialization code */
  33. #define START( n ) char **sa = (char **)malloc( sizeof( char * ) * (1 + (n) ) ); int i = 0
  34. #define PUT( fmt, arg ) asprintf( &sa[ i++ ], (fmt), (arg) )
  35. #define END() sa[ i ] = NULL; return sa;
  36. #define SWITCH do
  37. #define CASE( arg ) if ( ! strcmp( s, ( arg ) ) )
  38. #define GET( arg, act ) CASE( arg ) { act ; break; }
  39. class Track : public Loggable
  40. {
  41. };
  42. class Region : public Loggable, public Track_Widget
  43. {
  44. Track *_track;
  45. Audio_File *_clip; /* clip this region represents */
  46. float _scale; /* amplitude adjustment */
  47. protected:
  48. const char *class_name ( void ) { return "Region"; }
  49. char ** get ( void )
  50. {
  51. START( 7 );
  52. PUT( ":source \"%s\"", _clip ? _clip->name() : "" );
  53. PUT( ":track 0x%X", _track ? _track->id() : 0 );
  54. PUT( ":x %lu", _offset );
  55. PUT( ":l %lu", _start );
  56. PUT( ":r %lu", _end );
  57. PUT( ":selected %d", _selected );
  58. PUT( ":gain %f", _scale );
  59. END();
  60. }
  61. void
  62. set ( char **sa )
  63. {
  64. for ( int i = 0; sa[i]; ++i )
  65. {
  66. char *s = sa[i];
  67. char *v = s + strlen( s ) + 1;
  68. SWITCH
  69. {
  70. GET( ":x", _offset = atol( v ) );
  71. GET( ":l" , _start = atol( v ) );
  72. GET( ":r", _end = atol( v ) );
  73. CASE( ":selected" )
  74. {
  75. if ( atoi( v ) )
  76. select();
  77. else
  78. deselect();
  79. break;
  80. }
  81. GET( ":gain", _scale = atof( v ) );
  82. CASE( ":source" )
  83. {
  84. if ( ! ( _clip = Audio_File::from_file( v ) ) )
  85. printf( "Grave error: could not open source \"%s\"\n", v );
  86. break;
  87. }
  88. CASE( ":track" )
  89. {
  90. int i;
  91. sscanf( v, "%X", &i );
  92. Track *t = (Track*)Loggable::find( i );
  93. assert( t );
  94. t->add( this );
  95. break;
  96. }
  97. }
  98. free( s );
  99. }
  100. free( sa );
  101. }
  102. };
  103. class Time_Point : public Track_Widget
  104. {
  105. protected:
  106. char ** get ( void )
  107. {
  108. START( 4 );
  109. PUT( ":track 0x%X", _track ? _track->id() : 0 );
  110. PUT( ":x %lu", _offset );
  111. PUT( ":beats_per_bar %d", _time.beats_per_bar );
  112. PUT( ":beat_type %d", _time.beat_type );
  113. END();
  114. }
  115. void
  116. set ( char **sa )
  117. {
  118. for ( int i = 0; sa[i]; ++i )
  119. {
  120. char *s = sa[i];
  121. char *v = s + strlen( s ) + 1;
  122. SWITCH
  123. {
  124. GET( ":x", _offset = atol( v ) );
  125. GET( ":beats_per_bar", _time.beats_per_bar = atoi( v ) );
  126. GET( ":beat_type", _time.beat_type = atoi( v ) );
  127. CASE( ":track" )
  128. {
  129. int i;
  130. sscanf( v, "%X", &i );
  131. Track *t = (Track*)Loggable::find( i );
  132. assert( t );
  133. t->add( this );
  134. break;
  135. }
  136. free( s );
  137. }
  138. free( sa );
  139. }
  140. }
  141. };