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
5.1KB

  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. #pragma once
  19. #include "Audio_File.H"
  20. #include "Timeline.H"
  21. /* Audio_Regions are "virtual" FLTK widgets; this is necessary because the
  22. * dimensions of real FLTK widgets are limited to 16-bits, which is
  23. * far too little for our purposes */
  24. #include "Sequence_Region.H"
  25. class Audio_Region : public Sequence_Region
  26. {
  27. /* not permitted */
  28. Audio_Region & operator = ( const Audio_Region &rhs );
  29. public:
  30. static bool inherit_track_color;
  31. struct Fade
  32. {
  33. enum fade_type_e { Linear = 0, Sigmoid, Logarithmic, Parabolic };
  34. enum fade_dir_e { In, Out };
  35. fade_type_e type;
  36. nframes_t length;
  37. Fade ( )
  38. {
  39. type = Linear;
  40. length = 0;
  41. }
  42. bool
  43. operator< ( const Fade &rhs ) const
  44. {
  45. return length < rhs.length;
  46. }
  47. float increment ( void ) const
  48. {
  49. return 1.0f / (float)length;
  50. }
  51. /** Return gain for frame /index/ of /nframes/ on a gain curve
  52. * of type /type/.*/
  53. /* FIXME: calling a function per sample is bad, switching on
  54. * type mid fade is bad. */
  55. inline float
  56. gain ( const float fi ) const
  57. {
  58. switch ( type )
  59. {
  60. case Linear:
  61. return fi;
  62. case Sigmoid:
  63. return (1.0f - cos( fi * M_PI )) / 2.0f;
  64. case Logarithmic:
  65. return pow( 0.1f, (1.0f - fi) * 3.0f );
  66. case Parabolic:
  67. return 1.0f - (1.0f - fi) * (1.0f - fi);
  68. default:
  69. return 1.0f;
  70. }
  71. }
  72. void apply ( sample_t *buf, fade_dir_e dir, long start, nframes_t end, nframes_t nframes ) const;
  73. };
  74. /* struct Fade_In : public Fade; */
  75. /* struct Fade_Out : public Fade; */
  76. private:
  77. Audio_File *_clip; /* clip this region represents */
  78. float _scale; /* amplitude adjustment */
  79. Fade _fade_in;
  80. Fade _fade_out;
  81. friend class Track; /* for _clip */
  82. protected:
  83. virtual void get ( Log_Entry &e ) const;
  84. virtual void set ( Log_Entry &e );
  85. public:
  86. static Fl_Boxtype _box;
  87. static Fl_Color _selection_color;
  88. Fl_Color selection_color ( void ) const { return _selection_color; }
  89. void selection_color ( Fl_Color v ) { _selection_color = v; }
  90. void init ( void );
  91. Audio_Region ( )
  92. {
  93. init();
  94. }
  95. bool current ( void ) const { return this == belowmouse(); }
  96. public:
  97. const char *source_name ( void ) const { return _clip->name(); }
  98. LOG_CREATE_FUNC( Audio_Region );
  99. SEQUENCE_WIDGET_CLONE_FUNC( Audio_Region );
  100. ~Audio_Region ( )
  101. {
  102. log_destroy();
  103. }
  104. Fl_Boxtype box ( void ) const { return Audio_Region::_box; }
  105. Fl_Align align ( void ) const { return (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM /*| FL_ALIGN_CLIP*/ | FL_ALIGN_INSIDE); }
  106. Audio_Region ( const Audio_Region & rhs );
  107. Audio_Region ( Audio_File *c );
  108. Audio_Region ( Audio_File *c, Sequence *t, nframes_t o );
  109. void draw_fade ( const Fade &fade, Fade::fade_dir_e dir, bool filled, int X, int W );
  110. int handle ( int m );
  111. void draw_box( void );
  112. void draw ( void );
  113. void resize ( void );
  114. void normalize ( void );
  115. /* Engine */
  116. nframes_t read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) const;
  117. nframes_t write ( nframes_t nframes );
  118. void prepare ( void );
  119. bool finalize ( nframes_t frame );
  120. };