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.

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