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.

157 lines
4.2KB

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