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. static Fl_Boxtype _box;
  38. static Fl_Color _selection_color;
  39. static Fl_Color selection_color ( void ) { return _selection_color; }
  40. static void selection_color ( Fl_Color v ) { _selection_color = v; }
  41. enum trim_e { NO, LEFT, RIGHT };
  42. void trim ( enum trim_e t, int X );
  43. void init ( void );
  44. protected:
  45. const char *class_name ( void ) { return "Region"; }
  46. char ** get ( void )
  47. {
  48. // char *r;
  49. char **sa = (char**)malloc( sizeof( char* ) * 8 );
  50. int i = 0;
  51. asprintf( &sa[ i++ ], ":source \"%s\"", _clip ? _clip->name() : "" );
  52. asprintf( &sa[ i++ ], ":track 0x%X", _track ? _track->id() : 0 );
  53. asprintf( &sa[ i++ ], ":x %lu", _offset );
  54. asprintf( &sa[ i++ ], ":l %lu", _start );
  55. asprintf( &sa[ i++ ], ":r %lu", _end );
  56. asprintf( &sa[ i++ ], ":selected %d", selected() );
  57. asprintf( &sa[ i++ ], ":gain %f", _scale );
  58. sa[ i ] = NULL;
  59. return sa;
  60. }
  61. void
  62. set ( char **sa )
  63. {
  64. for ( int i = 0; sa[i]; ++i )
  65. {
  66. char *s = sa[i];
  67. strtok( s, " " );
  68. char *v = s + strlen( s ) + 1;
  69. if ( *v == '"' )
  70. {
  71. v++;
  72. v[ strlen( v ) - 2 ] = '\0';
  73. }
  74. if ( ! strcmp( s, ":x" ) )
  75. _offset = atol( v );
  76. else
  77. if ( ! strcmp( s, ":l" ) )
  78. _start = atol( v );
  79. else
  80. if ( ! strcmp( s, ":r" ) )
  81. _end = atol( v );
  82. else
  83. if ( ! strcmp( s, ":selected" ) )
  84. {
  85. if ( atoi( v ) )
  86. select();
  87. else
  88. deselect();
  89. }
  90. else
  91. if ( ! strcmp( s, ":gain" ) )
  92. _scale = atof( v );
  93. else
  94. if ( ! strcmp( s, ":source" ) )
  95. {
  96. if ( ! ( _clip = Audio_File::from_file( v ) ) )
  97. {
  98. printf( "Grave error: could not open source \"%s\"\n", v );
  99. }
  100. }
  101. else
  102. if ( ! strcmp( s, ":track" ) )
  103. {
  104. int i;
  105. sscanf( v, "%X", &i );
  106. Track *t = (Track*)Loggable::find( i );
  107. assert( t );
  108. t->add( this );
  109. }
  110. free( s );
  111. }
  112. free( sa );
  113. if ( _track )
  114. _track->redraw();
  115. }
  116. Region ( )
  117. {
  118. init();
  119. }
  120. bool current ( void ) const { return this == Track::belowmouse(); }
  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__