2018-02-27 08:25:20 +08:00
|
|
|
//
|
|
|
|
// Created by Alex Birch on 10/09/2017.
|
|
|
|
//
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../JuceLibraryCode/JuceHeader.h"
|
2018-04-10 08:17:50 +08:00
|
|
|
#include "SharesParams.h"
|
2018-02-27 08:25:20 +08:00
|
|
|
#include <fluidsynth.h>
|
|
|
|
#include <memory>
|
2018-04-13 08:14:07 +08:00
|
|
|
#include "BankAndPreset.h"
|
2018-02-27 08:25:20 +08:00
|
|
|
#include "PresetsToBanks.h"
|
|
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/13446565/5257399
|
2018-04-13 08:14:07 +08:00
|
|
|
//using std::shared_ptr;
|
|
|
|
|
|
|
|
using namespace std;
|
2018-02-27 08:25:20 +08:00
|
|
|
|
|
|
|
class FluidSynthModel {
|
|
|
|
public:
|
2018-04-10 08:20:23 +08:00
|
|
|
FluidSynthModel(SharesParams& p);
|
2018-02-27 08:25:20 +08:00
|
|
|
~FluidSynthModel();
|
|
|
|
|
|
|
|
fluid_synth_t* getSynth();
|
2018-04-10 08:20:23 +08:00
|
|
|
void initialise();
|
2018-02-27 08:25:20 +08:00
|
|
|
|
|
|
|
BanksToPresets getBanks();
|
|
|
|
|
|
|
|
void changePreset(int bank, int preset);
|
|
|
|
int getChannel();
|
|
|
|
|
2018-04-13 08:14:07 +08:00
|
|
|
void onFileNameChanged(const String &absPath, int bank, int preset);
|
2018-02-27 08:25:20 +08:00
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
/**
|
|
|
|
Used to receive callbacks when a button is clicked.
|
|
|
|
|
|
|
|
@see Button::addListener, Button::removeListener
|
|
|
|
*/
|
|
|
|
class Listener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Destructor. */
|
|
|
|
virtual ~Listener();
|
|
|
|
|
|
|
|
/** Called when the button is clicked. */
|
2018-04-11 06:29:32 +08:00
|
|
|
virtual void fontChanged (FluidSynthModel*, const String &absPath);
|
2018-02-27 08:25:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Registers a listener to receive events when this button's state changes.
|
|
|
|
If the listener is already registered, this will not register it again.
|
|
|
|
@see removeListener
|
|
|
|
*/
|
|
|
|
void addListener (Listener* newListener);
|
|
|
|
|
|
|
|
/** Removes a previously-registered button listener
|
|
|
|
@see addListener
|
|
|
|
*/
|
|
|
|
void removeListener (Listener* listener);
|
|
|
|
|
2018-04-16 04:32:26 +08:00
|
|
|
void setSampleRate(float sampleRate);
|
|
|
|
|
2018-04-11 07:08:15 +08:00
|
|
|
const String& getCurrentSoundFontAbsPath();
|
|
|
|
|
2018-02-27 08:25:20 +08:00
|
|
|
private:
|
2018-04-10 08:20:23 +08:00
|
|
|
SharesParams& sharesParams;
|
2018-04-10 07:51:21 +08:00
|
|
|
|
2018-02-27 08:25:20 +08:00
|
|
|
fluid_synth_t* synth;
|
|
|
|
fluid_settings_t* settings;
|
|
|
|
// fluid_audio_driver_t* driver;
|
|
|
|
|
2018-04-11 06:29:32 +08:00
|
|
|
String currentSoundFontAbsPath;
|
|
|
|
|
2018-04-16 04:32:26 +08:00
|
|
|
float currentSampleRate;
|
|
|
|
|
2018-06-18 00:53:32 +08:00
|
|
|
fluid_preset_t* getFirstPreset();
|
2018-02-27 08:25:20 +08:00
|
|
|
void selectFirstPreset();
|
2018-04-13 08:14:07 +08:00
|
|
|
unique_ptr<BankAndPreset> getFirstBankAndPreset();
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2018-04-11 06:29:32 +08:00
|
|
|
void unloadAndLoadFont(const String &absPath);
|
|
|
|
void loadFont(const String &absPath);
|
|
|
|
bool shouldLoadFont(const String &absPath);
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2018-04-13 07:40:27 +08:00
|
|
|
void changePresetImpl(int bank, int preset);
|
|
|
|
|
2018-02-27 08:25:20 +08:00
|
|
|
bool initialised;
|
|
|
|
unsigned int sfont_id;
|
|
|
|
unsigned int channel;
|
|
|
|
|
2019-06-24 02:40:36 +08:00
|
|
|
// fluid_mod_t* mod;
|
2018-06-23 04:32:16 +08:00
|
|
|
|
2018-02-27 08:25:20 +08:00
|
|
|
ListenerList<Listener> eventListeners;
|
|
|
|
|
|
|
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FluidSynthModel)
|
2018-06-18 00:53:32 +08:00
|
|
|
};
|