Skip to content

Commit

Permalink
add MMC support in mididispatch module
Browse files Browse the repository at this point in the history
  • Loading branch information
gisogrimm committed Oct 14, 2024
1 parent fc5e939 commit ecde75e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 11 deletions.
1 change: 1 addition & 0 deletions libtascar/include/alsamidicc.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ namespace TASCAR {
*/
virtual void emit_event(int channel, int param, int value) = 0;
virtual void emit_event_note(int, int, int){};
virtual void emit_event_mmc(uint8_t, uint8_t){};

private:
// MIDI sequencer:
Expand Down
37 changes: 26 additions & 11 deletions libtascar/src/alsamidicc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,32 @@ void TASCAR::midi_ctl_t::service()
while(run_service) {
// while( snd_seq_event_input_pending(seq,0) ){
while(snd_seq_event_input(seq, &ev) >= 0) {
if(ev && (ev->type == SND_SEQ_EVENT_CONTROLLER)) {
emit_event(ev->data.control.channel, ev->data.control.param,
ev->data.control.value);
}
if(ev && ((ev->type == SND_SEQ_EVENT_NOTE) ||
(ev->type == SND_SEQ_EVENT_NOTEON) ||
(ev->type == SND_SEQ_EVENT_NOTEOFF))) {
emit_event_note(ev->data.note.channel, ev->data.note.note,
((ev->type == SND_SEQ_EVENT_NOTEOFF)
? 0
: (ev->data.note.velocity)));
if(ev) {
switch(ev->type) {
case SND_SEQ_EVENT_CONTROLLER:
// if(ev && (ev->type == SND_SEQ_EVENT_CONTROLLER)) {
emit_event(ev->data.control.channel, ev->data.control.param,
ev->data.control.value);
break;
//}
case SND_SEQ_EVENT_NOTE:
case SND_SEQ_EVENT_NOTEON:
case SND_SEQ_EVENT_NOTEOFF:
// if(ev && ((ev->type == SND_SEQ_EVENT_NOTE) ||
// (ev->type == SND_SEQ_EVENT_NOTEON) ||
// (ev->type == SND_SEQ_EVENT_NOTEOFF))) {
emit_event_note(ev->data.note.channel, ev->data.note.note,
((ev->type == SND_SEQ_EVENT_NOTEOFF)
? 0
: (ev->data.note.velocity)));
break;
case SND_SEQ_EVENT_SYSEX:
uint8_t* buf((uint8_t*)(ev->data.ext.ptr));
if((ev->data.ext.len == 6) && (buf[0] == 0xf0) && (buf[1] == 0x7f) &&
(buf[3] == 0x06) && (buf[5] == 0xf7))
emit_event_mmc(buf[2], buf[4]);
break;
}
}
}
usleep(10);
Expand Down
52 changes: 52 additions & 0 deletions plugins/src/tascarmod_mididispatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ class mididispatch_t : public mididispatch_vars_t, public TASCAR::midi_ctl_t {
void add_variables(TASCAR::osc_server_t* srv);
virtual void emit_event(int channel, int param, int value);
virtual void emit_event_note(int channel, int pitch, int velocity);
virtual void emit_event_mmc(uint8_t deviceid, uint8_t cmd);
void validate_attributes(std::string& msg) const;
void send_midi_(int channel, int param, int value)
{
send_midi(channel, param, value);
Expand Down Expand Up @@ -385,12 +387,30 @@ class mididispatch_t : public mididispatch_vars_t, public TASCAR::midi_ctl_t {
private:
std::vector<std::pair<uint16_t, m_msg_t>> ccmsg;
std::vector<std::pair<uint16_t, m_msg_t>> notemsg;
std::vector<std::pair<uint16_t, m_msg_t>> mmcmsg;
std::mutex mtxdispatch;
lo_address copytarget = NULL;
std::map<uint8_t, lpaction_t> lpactmap;
std::mutex mtxlpactmap;
};

void mididispatch_t::validate_attributes(std::string& msg) const
{
TASCAR::xml_element_t::validate_attributes(msg);
for(auto sne : tsccfg::node_get_children(e, "ccmsg")) {
TASCAR::xml_element_t xml(sne);
xml.validate_attributes(msg);
}
for(auto sne : tsccfg::node_get_children(e, "notemsg")) {
TASCAR::xml_element_t xml(sne);
xml.validate_attributes(msg);
}
for(auto sne : tsccfg::node_get_children(e, "mmcmsg")) {
TASCAR::xml_element_t xml(sne);
xml.validate_attributes(msg);
}
}

mididispatch_t::mididispatch_t(const TASCAR::module_cfg_t& cfg)
: mididispatch_vars_t(cfg), TASCAR::midi_ctl_t(name)
{
Expand All @@ -416,6 +436,17 @@ mididispatch_t::mididispatch_t(const TASCAR::module_cfg_t& cfg)
notemsg.push_back(
std::pair<uint16_t, m_msg_t>(256 * channel + note, action));
}
for(auto sne : tsccfg::node_get_children(e, "mmcmsg")) {
m_msg_t action;
TASCAR::xml_element_t xml(sne);
action.parse(xml);
uint32_t deviceid = 127;
uint32_t command = 1;
xml.GET_ATTRIBUTE(deviceid, "", "MMC device ID");
xml.GET_ATTRIBUTE(command, "", "MMC command");
mmcmsg.push_back(
std::pair<uint16_t, m_msg_t>(256 * deviceid + command, action));
}
if(!connect.empty()) {
connect_input(connect, true);
connect_output(connect, true);
Expand Down Expand Up @@ -700,6 +731,27 @@ void mididispatch_t::emit_event_note(int channel, int pitch, int velocity)
}
}

void mididispatch_t::emit_event_mmc(uint8_t deviceid, uint8_t cmd)
{
// uint16_t ctl(channel + param);
bool known = false;
for(auto& m : mmcmsg) {
bool same_device = ((m.first >> 8) == deviceid);
bool any_device = (((m.first >> 8) == 127) || (deviceid == 127));
if((same_device || any_device) && ((m.first & 0xff) == cmd)) {
std::lock_guard<std::mutex> lock(mtxdispatch);
m.second.updatemsg(session, 0);
known = true;
}
}
if((!known) && dumpmsg) {
char ctmp[256];
snprintf(ctmp, 256, "MMC device-ID %0x command %0x", deviceid, cmd);
ctmp[255] = 0;
std::cout << ctmp << std::endl;
}
}

REGISTER_MODULE(mididispatch_t);

/*
Expand Down

0 comments on commit ecde75e

Please sign in to comment.