aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/qmpmidioutfluid.cpp3
-rw-r--r--core/qmpmidioutfluid.hpp2
-rw-r--r--core/qmpmidioutrtmidi.cpp52
-rw-r--r--core/qmpmidioutrtmidi.hpp5
4 files changed, 58 insertions, 4 deletions
diff --git a/core/qmpmidioutfluid.cpp b/core/qmpmidioutfluid.cpp
index 414cb3a..ac6523f 100644
--- a/core/qmpmidioutfluid.cpp
+++ b/core/qmpmidioutfluid.cpp
@@ -123,7 +123,7 @@ std::vector<std::pair<uint16_t,std::string>> qmpMidiOutFluid::getBankList()
{
return bnk;
}
-std::vector<std::pair<uint8_t,std::string>> qmpMidiOutFluid::getPresets(int bank)
+std::vector<std::pair<uint8_t,std::string>> qmpMidiOutFluid::getPresets(uint16_t bank)
{
std::vector<std::pair<uint8_t,std::string>> ret;
if(pst.find(bank)==pst.end())return ret;
@@ -137,6 +137,7 @@ std::vector<std::pair<uint8_t,std::string>> qmpMidiOutFluid::getPresets(int bank
std::string qmpMidiOutFluid::getPresetName(uint16_t bank,uint8_t preset)
{
if(pst.find(bank)==pst.end())return "";
+ //should consult fluidsynth instead? (4 bank mapping methods)
return pst[bank][preset];
}
bool qmpMidiOutFluid::getChannelPreset(int ch,uint16_t *bank,uint8_t *preset,std::string &presetname)
diff --git a/core/qmpmidioutfluid.hpp b/core/qmpmidioutfluid.hpp
index 72197e7..d6a62c9 100644
--- a/core/qmpmidioutfluid.hpp
+++ b/core/qmpmidioutfluid.hpp
@@ -41,7 +41,7 @@ class qmpMidiOutFluid:public qmpMidiOutDevice,public IFluidSettings
void onMapped(uint8_t ch,int refcnt);
void onUnmapped(uint8_t ch,int refcnt);
std::vector<std::pair<uint16_t,std::string>> getBankList();
- std::vector<std::pair<uint8_t,std::string>> getPresets(int bank);
+ std::vector<std::pair<uint8_t,std::string>> getPresets(uint16_t bank);
std::string getPresetName(uint16_t bank,uint8_t preset);
bool getChannelPreset(int ch,uint16_t *bank,uint8_t *preset,std::string &presetname);
uint8_t getInitialCCValue(uint8_t cc);
diff --git a/core/qmpmidioutrtmidi.cpp b/core/qmpmidioutrtmidi.cpp
index 0ff2c86..2cc9d5b 100644
--- a/core/qmpmidioutrtmidi.cpp
+++ b/core/qmpmidioutrtmidi.cpp
@@ -1,6 +1,7 @@
#include <cctype>
#include <cstdio>
#include <cstring>
+#include <algorithm>
#include <deque>
#include <vector>
#include RT_MIDI_H
@@ -132,6 +133,27 @@ qmpDeviceInitializer* qmpDeviceInitializer::parse(const char* path)
}
}
}
+ else if(st_inmapping)
+ {
+ if(b.front()=='['&&b.back()==']')
+ {
+ b=b.substr(1,b.length()-2);
+ split(b,':',tok);
+ if(tok.size()<3)err("invalid bank")
+ cmsb=strtol(tok[0].c_str(),nullptr,10);
+ clsb=strtol(tok[1].c_str(),nullptr,10);
+ ret->banks[cmsb<<7|clsb]=BankStore{{},tok[2]};
+ }
+ else if(b.find('=')!=std::string::npos)
+ {
+ if(!~cmsb||!~clsb)err("inst outside a bank")
+ split(b,'=',tok);
+ if(tok.size()<2)err("invalid inst")
+ int p=strtol(tok[0].c_str(),nullptr,10);
+ ret->banks[cmsb<<7|clsb].presets[p]=tok[1];
+ }
+ else err("invalid mapping line")
+ }
}
#undef err
@@ -143,10 +165,12 @@ qmpMidiOutRtMidi::qmpMidiOutRtMidi(unsigned _portid)
{
portid=_portid;
outport=nullptr;
+ devinit=nullptr;
}
qmpMidiOutRtMidi::~qmpMidiOutRtMidi()
{
if(!outport)return;
+ if(devinit){delete devinit;devinit=nullptr;}
if(outport->isPortOpen())outport->closePort();
delete outport;outport=nullptr;
}
@@ -229,18 +253,44 @@ void qmpMidiOutRtMidi::onUnmapped(uint8_t ch,int refcnt)
}
std::vector<std::pair<uint16_t,std::string>> qmpMidiOutRtMidi::getBankList()
{
+ if(!devinit)return{};
+ std::vector<std::pair<uint16_t,std::string>> ret;
+ for(auto&i:devinit->banks)
+ ret.push_back({i.first,i.second.bankname});
+ std::sort(ret.begin(),ret.end(),[](std::pair<uint16_t,std::string>&a,std::pair<uint16_t,std::string>&b){return a.first<b.first;});
+ return ret;
}
-std::vector<std::pair<uint8_t,std::string>> qmpMidiOutRtMidi::getPresets(int bank)
+std::vector<std::pair<uint8_t,std::string>> qmpMidiOutRtMidi::getPresets(uint16_t bank)
{
+ if(!devinit)return{};
+ if(devinit->banks.find(bank)==devinit->banks.end())return{};
+ std::vector<std::pair<uint8_t,std::string>> ret;
+ for(auto&i:devinit->banks[bank].presets)
+ ret.push_back({i.first,i.second});
+ std::sort(ret.begin(),ret.end(),[](std::pair<uint8_t,std::string>&a,std::pair<uint8_t,std::string>&b){return a.first<b.first;});
+ return ret;
}
std::string qmpMidiOutRtMidi::getPresetName(uint16_t bank,uint8_t preset)
{
+ if(!devinit)return"";
+ if(devinit->banks.find(bank)!=devinit->banks.end())
+ if(devinit->banks[bank].presets.find(preset)!=devinit->banks[bank].presets.end())
+ return devinit->banks[bank].presets[preset];
+ return"";
}
bool qmpMidiOutRtMidi::getChannelPreset(int ch,uint16_t *bank,uint8_t *preset,std::string &presetname)
{
+ //This ain't a state-tracking device
+ return false;
}
uint8_t qmpMidiOutRtMidi::getInitialCCValue(uint8_t cc)
{
+ if(!devinit)return 0;//Nope!
+}
+void qmpMidiOutRtMidi::setInitializerFile(const char* path)
+{
+ if(devinit)delete devinit;
+ devinit=qmpDeviceInitializer::parse(path);
}
RtMidiOut* qmpRtMidiManager::dummy=nullptr;
diff --git a/core/qmpmidioutrtmidi.hpp b/core/qmpmidioutrtmidi.hpp
index 23adec6..0c1843c 100644
--- a/core/qmpmidioutrtmidi.hpp
+++ b/core/qmpmidioutrtmidi.hpp
@@ -23,6 +23,7 @@ class qmpMidiOutRtMidi:public qmpMidiOutDevice
private:
unsigned portid;
RtMidiOut* outport;
+ qmpDeviceInitializer* devinit;
public:
qmpMidiOutRtMidi(unsigned _portid);
~qmpMidiOutRtMidi();
@@ -37,10 +38,12 @@ public:
void onMapped(uint8_t ch,int refcnt);
void onUnmapped(uint8_t ch,int refcnt);
std::vector<std::pair<uint16_t,std::string>> getBankList();
- std::vector<std::pair<uint8_t,std::string>> getPresets(int bank);
+ std::vector<std::pair<uint8_t,std::string>> getPresets(uint16_t bank);
std::string getPresetName(uint16_t bank,uint8_t preset);
bool getChannelPreset(int ch,uint16_t *bank,uint8_t *preset,std::string &presetname);
uint8_t getInitialCCValue(uint8_t cc);
+
+ void setInitializerFile(const char* path);
};
class qmpRtMidiManager
{