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.

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