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.

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