LMMS
Loading...
Searching...
No Matches
OpulenZ.h
Go to the documentation of this file.
1/*
2 * OpulenZ.h - AdLib OPL2 FM synth based instrument
3 *
4 * Copyright (c) 2013 Raine M. Ekman <raine/at/iki/fi>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef OPULENZ_H
26#define OPULENZ_H
27
28
29#include "AutomatableModel.h"
30#include "Instrument.h"
31#include "InstrumentView.h"
32
33class Copl;
34
35
36namespace lmms
37{
38
39namespace gui
40{
41class Knob;
42class LcdSpinBox;
43class PixmapButton;
45}
46
47// This one is a flag, MIDI notes take 7 low bits
48#define OPL2_VOICE_FREE 128
49#define OPL2_NO_VOICE 255
50#define OPL2_VOICES 9
51
52// The "normal" range for LMMS pitchbends
53#define DEFAULT_BEND_CENTS 100
54
55class OpulenzInstrument;
56
77
79{
80 Q_OBJECT
81public:
83 ~OpulenzInstrument() override;
84
85 QString nodeName() const override;
86 gui::PluginView* instantiateView(QWidget* _parent) override;
87
88 bool handleMidiEvent(const MidiEvent& event, const TimePos& time, f_cnt_t offset = 0) override;
89 void play(SampleFrame* _working_buffer) override;
90
91 void saveSettings(QDomDocument& _doc, QDomElement& _this) override;
92 void loadSettings(const QDomElement& _this) override;
93
94 void loadDefaultPatch();
95 void loadPatch(const unsigned char inst[14]);
96
97 void tuneEqual(int center, float Hz);
98 void loadFile(const QString& file) override;
99
107
108private slots:
109 void updatePatch();
110 void reloadEmulator();
111 void loadGMPatch();
112
113private:
115 QString storedname;
119
121
122 // 0 - no note, >0 - note on velocity
123 int velocities[128];
124
125 // These include both octave and Fnumber
126 int fnums[128];
127
128 // in cents, range defaults to +/-100 cents (should this be changeable?)
131
132 int popVoice();
133 int pushVoice(int v);
134 int Hz2fnum(float Hz);
135
140 static QMutex s_emulatorMutex;
141
143 static constexpr auto OpAdd = std::array<unsigned int, OPL2_VOICES>{
144 0x00, 0x01, 0x02, 0x08, 0x09, 0x0A, 0x10, 0x11, 0x12
145 };
146
151 void writeVoice(int voice, int reg, int val);
152
154 void setVoiceVelocity(int voice, int vel);
155
156 // Pitch bend range comes through RPNs.
158};
159
160namespace gui
161{
162
183
185{
186 Q_OBJECT
187
188public:
189 OpulenzInstrumentView(Instrument* _instrument, QWidget* _parent);
190 ~OpulenzInstrumentView() override;
192 void modelChanged() override;
193
200
201private slots:
203 void updateKnobHints();
204
205private:
207 QString timeKnobHint(float n);
208};
209
210} // namespace gui
211
212} // namespace lmms
213
214#endif
#define OPL2_VOICES
Definition OpulenZ.h:50
Definition opl.h:26
Definition AutomatableModel.h:497
Definition AutomatableModel.h:463
Definition Instrument.h:52
Instrument(InstrumentTrack *_instrument_track, const Descriptor *_descriptor, const Descriptor::SubPluginFeatures::Key *key=nullptr, Flags flags=Flag::NoFlags)
Definition Instrument.cpp:38
Definition InstrumentTrack.h:62
Definition AutomatableModel.h:481
Definition MidiEvent.h:37
Definition OpulenZ.h:79
void loadFile(const QString &file) override
Load an SBI file into the knob models.
Definition OpulenZ.cpp:604
FloatModel m_feedbackModel
Definition OpulenZ.h:101
QString nodeName() const override
Definition OpulenZ.cpp:354
void updatePatch()
Update patch from the models to the chip emulation.
Definition OpulenZ.cpp:507
int pitchbend
Definition OpulenZ.h:129
void play(SampleFrame *_working_buffer) override
Definition OpulenZ.cpp:364
static QMutex s_emulatorMutex
Definition OpulenZ.h:140
void loadSettings(const QDomElement &_this) override
Definition OpulenZ.cpp:416
void saveSettings(QDomDocument &_doc, QDomElement &_this) override
Definition OpulenZ.cpp:380
int fnums[128]
Definition OpulenZ.h:126
BoolModel m_vibDepthModel
Definition OpulenZ.h:103
int RPNcoarse
Definition OpulenZ.h:157
bool handleMidiEvent(const MidiEvent &event, const TimePos &time, f_cnt_t offset=0) override
Definition OpulenZ.cpp:265
void reloadEmulator()
Samplerate changes when choosing oversampling, so this is more or less mandatory.
Definition OpulenZ.cpp:198
OpulenzOperatorModels m_op2
Definition OpulenZ.h:106
int RPNfine
Definition OpulenZ.h:157
int pitchBendRange
Definition OpulenZ.h:130
int pushVoice(int v)
Push voice into first free slot.
Definition OpulenZ.cpp:249
void loadGMPatch()
Load one of the default patches.
Definition OpulenZ.cpp:501
void writeVoice(int voice, int reg, int val)
Definition OpulenZ.cpp:214
~OpulenzInstrument() override
Definition OpulenZ.cpp:190
gui::PluginView * instantiateView(QWidget *_parent) override
Create a view for the model.
Definition OpulenZ.cpp:359
QString storedname
Definition OpulenZ.h:115
void loadPatch(const unsigned char inst[14])
Load a patch into the emulator.
Definition OpulenZ.cpp:459
void setVoiceVelocity(int voice, int vel)
Can only be called by code protected by the holy mutex!
Definition OpulenZ.cpp:219
int Hz2fnum(float Hz)
Find suitable F number in lowest possible block.
Definition OpulenZ.cpp:491
int voiceNote[OPL2_VOICES]
Definition OpulenZ.h:118
BoolModel m_fmModel
Definition OpulenZ.h:102
int popVoice()
Pop least recently used voice.
Definition OpulenZ.cpp:234
Copl * theEmulator
Definition OpulenZ.h:114
short * renderbuffer
Definition OpulenZ.h:117
IntModel m_patchModel
Definition OpulenZ.h:100
BoolModel m_tremDepthModel
Definition OpulenZ.h:104
void tuneEqual(int center, float Hz)
Definition OpulenZ.cpp:482
static constexpr auto OpAdd
(Weird) offsets for voice parameters
Definition OpulenZ.h:143
f_cnt_t frameCount
Definition OpulenZ.h:116
OpulenzOperatorModels m_op1
Definition OpulenZ.h:105
OpulenzInstrument(InstrumentTrack *insTrack)
Definition OpulenZ.cpp:105
int velocities[128]
Definition OpulenZ.h:123
void loadDefaultPatch()
Load default patch.
Definition OpulenZ.cpp:570
int voiceLRU[OPL2_VOICES]
Least recently used voices.
Definition OpulenZ.h:120
Definition SampleFrame.h:41
Definition TimePos.h:68
Definition AutomatableButton.h:84
Instrument view with fixed LMMS-default size.
Definition InstrumentView.h:66
Definition Knob.h:47
Definition LcdSpinBox.h:35
LcdSpinBox * m_patch
Definition OpulenZ.h:191
~OpulenzInstrumentView() override
Definition OpulenZ.cpp:777
PixmapButton * vibDepthButton
Definition OpulenZ.h:198
OpulenzOperatorControls op2View
Definition OpulenZ.h:195
Knob * feedbackKnob
Definition OpulenZ.h:196
QString timeKnobHint(float n)
Formats time nicely for knob hints.
Definition OpulenZ.cpp:782
PixmapButton * tremDepthButton
Definition OpulenZ.h:199
OpulenzInstrumentView(Instrument *_instrument, QWidget *_parent)
Definition OpulenZ.cpp:700
OpulenzOperatorControls op1View
Definition OpulenZ.h:194
void updateKnobHints()
Update hints to have user-friendly formatting and units.
Definition OpulenZ.cpp:789
PixmapButton * fmButton
Definition OpulenZ.h:197
void modelChanged() override
Definition OpulenZ.cpp:835
Definition PixmapButton.h:37
Definition PluginView.h:36
unsigned v[N_MAX]
Definition inflate.c:1584
int val
Definition jpeglib.h:956
Definition AudioPortAudio.cpp:209
Definition AudioAlsa.cpp:35
Instrument * ins
Definition HydrogenImport.cpp:138
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
Stores parameters unique to both operators, to avoid duplication.
Definition OpulenZ.h:59
FloatModel release
Definition OpulenZ.h:67
BoolModel ksr
Key-Scale Rate.
Definition OpulenZ.h:71
OpulenzOperatorModels(OpulenzInstrument *ins, int num)
num is the number of the operator (1 or 2 on an OPL2)
Definition OpulenZ.cpp:89
BoolModel vib
Vibrato.
Definition OpulenZ.h:74
FloatModel mul
Frequency multiplier.
Definition OpulenZ.h:70
FloatModel attack
Definition OpulenZ.h:64
IntModel waveform
Definition OpulenZ.h:75
FloatModel decay
Definition OpulenZ.h:65
FloatModel scale
Definition OpulenZ.h:69
FloatModel sustain
Definition OpulenZ.h:66
BoolModel perc
Percussive envelope mode.
Definition OpulenZ.h:72
BoolModel trem
Tremolo.
Definition OpulenZ.h:73
FloatModel level
Definition OpulenZ.h:68
Aggregates controls for models available in OpulenzOperatorModels. All pointers are non-owning.
Definition OpulenZ.h:165
Knob * level
Definition OpulenZ.h:170
AutomatableButtonGroup * waveform
Definition OpulenZ.h:177
PixmapButton * vib
Definition OpulenZ.h:176
Knob * attack
Definition OpulenZ.h:166
Knob * decay
Definition OpulenZ.h:167
PixmapButton * perc
Definition OpulenZ.h:174
Knob * release
Definition OpulenZ.h:169
Knob * sustain
Definition OpulenZ.h:168
PixmapButton * trem
Definition OpulenZ.h:175
Knob * scale
Definition OpulenZ.h:171
PixmapButton * w3
Definition OpulenZ.h:181
Knob * mul
Definition OpulenZ.h:172
PixmapButton * w1
Definition OpulenZ.h:179
PixmapButton * w0
Definition OpulenZ.h:178
PixmapButton * ksr
Definition OpulenZ.h:173
PixmapButton * w2
Definition OpulenZ.h:180
int n
Definition crypt.c:458
struct zdirent * file
Definition win32.c:1500