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 __SYNTHESIZER_H__
14 #define __SYNTHESIZER_H__
15 
16 #include "libmscore/synthesizerstate.h"
17 
18 namespace Ms {
19 
20 struct MidiPatch;
21 class PlayEvent;
22 class Synth;
23 class SynthesizerGui;
24 
25 //---------------------------------------------------------
26 //   SoundFontInfo
27 //---------------------------------------------------------
28 
29 struct SoundFontInfo {
30       QString fileName;
31       QString fontName;
32 
SoundFontInfoSoundFontInfo33       SoundFontInfo(QString _fileName) : fileName(_fileName), fontName(_fileName) {}
SoundFontInfoSoundFontInfo34       SoundFontInfo(QString _fileName, QString _fontName) : fileName(_fileName), fontName(_fontName) {}
35       };
36 
37 //---------------------------------------------------------
38 //   Synthesizer
39 //---------------------------------------------------------
40 
41 class Synthesizer {
42       bool _active;
43 
44    protected:
45       float _sampleRate { 44100.0f };
46       SynthesizerGui* _gui { nullptr };
47 
48    public:
Synthesizer()49       Synthesizer() : _active(false) { _gui = 0; }
~Synthesizer()50       virtual ~Synthesizer() {}
init(float sr)51       virtual void init(float sr)    { _sampleRate = sr; }
sampleRate()52       float sampleRate() const       { return _sampleRate; }
53 
54       virtual const char* name() const = 0;
55 
setMasterTuning(double)56       virtual void setMasterTuning(double) {}
masterTuning()57       virtual double masterTuning() const { return 440.0; }
58 
59       virtual bool loadSoundFonts(const QStringList&) = 0;
addSoundFont(const QString &)60       virtual bool addSoundFont(const QString&)    { return false; }
removeSoundFont(const QString &)61       virtual bool removeSoundFont(const QString&) { return false; }
62 
63       virtual std::vector<SoundFontInfo> soundFontsInfo() const = 0;
64 
65       virtual void process(unsigned, float*, float*, float*) = 0;
66       virtual void play(const PlayEvent&) = 0;
67 
68       virtual const QList<MidiPatch*>& getPatchInfo() const = 0;
69 
70       // get/set synthesizer state
71       virtual SynthesizerGroup state() const = 0;
72       virtual bool setState(const SynthesizerGroup&) = 0;
setValue(int,double)73       virtual void setValue(int, double) {}
value(int)74       virtual double value(int) const { return 0.0; }
75 
reset()76       void reset()                    { _active = false; }
active()77       bool active() const             { return _active; }
78       void setActive(bool val = true) { _active = val;  }
79 
allSoundsOff(int)80       virtual void allSoundsOff(int /*channel*/) {}
allNotesOff(int)81       virtual void allNotesOff(int /*channel*/) {}
82 
gui()83       virtual SynthesizerGui* gui()  { return _gui; }
84       };
85 
86 }
87 #endif
88 
89