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.

166 lines
5.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. #pragma once
  19. #include "Timeline.H"
  20. #include "Sequence_Region.H"
  21. class Audio_File;
  22. class Peaks_Redraw_Request;
  23. class Fl_Menu_;
  24. class Fl_Menu_Button;
  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. nframes_t _loop; /* loop point */
  82. friend class Track; /* for _clip */
  83. Fl_Menu_Button & menu ( void );
  84. static void peaks_pending_cb ( void *v );
  85. void peaks_pending_cb ( Peaks_Redraw_Request *r );
  86. static void menu_cb ( Fl_Widget *w, void *v );
  87. void menu_cb ( const Fl_Menu_ *m );
  88. void draw_fade ( const Fade &fade, Fade::fade_dir_e dir, bool filled, int X, int W );
  89. protected:
  90. virtual void get ( Log_Entry &e ) const;
  91. virtual void set ( Log_Entry &e );
  92. int handle ( int m );
  93. void draw_box( void );
  94. void draw ( void );
  95. void resize ( void );
  96. public:
  97. LOG_CREATE_FUNC( Audio_Region );
  98. SEQUENCE_WIDGET_CLONE_FUNC( Audio_Region );
  99. static Fl_Boxtype _box;
  100. static Fl_Color _selection_color;
  101. Fl_Color selection_color ( void ) const { return _selection_color; }
  102. void selection_color ( Fl_Color v ) { _selection_color = v; }
  103. void init ( void );
  104. Audio_Region ( )
  105. {
  106. init();
  107. }
  108. bool current ( void ) const { return this == belowmouse(); }
  109. const char * source_name ( void ) const;
  110. Audio_Region ( const Audio_Region & rhs );
  111. Audio_Region ( Audio_File *c );
  112. Audio_Region ( Audio_File *c, Sequence *t, nframes_t o );
  113. ~Audio_Region ( );
  114. Fl_Boxtype box ( void ) const { return Audio_Region::_box; }
  115. Fl_Align align ( void ) const { return (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM /*| FL_ALIGN_CLIP*/ | FL_ALIGN_INSIDE); }
  116. void normalize ( void );
  117. void split ( nframes_t where );
  118. /* Engine */
  119. nframes_t read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) const;
  120. nframes_t write ( nframes_t nframes );
  121. void prepare ( void );
  122. bool finalize ( nframes_t frame );
  123. };