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.

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