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.

286 lines
6.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. /* An Audio_Sequence is a sequence of Audio_Regions. Takes and 'track
  19. * contents' consist of these objects */
  20. #include <Fl/fl_ask.H>
  21. #include "Audio_Sequence.H"
  22. #include "Waveform.H"
  23. #include <list>
  24. using namespace std;
  25. #include "Track.H"
  26. #include "Engine/Audio_File.H" // for ::from_file()
  27. #include "Transport.H" // for locate()
  28. Audio_Sequence::Audio_Sequence ( Track *track ) : Sequence( track )
  29. {
  30. _track = track;
  31. if ( track )
  32. track->add( this );
  33. log_create();
  34. /* FIXME: temporary */
  35. labeltype( FL_NO_LABEL );
  36. }
  37. Audio_Sequence::~Audio_Sequence ( )
  38. {
  39. Loggable::block_start();
  40. clear();
  41. log_destroy();
  42. track()->remove( this );
  43. Loggable::block_end();
  44. }
  45. /** return a pointer to the current capture region for this sequence */
  46. const Audio_Region *
  47. Audio_Sequence::capture_region ( void ) const
  48. {
  49. return track()->capture_region();
  50. }
  51. void
  52. Audio_Sequence::get ( Log_Entry &e ) const
  53. {
  54. e.add( ":track", _track );
  55. e.add( ":name", name() );
  56. }
  57. void
  58. Audio_Sequence::set ( Log_Entry &e )
  59. {
  60. for ( int i = 0; i < e.size(); ++i )
  61. {
  62. const char *s, *v;
  63. e.get( i, &s, &v );
  64. if ( ! strcmp( ":track", s ) )
  65. {
  66. int i;
  67. sscanf( v, "%X", &i );
  68. Track *t = (Track*)Loggable::find( i );
  69. assert( t );
  70. t->sequence( this );
  71. }
  72. else if ( ! strcmp( ":name", s ) )
  73. name( v );
  74. }
  75. }
  76. static
  77. void
  78. deurlify ( char *url )
  79. {
  80. char *r, *w;
  81. r = w = url;
  82. for ( ; *r; r++, w++ )
  83. {
  84. if ( *r == '%' )
  85. {
  86. char data[3] = { *(r + 1), *(r + 2), 0 };
  87. int c;
  88. sscanf( data, "%2X", &c );
  89. *w = c;
  90. r += 2;
  91. }
  92. else
  93. *w = *r;
  94. }
  95. *w = NULL;
  96. }
  97. void
  98. Audio_Sequence::handle_widget_change ( nframes_t start, nframes_t length )
  99. {
  100. Sequence::handle_widget_change( start, length );
  101. /* a region has changed. we may need to rebuffer... */
  102. /* trigger rebuffer */
  103. /* FIXME: we really only need to rebuffer *this* sequence! */
  104. /* FIXME: how does this fit into the selection? */
  105. if ( transport->rolling && ( start > transport->frame || start + length > transport->frame ) )
  106. transport->locate( transport->frame );
  107. }
  108. void
  109. Audio_Sequence::draw ( void )
  110. {
  111. Sequence::draw();
  112. int xfades = 0;
  113. /* draw crossfades */
  114. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
  115. {
  116. Sequence_Widget *o = overlaps( *r );
  117. if ( o )
  118. {
  119. if ( *o <= **r )
  120. {
  121. /* if ( o->x() == (*r)->x() && o->w() == (*r)->w() ) */
  122. /* printf( "complete superposition\n" ); */
  123. if ( o->contains( *r ) )
  124. /* completely inside */
  125. continue;
  126. ++xfades;
  127. Rectangle b( (*r)->x(),
  128. o->y(),
  129. (o->x() + o->w()) - (*r)->x(),
  130. o->h() );
  131. Fl_Color c = fl_color_average( o->box_color(), (*r)->box_color(), 0.50f );
  132. c = fl_color_average( c, FL_YELLOW, 0.30f );
  133. fl_push_clip( b.x, b.y, b.w, b.h );
  134. draw_box( FL_FLAT_BOX, b.x - 100, b.y, b.w + 200, b.h, c );
  135. draw_box( FL_UP_FRAME, b.x - 100, b.y, b.w + 200, b.h, c );
  136. fl_pop_clip();
  137. }
  138. }
  139. }
  140. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
  141. {
  142. Sequence_Widget *o = overlaps( *r );
  143. if ( o )
  144. {
  145. if ( *o <= **r )
  146. {
  147. if ( o->contains( *r ) )
  148. /* completely inside */
  149. continue;
  150. Rectangle b( (*r)->x(), o->y(), (o->x() + o->w()) - (*r)->x(), o->h() );
  151. /* draw overlapping waveforms in X-ray style. */
  152. bool t = Waveform::fill;
  153. Waveform::fill = false;
  154. fl_push_clip( b.x, b.y, b.w, b.h );
  155. o->draw();
  156. (*r)->draw();
  157. fl_pop_clip();
  158. Waveform::fill = t;
  159. }
  160. }
  161. }
  162. }
  163. /** event handler that supports DND of audio clips */
  164. int
  165. Audio_Sequence::handle ( int m )
  166. {
  167. switch ( m )
  168. {
  169. case FL_PASTE:
  170. {
  171. const char *text = Fl::event_text();
  172. if ( ! strcmp( text, "Audio_Region" ) )
  173. return 1;
  174. char *file;
  175. if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
  176. {
  177. printf( "invalid drop \"%s\"\n", text );
  178. return 0;
  179. }
  180. deurlify( file );
  181. printf( "pasted file \"%s\"\n", file );
  182. fl_cursor( FL_CURSOR_WAIT );
  183. Fl::check();
  184. Audio_File *c = Audio_File::from_file( file );
  185. fl_cursor( FL_CURSOR_DEFAULT );
  186. if ( ! c )
  187. {
  188. fl_alert( "Could not import file \"%s\": Unsupported file type.", file );
  189. printf( "could not open file\n" );
  190. free( file );
  191. return 0;
  192. }
  193. free( file );
  194. // Audio_Region *r =
  195. new Audio_Region( c, this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ) );
  196. redraw();
  197. return 1;
  198. }
  199. default:
  200. return Sequence::handle( m );
  201. }
  202. }