2018-02-27 08:25:20 +08:00
|
|
|
//
|
|
|
|
// Created by Alex Birch on 10/09/2017.
|
|
|
|
//
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../JuceLibraryCode/JuceHeader.h"
|
|
|
|
#include <fluidsynth.h>
|
|
|
|
#include <memory>
|
|
|
|
|
2018-04-13 08:14:07 +08:00
|
|
|
using namespace std;
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-16 04:28:35 +08:00
|
|
|
class FluidSynthModel
|
|
|
|
: public ValueTree::Listener
|
|
|
|
, public AudioProcessorValueTreeState::Listener {
|
2018-02-27 08:25:20 +08:00
|
|
|
public:
|
2019-07-07 07:22:47 +08:00
|
|
|
FluidSynthModel(
|
2019-07-11 06:13:58 +08:00
|
|
|
AudioProcessorValueTreeState& valueTreeState
|
2019-07-07 07:22:47 +08:00
|
|
|
);
|
2019-07-08 00:35:31 +08:00
|
|
|
~FluidSynthModel();
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2018-04-10 08:20:23 +08:00
|
|
|
void initialise();
|
2019-07-29 05:51:51 +08:00
|
|
|
|
2018-02-27 08:25:20 +08:00
|
|
|
int getChannel();
|
|
|
|
|
2019-07-01 04:40:24 +08:00
|
|
|
void setControllerValue(int controller, int value);
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-29 05:22:25 +08:00
|
|
|
void processBlock(AudioBuffer<float>& buffer, MidiBuffer& midiMessages);
|
|
|
|
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2018-04-16 04:32:26 +08:00
|
|
|
void setSampleRate(float sampleRate);
|
2019-07-08 00:35:31 +08:00
|
|
|
|
2019-07-29 05:51:51 +08:00
|
|
|
//==============================================================================
|
2019-07-16 04:28:35 +08:00
|
|
|
virtual void parameterChanged (const String& parameterID, float newValue) override;
|
2019-07-08 00:35:31 +08:00
|
|
|
|
|
|
|
virtual void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged,
|
|
|
|
const Identifier& property) override;
|
|
|
|
inline virtual void valueTreeChildAdded (ValueTree& parentTree,
|
|
|
|
ValueTree& childWhichHasBeenAdded) override {};
|
|
|
|
inline virtual void valueTreeChildRemoved (ValueTree& parentTree,
|
|
|
|
ValueTree& childWhichHasBeenRemoved,
|
|
|
|
int indexFromWhichChildWasRemoved) override {};
|
|
|
|
inline virtual void valueTreeChildOrderChanged (ValueTree& parentTreeWhoseChildrenHaveMoved,
|
|
|
|
int oldIndex, int newIndex) override {};
|
|
|
|
inline virtual void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged) override {};
|
|
|
|
inline virtual void valueTreeRedirected (ValueTree& treeWhichHasBeenChanged) override {};
|
2018-04-11 07:08:15 +08:00
|
|
|
|
2019-07-29 05:51:51 +08:00
|
|
|
//==============================================================================
|
|
|
|
int getNumPrograms();
|
|
|
|
int getCurrentProgram();
|
|
|
|
void setCurrentProgram(int index);
|
|
|
|
const String getProgramName(int index);
|
|
|
|
void changeProgramName(int index, const String& newName);
|
2019-07-08 00:35:31 +08:00
|
|
|
|
2019-07-29 05:51:51 +08:00
|
|
|
private:
|
2019-07-16 04:28:35 +08:00
|
|
|
void refreshBanks();
|
2018-04-10 07:51:21 +08:00
|
|
|
|
2019-07-07 07:22:47 +08:00
|
|
|
AudioProcessorValueTreeState& valueTreeState;
|
|
|
|
|
2019-07-08 00:35:31 +08:00
|
|
|
// https://stackoverflow.com/questions/38980315/is-stdunique-ptr-deletion-order-guaranteed
|
|
|
|
// members are destroyed in reverse of the order they're declared
|
|
|
|
// http://www.fluidsynth.org/api/
|
|
|
|
// in their examples, they destroy the synth before destroying the settings
|
2019-07-07 07:22:47 +08:00
|
|
|
unique_ptr<fluid_settings_t, decltype(&delete_fluid_settings)> settings;
|
2019-07-29 06:02:22 +08:00
|
|
|
unique_ptr<fluid_synth_t, decltype(&delete_fluid_synth)> synth;
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2018-04-16 04:32:26 +08:00
|
|
|
float currentSampleRate;
|
|
|
|
|
2018-04-11 06:29:32 +08:00
|
|
|
void unloadAndLoadFont(const String &absPath);
|
|
|
|
void loadFont(const String &absPath);
|
2019-07-29 05:51:51 +08:00
|
|
|
|
2019-07-28 06:04:20 +08:00
|
|
|
int sfont_id;
|
2018-02-27 08:25:20 +08:00
|
|
|
unsigned int channel;
|
|
|
|
|
|
|
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FluidSynthModel)
|
2018-06-18 00:53:32 +08:00
|
|
|
};
|