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.

165 lines
4.4KB

  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_Track.H"
  19. #include "dsp.h"
  20. #include <Fl/fl_ask.H>
  21. static
  22. void
  23. deurlify ( char *url )
  24. {
  25. char *r, *w;
  26. r = w = url;
  27. for ( ; *r; r++, w++ )
  28. {
  29. if ( *r == '%' )
  30. {
  31. char data[3] = { *(r + 1), *(r + 2), 0 };
  32. int c;
  33. sscanf( data, "%2X", &c );
  34. *w = c;
  35. r += 2;
  36. }
  37. else
  38. *w = *r;
  39. }
  40. *w = NULL;
  41. }
  42. /** event handler that supports DND of audio clips */
  43. int
  44. Audio_Track::handle ( int m )
  45. {
  46. switch ( m )
  47. {
  48. case FL_DND_DRAG:
  49. return Track::handle( m ) | 1;
  50. /* case FL_DND_ENTER: */
  51. /* case FL_DND_LEAVE: */
  52. case FL_DND_RELEASE:
  53. return 1;
  54. case FL_PASTE:
  55. {
  56. const char *text = Fl::event_text();
  57. if ( ! strcmp( text, "Region" ) )
  58. return 1;
  59. char *file;
  60. if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
  61. {
  62. printf( "invalid drop \"%s\"\n", text );
  63. return 0;
  64. }
  65. deurlify( file );
  66. printf( "pasted file \"%s\"\n", file );
  67. fl_cursor( FL_CURSOR_WAIT );
  68. Fl::check();
  69. Audio_File *c = Audio_File::from_file( file );
  70. fl_cursor( FL_CURSOR_DEFAULT );
  71. if ( ! c )
  72. {
  73. fl_alert( "Could not import file \"%s\": Unsupported file type.", file );
  74. printf( "could not open file\n" );
  75. free( file );
  76. return 0;
  77. }
  78. // Region *r =
  79. new Region( c, this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ) );
  80. redraw();
  81. return 1;
  82. }
  83. default:
  84. return Track::handle( m );
  85. }
  86. }
  87. /**********/
  88. /* Engine */
  89. /**********/
  90. /* THREAD: IO */
  91. /** determine region coverage and fill /buf/ with interleaved samples
  92. * from /frame/ to /nframes/ for exactly /channels/ channels. */
  93. nframes_t
  94. Audio_Track::play ( sample_t *buf, nframes_t frame, nframes_t nframes, int channels )
  95. {
  96. sample_t *cbuf = new sample_t[ nframes ];
  97. memset( cbuf, 0, nframes * sizeof( sample_t ) );
  98. /* quick and dirty--let the regions figure out coverage for themselves */
  99. for ( list <Track_Widget *>::const_iterator i = _widgets.begin();
  100. i != _widgets.end(); i++ )
  101. {
  102. const Region *r = (Region*)(*i);
  103. for ( int i = channels; i--; )
  104. {
  105. int nfr;
  106. if ( ! ( nfr = r->read( cbuf, frame, nframes, i ) ) )
  107. /* error ? */
  108. continue;
  109. if ( channels == 1 )
  110. buffer_mix( buf, cbuf, nframes );
  111. else
  112. buffer_interleave_one_channel_and_mix( buf, cbuf, i, channels, nframes );
  113. }
  114. }
  115. delete[] cbuf;
  116. /* FIXME: bogus */
  117. return nframes;
  118. }
  119. /* /\* THREAD: RT *\/ */
  120. /* nframes_t */
  121. /* Audio_Track::process ( nframes_t nframes ) */
  122. /* { */
  123. /* return disktream->process( nframes ); */
  124. /* } */