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.

104 lines
3.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 "../Control_Sequence.H"
  19. #include "../Transport.H" // for ->frame
  20. #include "util/Thread.H"
  21. #include <list>
  22. using std::list;
  23. /**********/
  24. /* Engine */
  25. /**********/
  26. static inline float
  27. linear_interpolate ( float y1, float y2, float mu )
  28. {
  29. // return y1 + mu * ( y2 - y1 );
  30. return y1 * ( 1.0f - mu ) + y2 * mu;
  31. }
  32. static inline float
  33. sigmoid_interpolate ( float y1, float y2, float mu )
  34. {
  35. return linear_interpolate( y1, y2, ( 1 - cos( mu * M_PI ) ) / 2 );
  36. }
  37. /** fill buf with /nframes/ of interpolated control curve values
  38. * starting at /frame/ */
  39. nframes_t
  40. Control_Sequence::play ( sample_t *buf, nframes_t frame, nframes_t nframes )
  41. {
  42. THREAD_ASSERT( RT );
  43. Control_Point *p2, *p1 = (Control_Point*)&_widgets.front();
  44. nframes_t n = nframes;
  45. for ( list <Sequence_Widget *>::const_iterator i = _widgets.begin();
  46. i != _widgets.end(); ++i, p1 = p2 )
  47. {
  48. p2 = (Control_Point*)(*i);
  49. if ( p2->when() < frame )
  50. continue;
  51. /* do incremental linear interpolation */
  52. const nframes_t len = p2->when() - p1->when();
  53. /* scale to -1.0 to 1.0 */
  54. const float y1 = 1.0f - ( 2.0f * p1->control() );
  55. const float y2 = 1.0f - ( 2.0f * p2->control() );
  56. const nframes_t start = frame - p1->when();
  57. const float incr = ( y2 - y1 ) / (float)len;
  58. float v = y1 + start * incr;
  59. for ( nframes_t i = start; i < len && n--; ++i, v += incr )
  60. *(buf++) = v;
  61. }
  62. return nframes - n;
  63. }
  64. nframes_t
  65. Control_Sequence::process ( nframes_t nframes )
  66. {
  67. THREAD_ASSERT( RT );
  68. if ( _output->connected() ) /* don't waste CPU on disconnected ports */
  69. {
  70. void *buf = _output->buffer( nframes );
  71. return play( (sample_t*)buf, transport->frame, nframes );
  72. }
  73. else
  74. return nframes;
  75. }