juicysfplugin/Source/FluidSynthModel.h

85 lines
3.0 KiB
C
Raw Normal View History

2018-02-27 08:25:20 +08:00
//
// Created by Alex Birch on 10/09/2017.
//
#pragma once
2021-09-07 14:04:35 +08:00
#include <JuceHeader.h>
2018-02-27 08:25:20 +08:00
#include <fluidsynth.h>
#include <memory>
#include <map>
#include "MidiConstants.h"
2018-02-27 08:25:20 +08:00
using namespace std;
2018-02-27 08:25:20 +08:00
class FluidSynthModel
: public ValueTree::Listener
, public AudioProcessorValueTreeState::Listener {
2018-02-27 08:25:20 +08:00
public:
FluidSynthModel(
AudioProcessorValueTreeState& valueTreeState
);
~FluidSynthModel();
2018-02-27 08:25:20 +08:00
2018-04-10 08:20:23 +08:00
void initialise();
2018-02-27 08:25:20 +08:00
int getChannel();
void setControllerValue(int controller, int value);
2018-02-27 08:25:20 +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);
//==============================================================================
virtual void parameterChanged (const String& parameterID, float newValue) override;
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 {};
//==============================================================================
int getNumPrograms();
int getCurrentProgram();
void setCurrentProgram(int index);
const String getProgramName(int index);
void changeProgramName(int index, const String& newName);
private:
2019-07-31 04:12:49 +08:00
static const StringArray programChangeParams;
// there's no bimap in the standard library!
static const map<fluid_midi_control_change, String> controllerToParam;
static const map<String, fluid_midi_control_change> paramToController;
void refreshBanks();
AudioProcessorValueTreeState& valueTreeState;
// 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
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;
void unloadAndLoadFont(const String &absPath);
void loadFont(const String &absPath);
int sfont_id;
2018-02-27 08:25:20 +08:00
unsigned int channel;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FluidSynthModel)
};