-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.h
122 lines (115 loc) · 2.1 KB
/
sample.h
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
#ifndef SAMPLE_H
#define SAMPLE_H
#include <QObject>
#include <QTimer>
#include <QMetaType>
#include <fmod.hpp>
#include "keyboardkey.h"
struct SampleInfo;
class Sample : public QObject
{
Q_OBJECT
private:
void init();
public:
enum LoopType
{
NoLoop,
SimpleLoop,
AutoLoop
};
Sample(const QString & name, const QString & file, LoopType looping, KeyboardKey kbdKey, FMOD::System * fmodSystem, int numChannel);
Sample(const SampleInfo & info, FMOD::System * fmodSystem, int numChannel);
~Sample()
{
stop();
if (sound)
sound->release();
}
QString name() const
{
return sampleName;
}
QString fileName() const
{
return sampleFileName;
}
KeyboardKey key() const
{
return keyboardKey;
}
unsigned int length() const // in ms
{
unsigned int l;
sound->getLength(&l, FMOD_TIMEUNIT_MS);
return l;
}
LoopType loopType() const
{
return loop;
}
bool isPlaying() const
{
return playing;
}
int getVolume() const
{
return volume;
}
int getPan() const
{
return panning;
}
SampleInfo info() const;
protected:
bool resOk(FMOD_RESULT res);
void reload();
signals:
void started();
void stopped();
void changed();
public slots:
void start();
void stop();
void setMute(bool mute);
// props
void setVolume(int volume);
void setPanning(int pan);
void setLoopType(LoopType loop);
void setKey(KeyboardKey newKey);
void setName(const QString & newName);
void setFileName(const QString & newFile);
protected slots:
void onFadeOutTimer();
private:
QString sampleName;
QString sampleFileName;
bool playing;
LoopType loop;
QTimer fadeOutTimer;
KeyboardKey keyboardKey;
int volume;
int panning;
int oldVolume;
bool needReloading;
bool muted;
// FMOD
FMOD::System * system;
FMOD::Sound * sound;
FMOD::Channel * channel;
int channelNumber;
};
struct SampleInfo
{
SampleInfo()
: key(Qt::Key_Space)
{}
QString name;
QString file;
Sample::LoopType loopType;
KeyboardKey key;
int volume;
int panning;
};
Q_DECLARE_METATYPE(SampleInfo)
#endif // SAMPLE_H