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