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.

194 lines
6.2KB

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