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.

188 lines
5.5KB

  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 if ( ! strcmp( s, ":l" ) )
  77. _start = atol( v );
  78. else if ( ! strcmp( s, ":r" ) )
  79. _end = atol( v );
  80. else if ( ! strcmp( s, ":selected" ) )
  81. {
  82. if ( atoi( v ) )
  83. select();
  84. else
  85. deselect();
  86. }
  87. else if ( ! strcmp( s, ":gain" ) )
  88. _scale = atof( v );
  89. else if ( ! strcmp( s, ":source" ) )
  90. {
  91. if ( ! ( _clip = Audio_File::from_file( v ) ) )
  92. {
  93. printf( "Grave error: could not open source \"%s\"\n", v );
  94. }
  95. }
  96. else if ( ! strcmp( s, ":track" ) )
  97. {
  98. int i;
  99. sscanf( v, "%X", &i );
  100. Track *t = (Track*)Loggable::find( i );
  101. assert( t );
  102. t->add( this );
  103. }
  104. free( s );
  105. }
  106. free( sa );
  107. if ( _track )
  108. _track->redraw();
  109. }
  110. Region ( )
  111. {
  112. init();
  113. }
  114. bool current ( void ) const { return this == Track::belowmouse(); }
  115. public:
  116. /* for loggable */
  117. static Loggable *
  118. create ( char **sa )
  119. {
  120. Region *r = new Region;
  121. r->set( sa );
  122. return (Loggable *)r;
  123. }
  124. ~Region ( )
  125. {
  126. log_destroy();
  127. }
  128. Fl_Boxtype box ( void ) const { return Region::_box; }
  129. Fl_Align align ( void ) const { return (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM /*| FL_ALIGN_CLIP*/ | FL_ALIGN_INSIDE); }
  130. Region ( const Region & rhs );
  131. Region ( Audio_File *c );
  132. Region ( Audio_File *c, Track *t, nframes_t o );
  133. int handle ( int m );
  134. void draw_box( int X, int Y, int W, int H );
  135. void draw ( int X, int Y, int W, int H );
  136. void resize ( void );
  137. void normalize ( void );
  138. void dump ( void );
  139. };
  140. #undef __CLASS__