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.

189 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. // 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. _selected = atoi( v );
  85. else
  86. if ( ! strcmp( s, ":gain" ) )
  87. _scale = atof( v );
  88. else
  89. 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
  97. if ( ! strcmp( s, ":track" ) )
  98. {
  99. int i;
  100. sscanf( v, "%X", &i );
  101. Track *t = (Track*)Loggable::find( i );
  102. assert( t );
  103. t->add( this );
  104. }
  105. free( s );
  106. }
  107. free( sa );
  108. if ( _track )
  109. _track->redraw();
  110. }
  111. Region ( )
  112. {
  113. init();
  114. }
  115. public:
  116. /* for loggable */
  117. static Loggable *
  118. create ( char **sa )
  119. {
  120. Region *r = new Region;
  121. r->set( sa );
  122. r->log_create();
  123. return (Loggable *)r;
  124. }
  125. ~Region ( )
  126. {
  127. log_destroy();
  128. }
  129. Fl_Boxtype box ( void ) const { return Region::_box; }
  130. Fl_Align align ( void ) const { return (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM /*| FL_ALIGN_CLIP*/ | FL_ALIGN_INSIDE); }
  131. Region ( const Region & rhs );
  132. Region ( Audio_File *c );
  133. Region ( Audio_File *c, Track *t, nframes_t o );
  134. int handle ( int m );
  135. void draw_box( int X, int Y, int W, int H );
  136. void draw ( int X, int Y, int W, int H );
  137. void resize ( void );
  138. void normalize ( void );
  139. void dump ( void );
  140. };
  141. #undef __CLASS__