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.

209 lines
5.9KB

  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. #pragma once
  19. #include "Audio_File.H"
  20. #include "Track.H"
  21. #include "Timeline.H"
  22. /* Regions are "virtual" FLTK widgets; this is necessary because the
  23. * dimensions of real FLTK widgets are limited to 16-bits, which is
  24. * far too little for our purposes */
  25. #include "Track_Widget.H"
  26. #include "Loggable.H"
  27. class Region;
  28. /* Base for engine. Just to maintain state. Must be free of FLTK
  29. * stuff */
  30. class Region_Base : public Track_Widget
  31. {
  32. private:
  33. Audio_File *_clip; /* clip this region represents */
  34. float _scale; /* amplitude adjustment */
  35. protected:
  36. const char *class_name ( void ) { return "Region"; }
  37. char ** get ( void )
  38. {
  39. // char *r;
  40. char **sa = (char**)malloc( sizeof( char* ) * 8 );
  41. int i = 0;
  42. asprintf( &sa[ i++ ], ":source \"%s\"", _clip ? _clip->name() : "" );
  43. asprintf( &sa[ i++ ], ":track 0x%X", _track ? _track->id() : 0 );
  44. asprintf( &sa[ i++ ], ":x %lu", _offset );
  45. asprintf( &sa[ i++ ], ":l %lu", _start );
  46. asprintf( &sa[ i++ ], ":r %lu", _end );
  47. asprintf( &sa[ i++ ], ":selected %d", selected() );
  48. asprintf( &sa[ i++ ], ":gain %f", _scale );
  49. sa[ i ] = NULL;
  50. return sa;
  51. }
  52. void
  53. set ( char **sa )
  54. {
  55. for ( int i = 0; sa[i]; ++i )
  56. {
  57. char *s = sa[i];
  58. strtok( s, " " );
  59. char *v = s + strlen( s ) + 1;
  60. if ( *v == '"' )
  61. {
  62. v++;
  63. v[ strlen( v ) - 2 ] = '\0';
  64. }
  65. if ( ! strcmp( s, ":x" ) )
  66. _offset = atol( v );
  67. else if ( ! strcmp( s, ":l" ) )
  68. _start = atol( v );
  69. else if ( ! strcmp( s, ":r" ) )
  70. _end = atol( v );
  71. else if ( ! strcmp( s, ":selected" ) )
  72. {
  73. if ( atoi( v ) )
  74. select();
  75. else
  76. deselect();
  77. }
  78. else if ( ! strcmp( s, ":gain" ) )
  79. _scale = atof( v );
  80. else if ( ! strcmp( s, ":source" ) )
  81. {
  82. if ( ! ( _clip = Audio_File::from_file( v ) ) )
  83. {
  84. printf( "Grave error: could not open source \"%s\"\n", v );
  85. }
  86. }
  87. else if ( ! strcmp( s, ":track" ) )
  88. {
  89. int i;
  90. sscanf( v, "%X", &i );
  91. Track *t = (Track*)Loggable::find( i );
  92. assert( t );
  93. t->add( this );
  94. }
  95. free( s );
  96. }
  97. free( sa );
  98. #ifndef ENGINE
  99. if ( _track )
  100. _track->redraw();
  101. #endif
  102. }
  103. public:
  104. Region_Base ( )
  105. {
  106. _start = _offset = _end = 0;
  107. _clip = NULL;
  108. _scale = 1.0f;
  109. }
  110. #ifdef ENGINE
  111. /* for loggable */
  112. static Loggable *
  113. create ( char **sa )
  114. {
  115. Region_Base *r = new Region_Base;
  116. r->set( sa );
  117. return (Loggable *)r;
  118. }
  119. #else
  120. friend class Region;
  121. #endif
  122. };
  123. #ifndef ENGINE
  124. class Region : public Region_Base
  125. {
  126. static Fl_Boxtype _box;
  127. static Fl_Color _selection_color;
  128. static Fl_Color selection_color ( void ) { return _selection_color; }
  129. static void selection_color ( Fl_Color v ) { _selection_color = v; }
  130. enum trim_e { NO, LEFT, RIGHT };
  131. void trim ( enum trim_e t, int X );
  132. void init ( void );
  133. Region ( )
  134. {
  135. init();
  136. }
  137. bool current ( void ) const { return this == Track::belowmouse(); }
  138. public:
  139. static Loggable *
  140. create ( char **sa )
  141. {
  142. Region *r = new Region;
  143. r->set( sa );
  144. return (Loggable *)r;
  145. }
  146. ~Region ( )
  147. {
  148. log_destroy();
  149. }
  150. Fl_Boxtype box ( void ) const { return Region::_box; }
  151. Fl_Align align ( void ) const { return (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM /*| FL_ALIGN_CLIP*/ | FL_ALIGN_INSIDE); }
  152. Region ( const Region & rhs );
  153. Region ( Audio_File *c );
  154. Region ( Audio_File *c, Track *t, nframes_t o );
  155. int handle ( int m );
  156. void draw_box( int X, int Y, int W, int H );
  157. void draw ( int X, int Y, int W, int H );
  158. void resize ( void );
  159. void normalize ( void );
  160. };
  161. #endif