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.

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