MuseScore  3.4
Music composition and notation
msynthesizer.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2012 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __MSYNTHESIZER_H__
14 #define __MSYNTHESIZER_H__
15 
16 #include <atomic>
17 #include "effects/effect.h"
19 
20 namespace Ms {
21 
22 struct MidiPatch;
23 class NPlayEvent;
24 class Synthesizer;
25 class Effect;
26 class Xml;
27 
28 //---------------------------------------------------------
29 // MasterSynthesizer
30 // hosts several synthesizers
31 //---------------------------------------------------------
32 
33 class MasterSynthesizer : public QObject {
34  Q_OBJECT
35 
36  float _gain { defaultGain };
37  float _boost { 10.0 }; // +20dB
38  double _masterTuning { 440.0 };
39 
40  int _dynamicsMethod { 1 }; // Default dynamics method
41  int _ccToUse { 1 }; // CC2
42 
43  static constexpr double MUTE = 0.00; // for gain to decibels conversion
44  static constexpr double MAX = 10.00; // for gain to decibels conversion
45  static constexpr double N = 20.0; // for gain to decibels conversion
46 
47  public:
48  static const int MAX_BUFFERSIZE = 8192;
49  static const int MAX_EFFECTS = 2;
50  static constexpr float defaultGain = 0.1f; // -20dB
51 
52  private:
53  std::atomic<bool> lock1 { false };
54  std::atomic<bool> lock2 { true };
55  std::vector<Synthesizer*> _synthesizer;
56  std::vector<Effect*> _effectList[MAX_EFFECTS];
57  Effect* _effect[MAX_EFFECTS] { nullptr, nullptr };
58 
59  float _sampleRate;
60 
63  int indexOfEffect(int ab, const QString& name);
64  float convertGainToDecibels(float gain) const;
65 
66  public slots:
67  void sfChanged() { emit soundFontChanged(); }
68  void setGain(float f);
69 
70  signals:
71  void soundFontChanged();
72  void gainChanged(float);
73 
74  public:
78 
79  void init();
80 
81  float sampleRate() { return _sampleRate; }
82  void setSampleRate(float val);
83 
84  void process(unsigned, float*);
85  void play(const NPlayEvent&, unsigned);
86 
87  void setMasterTuning(double val);
88  double masterTuning() const { return _masterTuning; }
89 
90  int index(const QString&) const;
91  QString name(unsigned) const;
92 
93  QList<MidiPatch*> getPatchInfo() const;
94  MidiPatch* getPatchInfo(QString synti, int bank, int program);
95 
96  SynthesizerState state() const;
97  bool setState(const SynthesizerState&);
98 
99  Synthesizer* synthesizer(const QString& name);
100  const std::vector<Effect*>& effectList(int ab) const { return _effectList[ab]; }
101  const std::vector<Synthesizer*> synthesizer() const { return _synthesizer; }
102  void registerEffect(int ab, Effect*);
103 
104  void reset();
105  void allSoundsOff(int channel);
106  void allNotesOff(int channel);
107 
108  void setEffect(int ab, int idx);
109  Effect* effect(int ab);
110  int indexOfEffect(int ab);
111 
112  float gain() const { return _gain; }
113  float gainAsDecibels() const;
115  float minGainAsDecibels = -80;
116  float maxGainAsDecibels = 0;
117 
118  void setGainAsDecibels(float decibelValue);
119  float boost() const { return _boost; }
120  void setBoost(float v) { _boost = v; }
121 
122  int dynamicsMethod() const { return _dynamicsMethod; }
123  void setDynamicsMethod(int val) { _dynamicsMethod = val; }
124  int ccToUseIndex() const { return _ccToUse; } // NOTE: this doesn't return a CC number, but returns an index instead
125  void setCcToUseIndex(int val) { _ccToUse = val; }
126 
127  bool storeState();
128  };
129 
130 }
131 #endif
132 
int index(const QString &) const
Definition: msynthesizer.cpp:103
float effect1Buffer[MAX_BUFFERSIZE]
Definition: msynthesizer.h:61
Definition: effect.h:41
static constexpr double MAX
Definition: msynthesizer.h:44
~MasterSynthesizer()
Definition: msynthesizer.cpp:66
int indexOfEffect(int ab, const QString &name)
Definition: msynthesizer.cpp:299
float boost() const
Definition: msynthesizer.h:119
Definition: midipatch.h:29
float effect2Buffer[MAX_BUFFERSIZE]
Definition: msynthesizer.h:62
QString name(unsigned) const
Definition: msynthesizer.cpp:119
int dynamicsMethod() const
Definition: msynthesizer.h:122
int _dynamicsMethod
Definition: msynthesizer.h:40
Definition: synthesizer.h:41
void gainChanged(float)
static const int MAX_BUFFERSIZE
Definition: msynthesizer.h:48
MasterSynthesizer()
Definition: msynthesizer.cpp:29
void setEffect(int ab, int idx)
Definition: msynthesizer.cpp:211
Effect * _effect[MAX_EFFECTS]
Definition: msynthesizer.h:57
void setGainAsDecibels(float decibelValue)
Definition: msynthesizer.cpp:435
float maxGainAsDecibels
Definition: msynthesizer.h:116
std::atomic< bool > lock1
Definition: msynthesizer.h:53
float gainAsDecibels() const
Definition: msynthesizer.cpp:458
void sfChanged()
Definition: msynthesizer.h:67
float sampleRate()
Definition: msynthesizer.h:81
float _boost
Definition: msynthesizer.h:37
bool setState(const SynthesizerState &)
Definition: msynthesizer.cpp:322
void setMasterTuning(double val)
Definition: msynthesizer.cpp:467
Definition: synthesizerstate.h:55
float _gain
Definition: msynthesizer.h:36
void setCcToUseIndex(int val)
Definition: msynthesizer.h:125
void setSampleRate(float val)
Definition: msynthesizer.cpp:241
std::vector< Synthesizer * > _synthesizer
Definition: msynthesizer.h:55
int ccToUseIndex() const
Definition: msynthesizer.h:124
float minGainAsDecibels
Definition: msynthesizer.h:115
void setGain(float f)
Definition: msynthesizer.cpp:422
void registerSynthesizer(Synthesizer *)
Definition: msynthesizer.cpp:193
bool storeState()
Definition: msynthesizer.cpp:402
float convertGainToDecibels(float gain) const
Definition: msynthesizer.cpp:447
MasterSynthesizer * synti
Definition: musescore.cpp:172
void process(unsigned, float *)
Definition: msynthesizer.cpp:260
void registerEffect(int ab, Effect *)
Definition: msynthesizer.cpp:202
SynthesizerState state() const
Definition: msynthesizer.cpp:377
const std::vector< Effect * > & effectList(int ab) const
Definition: msynthesizer.h:100
Definition: aeolus.cpp:26
void setBoost(float v)
Definition: msynthesizer.h:120
void allSoundsOff(int channel)
Definition: msynthesizer.cpp:159
Effect * effect(int ab)
Definition: msynthesizer.cpp:232
QList< MidiPatch * > getPatchInfo() const
Definition: msynthesizer.cpp:132
static constexpr float defaultGain
Definition: msynthesizer.h:50
void reset()
Definition: msynthesizer.cpp:81
static constexpr double MUTE
Definition: msynthesizer.h:43
Definition: event.h:238
float gain() const
Definition: msynthesizer.h:112
double masterTuning() const
Definition: msynthesizer.h:88
static const int MAX_EFFECTS
Definition: msynthesizer.h:49
double _masterTuning
Definition: msynthesizer.h:38
std::atomic< bool > lock2
Definition: msynthesizer.h:54
std::vector< Effect * > _effectList[MAX_EFFECTS]
Definition: msynthesizer.h:56
void init()
Definition: msynthesizer.cpp:39
Definition: msynthesizer.h:33
static constexpr double N
Definition: msynthesizer.h:45
int _ccToUse
Definition: msynthesizer.h:41
float defaultGainAsDecibels
Definition: msynthesizer.h:114
const std::vector< Synthesizer * > synthesizer() const
Definition: msynthesizer.h:101
float _sampleRate
Definition: msynthesizer.h:59
void allNotesOff(int channel)
Definition: msynthesizer.cpp:169
void setDynamicsMethod(int val)
Definition: msynthesizer.h:123
void play(const NPlayEvent &, unsigned)
Definition: msynthesizer.cpp:91