audio_file_processor.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * audio_file_processor.h - declaration of class audioFileProcessor
  3. * (instrument-plugin for using audio-files)
  4. *
  5. * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef AUDIO_FILE_PROCESSOR_H
  26. #define AUDIO_FILE_PROCESSOR_H
  27. #include <QPixmap>
  28. #include "Instrument.h"
  29. #include "InstrumentView.h"
  30. #include "SampleBuffer.h"
  31. #include "Knob.h"
  32. #include "PixmapButton.h"
  33. #include "AutomatableButton.h"
  34. #include "ComboBox.h"
  35. class audioFileProcessor : public Instrument
  36. {
  37. Q_OBJECT
  38. public:
  39. audioFileProcessor( InstrumentTrack * _instrument_track );
  40. virtual ~audioFileProcessor();
  41. virtual void playNote( NotePlayHandle * _n,
  42. sampleFrame * _working_buffer );
  43. virtual void deleteNotePluginData( NotePlayHandle * _n );
  44. virtual void saveSettings( QDomDocument & _doc,
  45. QDomElement & _parent );
  46. virtual void loadSettings( const QDomElement & _this );
  47. virtual void loadFile( const QString & _file );
  48. virtual QString nodeName() const;
  49. virtual int getBeatLen( NotePlayHandle * _n ) const;
  50. virtual f_cnt_t desiredReleaseFrames() const
  51. {
  52. return 128;
  53. }
  54. virtual PluginView * instantiateView( QWidget * _parent );
  55. public slots:
  56. void setAudioFile( const QString & _audio_file, bool _rename = true );
  57. private slots:
  58. void reverseModelChanged();
  59. void ampModelChanged();
  60. void loopPointChanged();
  61. void startPointChanged();
  62. void endPointChanged();
  63. void pointChanged();
  64. void stutterModelChanged();
  65. signals:
  66. void isPlaying( f_cnt_t _current_frame );
  67. private:
  68. typedef SampleBuffer::handleState handleState;
  69. SampleBuffer m_sampleBuffer;
  70. FloatModel m_ampModel;
  71. FloatModel m_startPointModel;
  72. FloatModel m_endPointModel;
  73. FloatModel m_loopPointModel;
  74. BoolModel m_reverseModel;
  75. IntModel m_loopModel;
  76. BoolModel m_stutterModel;
  77. ComboBoxModel m_interpolationModel;
  78. f_cnt_t m_nextPlayStartPoint;
  79. bool m_nextPlayBackwards;
  80. friend class AudioFileProcessorView;
  81. } ;
  82. class AudioFileProcessorWaveView;
  83. class AudioFileProcessorView : public InstrumentViewFixedSize
  84. {
  85. Q_OBJECT
  86. public:
  87. AudioFileProcessorView( Instrument * _instrument, QWidget * _parent );
  88. virtual ~AudioFileProcessorView();
  89. void newWaveView();
  90. protected slots:
  91. void sampleUpdated();
  92. void openAudioFile();
  93. protected:
  94. virtual void dragEnterEvent( QDragEnterEvent * _dee );
  95. virtual void dropEvent( QDropEvent * _de );
  96. virtual void paintEvent( QPaintEvent * );
  97. private:
  98. virtual void modelChanged();
  99. static QPixmap * s_artwork;
  100. AudioFileProcessorWaveView * m_waveView;
  101. Knob * m_ampKnob;
  102. Knob * m_startKnob;
  103. Knob * m_endKnob;
  104. Knob * m_loopKnob;
  105. PixmapButton * m_openAudioFileButton;
  106. PixmapButton * m_reverseButton;
  107. automatableButtonGroup * m_loopGroup;
  108. PixmapButton * m_stutterButton;
  109. ComboBox * m_interpBox;
  110. } ;
  111. class AudioFileProcessorWaveView : public QWidget
  112. {
  113. Q_OBJECT
  114. protected:
  115. virtual void enterEvent( QEvent * _e );
  116. virtual void leaveEvent( QEvent * _e );
  117. virtual void mousePressEvent( QMouseEvent * _me );
  118. virtual void mouseReleaseEvent( QMouseEvent * _me );
  119. virtual void mouseMoveEvent( QMouseEvent * _me );
  120. virtual void wheelEvent( QWheelEvent * _we );
  121. virtual void paintEvent( QPaintEvent * _pe );
  122. public:
  123. enum knobType
  124. {
  125. start,
  126. end,
  127. loop
  128. } ;
  129. class knob : public ::Knob
  130. {
  131. const AudioFileProcessorWaveView * m_waveView;
  132. const Knob * m_relatedKnob;
  133. public:
  134. knob( QWidget * _parent ) :
  135. ::Knob( knobBright_26, _parent ),
  136. m_waveView( 0 ),
  137. m_relatedKnob( 0 )
  138. {
  139. setFixedSize( 37, 47 );
  140. }
  141. void setWaveView( const AudioFileProcessorWaveView * _wv )
  142. {
  143. m_waveView = _wv;
  144. }
  145. void setRelatedKnob( const Knob * _knob )
  146. {
  147. m_relatedKnob = _knob;
  148. }
  149. void slideBy( double _v, bool _check_bound = true )
  150. {
  151. slideTo( model()->value() + _v, _check_bound );
  152. }
  153. void slideTo( double _v, bool _check_bound = true );
  154. protected:
  155. float getValue( const QPoint & _p );
  156. private:
  157. bool checkBound( double _v ) const;
  158. } ;
  159. public slots:
  160. void update()
  161. {
  162. updateGraph();
  163. QWidget::update();
  164. }
  165. void isPlaying( f_cnt_t _current_frame );
  166. private:
  167. static const int s_padding = 2;
  168. enum draggingType
  169. {
  170. wave,
  171. sample_start,
  172. sample_end,
  173. sample_loop
  174. } ;
  175. SampleBuffer& m_sampleBuffer;
  176. QPixmap m_graph;
  177. f_cnt_t m_from;
  178. f_cnt_t m_to;
  179. f_cnt_t m_last_from;
  180. f_cnt_t m_last_to;
  181. float m_last_amp;
  182. knob * m_startKnob;
  183. knob * m_endKnob;
  184. knob * m_loopKnob;
  185. f_cnt_t m_startFrameX;
  186. f_cnt_t m_endFrameX;
  187. f_cnt_t m_loopFrameX;
  188. bool m_isDragging;
  189. QPoint m_draggingLastPoint;
  190. draggingType m_draggingType;
  191. bool m_reversed;
  192. f_cnt_t m_framesPlayed;
  193. bool m_animation;
  194. public:
  195. AudioFileProcessorWaveView( QWidget * _parent, int _w, int _h, SampleBuffer& buf );
  196. void setKnobs(knob *_start, knob *_end, knob *_loop );
  197. void updateSampleRange();
  198. private:
  199. void zoom( const bool _out = false );
  200. void slide( int _px );
  201. void slideSamplePointByPx( knobType _point, int _px );
  202. void slideSamplePointByFrames( knobType _point, f_cnt_t _frames, bool _slide_to = false );
  203. void slideSampleByFrames( f_cnt_t _frames );
  204. void slideSamplePointToFrames( knobType _point, f_cnt_t _frames )
  205. {
  206. slideSamplePointByFrames( _point, _frames, true );
  207. }
  208. void updateGraph();
  209. void reverse();
  210. void updateCursor( QMouseEvent * _me = nullptr );
  211. static bool isCloseTo( int _a, int _b )
  212. {
  213. return qAbs( _a - _b ) < 4;
  214. }
  215. } ;
  216. #endif