Non reinvents the DAW. Powerful enough to form a complete studio, fast and light enough to run on low-end hardware like the eeePC or Raspberry Pi, and so reliable that it can be used live https://non.tuxfamily.org/
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.0KB

  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 Audio_Region : public Sequence_Region
  24. {
  25. /* not permitted */
  26. Audio_Region & operator = ( const Audio_Region &rhs );
  27. public:
  28. static bool inherit_track_color;
  29. struct Fade
  30. {
  31. enum fade_type_e { Linear = 0, Sigmoid, Logarithmic, Parabolic };
  32. enum fade_dir_e { In, Out };
  33. fade_type_e type;
  34. nframes_t length;
  35. Fade ( )
  36. {
  37. type = Linear;
  38. length = 0;
  39. }
  40. bool
  41. operator< ( const Fade &rhs ) const
  42. {
  43. return length < rhs.length;
  44. }
  45. float increment ( void ) const
  46. {
  47. return 1.0f / (float)length;
  48. }
  49. /** Return gain for frame /index/ of /nframes/ on a gain curve
  50. * of type /type/.*/
  51. /* FIXME: calling a function per sample is bad, switching on
  52. * type mid fade is bad. */
  53. inline float
  54. gain ( const float fi ) const
  55. {
  56. switch ( type )
  57. {
  58. case Linear:
  59. return fi;
  60. case Sigmoid:
  61. return (1.0f - cos( fi * M_PI )) / 2.0f;
  62. case Logarithmic:
  63. return pow( 0.1f, (1.0f - fi) * 3.0f );
  64. case Parabolic:
  65. return 1.0f - (1.0f - fi) * (1.0f - fi);
  66. default:
  67. return 1.0f;
  68. }
  69. }
  70. void apply ( sample_t *buf, fade_dir_e dir, long start, nframes_t end, nframes_t nframes ) const;
  71. };
  72. /* struct Fade_In : public Fade; */
  73. /* struct Fade_Out : public Fade; */
  74. private:
  75. Audio_File *_clip; /* clip this region represents */
  76. float _scale; /* amplitude adjustment */
  77. Fade _fade_in;
  78. Fade _fade_out;
  79. friend class Track; /* for _clip */
  80. static void peaks_pending_cb ( void *v );
  81. void peaks_pending_cb ( Peaks_Redraw_Request *r );
  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;
  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. };