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.

183 lines
5.7KB

  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 ** log_dump ( void )
  47. {
  48. // char *r;
  49. char **sa = (char**)malloc( sizeof( char* ) * 7 );
  50. int i = 0;
  51. asprintf( &sa[ i++ ], ":source \"%s\"", _clip->name() );
  52. asprintf( &sa[ i++ ], ":x %lu", _offset );
  53. asprintf( &sa[ i++ ], ":l %lu", _start );
  54. asprintf( &sa[ i++ ], ":r %lu", _end );
  55. asprintf( &sa[ i++ ], ":selected %d", _selected );
  56. asprintf( &sa[ i++ ], ":gain %f", _scale );
  57. sa[ i ] = NULL;
  58. // asprintf( &sa[4], ":track 0x%X", _track->id() );
  59. // asprintf( &r, ":x %lu\n:l %lu\n:r %lu\n:selected %d\n:gain %f", _offset, _start, _end, _selected, _scale );
  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. _selected = atoi( v );
  86. else
  87. if ( ! strcmp( s, ":gain" ) )
  88. _scale = atof( v );
  89. else
  90. if ( ! strcmp( s, ":source" ) )
  91. _clip = Audio_File::from_file( v );
  92. /* else */
  93. /* if ( ! strcmp( s, ":track" ) ) */
  94. /* { */
  95. /* int i; */
  96. /* sscanf( v, "%X", &i ); */
  97. /* Track *t = (Track*)Loggable::find( i ); */
  98. /* assert( t ); */
  99. /* t->add( this ); */
  100. /* } */
  101. free( s );
  102. }
  103. free( sa );
  104. if ( _track )
  105. _track->redraw();
  106. }
  107. Region ( )
  108. {
  109. init();
  110. }
  111. public:
  112. /* for loggable */
  113. static Loggable *
  114. create ( char **sa )
  115. {
  116. Region *r = new Region;
  117. r->set( sa );
  118. return (Loggable *)r;
  119. }
  120. ~Region ( )
  121. {
  122. log_destroy();
  123. }
  124. Fl_Boxtype box ( void ) const { return Region::_box; }
  125. Fl_Align align ( void ) const { return (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM /*| FL_ALIGN_CLIP*/ | FL_ALIGN_INSIDE); }
  126. Region ( const Region & rhs );
  127. Region ( Audio_File *c );
  128. int handle ( int m );
  129. void draw_box( int X, int Y, int W, int H );
  130. void draw ( int X, int Y, int W, int H );
  131. void resize ( void );
  132. void normalize ( void );
  133. void dump ( void );
  134. };
  135. #undef __CLASS__