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.

238 lines
6.3KB

  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 "Audio_Sequence.H"
  19. #include "Waveform.H"
  20. #include "dsp.h"
  21. #include <Fl/fl_ask.H>
  22. static
  23. void
  24. deurlify ( char *url )
  25. {
  26. char *r, *w;
  27. r = w = url;
  28. for ( ; *r; r++, w++ )
  29. {
  30. if ( *r == '%' )
  31. {
  32. char data[3] = { *(r + 1), *(r + 2), 0 };
  33. int c;
  34. sscanf( data, "%2X", &c );
  35. *w = c;
  36. r += 2;
  37. }
  38. else
  39. *w = *r;
  40. }
  41. *w = NULL;
  42. }
  43. void
  44. Audio_Sequence::draw ( void )
  45. {
  46. Sequence::draw();
  47. int xfades = 0;
  48. /* draw crossfades */
  49. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
  50. {
  51. Sequence_Widget *o = overlaps( *r );
  52. if ( o )
  53. {
  54. if ( *o <= **r )
  55. {
  56. /* if ( o->x() == (*r)->x() && o->w() == (*r)->w() ) */
  57. /* printf( "complete superposition\n" ); */
  58. if ( (*r)->x() >= o->x() && (*r)->x() + (*r)->w() <= o->x() + o->w() )
  59. /* completely inside */
  60. continue;
  61. ++xfades;
  62. Rectangle b( (*r)->x(),
  63. o->y(),
  64. (o->x() + o->w()) - (*r)->x(),
  65. o->h() );
  66. Fl_Color c = fl_color_average( o->box_color(), (*r)->box_color(), 0.50f );
  67. c = fl_color_average( c, FL_YELLOW, 0.30f );
  68. fl_push_clip( b.x, b.y, b.w, b.h );
  69. draw_box( FL_FLAT_BOX, b.x - 100, b.y, b.w + 200, b.h, c );
  70. draw_box( FL_UP_FRAME, b.x - 100, b.y, b.w + 200, b.h, c );
  71. fl_pop_clip();
  72. }
  73. }
  74. }
  75. for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
  76. {
  77. Sequence_Widget *o = overlaps( *r );
  78. if ( o )
  79. {
  80. if ( *o <= **r )
  81. {
  82. if ( (*r)->x() >= o->x() && (*r)->x() + (*r)->w() <= o->x() + o->w() )
  83. /* completely inside */
  84. continue;
  85. Rectangle b( (*r)->x(), o->y(), (o->x() + o->w()) - (*r)->x(), o->h() );
  86. /* draw overlapping waveforms in X-ray style. */
  87. bool t = Waveform::fill;
  88. Waveform::fill = false;
  89. fl_push_clip( b.x, b.y, b.w, b.h );
  90. o->draw();
  91. (*r)->draw();
  92. fl_pop_clip();
  93. Waveform::fill = t;
  94. }
  95. }
  96. }
  97. }
  98. /** event handler that supports DND of audio clips */
  99. int
  100. Audio_Sequence::handle ( int m )
  101. {
  102. switch ( m )
  103. {
  104. case FL_PASTE:
  105. {
  106. const char *text = Fl::event_text();
  107. if ( ! strcmp( text, "Region" ) )
  108. return 1;
  109. char *file;
  110. if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
  111. {
  112. printf( "invalid drop \"%s\"\n", text );
  113. return 0;
  114. }
  115. deurlify( file );
  116. printf( "pasted file \"%s\"\n", file );
  117. fl_cursor( FL_CURSOR_WAIT );
  118. Fl::check();
  119. Audio_File *c = Audio_File::from_file( file );
  120. fl_cursor( FL_CURSOR_DEFAULT );
  121. if ( ! c )
  122. {
  123. fl_alert( "Could not import file \"%s\": Unsupported file type.", file );
  124. printf( "could not open file\n" );
  125. free( file );
  126. return 0;
  127. }
  128. // Region *r =
  129. new Region( c, this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ) );
  130. redraw();
  131. return 1;
  132. }
  133. default:
  134. return Sequence::handle( m );
  135. }
  136. }
  137. /**********/
  138. /* Engine */
  139. /**********/
  140. /* THREAD: IO */
  141. /** determine region coverage and fill /buf/ with interleaved samples
  142. * from /frame/ to /nframes/ for exactly /channels/ channels. */
  143. nframes_t
  144. Audio_Sequence::play ( sample_t *buf, nframes_t frame, nframes_t nframes, int channels )
  145. {
  146. sample_t *cbuf = new sample_t[ nframes ];
  147. memset( cbuf, 0, nframes * sizeof( sample_t ) );
  148. /* quick and dirty--let the regions figure out coverage for themselves */
  149. for ( list <Sequence_Widget *>::const_iterator i = _widgets.begin();
  150. i != _widgets.end(); ++i )
  151. {
  152. const Region *r = (Region*)(*i);
  153. for ( int i = channels; i--; )
  154. {
  155. int nfr;
  156. if ( ! ( nfr = r->read( cbuf, frame, nframes, i ) ) )
  157. /* error ? */
  158. continue;
  159. if ( channels == 1 )
  160. buffer_mix( buf, cbuf, nframes );
  161. else
  162. buffer_interleave_one_channel_and_mix( buf, cbuf, i, channels, nframes );
  163. }
  164. }
  165. delete[] cbuf;
  166. /* FIXME: bogus */
  167. return nframes;
  168. }
  169. /* /\* THREAD: RT *\/ */
  170. /* nframes_t */
  171. /* Audio_Sequence::process ( nframes_t nframes ) */
  172. /* { */
  173. /* return disktream->process( nframes ); */
  174. /* } */