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.

249 lines
6.5KB

  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_DND_DRAG:
  105. return Sequence::handle( m ) | 1;
  106. /* case FL_DND_ENTER: */
  107. /* case FL_DND_LEAVE: */
  108. case FL_DND_RELEASE:
  109. return 1;
  110. case FL_PASTE:
  111. {
  112. const char *text = Fl::event_text();
  113. if ( ! strcmp( text, "Region" ) )
  114. return 1;
  115. char *file;
  116. if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
  117. {
  118. printf( "invalid drop \"%s\"\n", text );
  119. return 0;
  120. }
  121. deurlify( file );
  122. printf( "pasted file \"%s\"\n", file );
  123. fl_cursor( FL_CURSOR_WAIT );
  124. Fl::check();
  125. Audio_File *c = Audio_File::from_file( file );
  126. fl_cursor( FL_CURSOR_DEFAULT );
  127. if ( ! c )
  128. {
  129. fl_alert( "Could not import file \"%s\": Unsupported file type.", file );
  130. printf( "could not open file\n" );
  131. free( file );
  132. return 0;
  133. }
  134. // Region *r =
  135. new Region( c, this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ) );
  136. redraw();
  137. return 1;
  138. }
  139. default:
  140. return Sequence::handle( m );
  141. }
  142. }
  143. /**********/
  144. /* Engine */
  145. /**********/
  146. /* THREAD: IO */
  147. /** determine region coverage and fill /buf/ with interleaved samples
  148. * from /frame/ to /nframes/ for exactly /channels/ channels. */
  149. nframes_t
  150. Audio_Sequence::play ( sample_t *buf, nframes_t frame, nframes_t nframes, int channels )
  151. {
  152. sample_t *cbuf = new sample_t[ nframes ];
  153. memset( cbuf, 0, nframes * sizeof( sample_t ) );
  154. /* quick and dirty--let the regions figure out coverage for themselves */
  155. for ( list <Sequence_Widget *>::const_iterator i = _widgets.begin();
  156. i != _widgets.end(); ++i )
  157. {
  158. const Region *r = (Region*)(*i);
  159. for ( int i = channels; i--; )
  160. {
  161. int nfr;
  162. if ( ! ( nfr = r->read( cbuf, frame, nframes, i ) ) )
  163. /* error ? */
  164. continue;
  165. if ( channels == 1 )
  166. buffer_mix( buf, cbuf, nframes );
  167. else
  168. buffer_interleave_one_channel_and_mix( buf, cbuf, i, channels, nframes );
  169. }
  170. }
  171. delete[] cbuf;
  172. /* FIXME: bogus */
  173. return nframes;
  174. }
  175. /* /\* THREAD: RT *\/ */
  176. /* nframes_t */
  177. /* Audio_Sequence::process ( nframes_t nframes ) */
  178. /* { */
  179. /* return disktream->process( nframes ); */
  180. /* } */