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.

270 lines
6.6KB

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