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.

283 lines
6.8KB

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