Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add MIDI Button actions and dec/inc trigger modes #767

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,32 @@ void CConfig::Load (void)

m_nMIDIButtonCh = m_Properties.GetNumber ("MIDIButtonCh", 0);
m_nMIDIButtonNotes = m_Properties.GetNumber ("MIDIButtonNotes", 0);

m_nMIDIButtonPrev = m_Properties.GetNumber ("MIDIButtonPrev", 0);
m_nMIDIButtonNext = m_Properties.GetNumber ("MIDIButtonNext", 0);
m_nMIDIButtonBack = m_Properties.GetNumber ("MIDIButtonBack", 0);
m_nMIDIButtonSelect = m_Properties.GetNumber ("MIDIButtonSelect", 0);
m_nMIDIButtonHome = m_Properties.GetNumber ("MIDIButtonHome", 0);

m_MIDIButtonActionPrev = m_Properties.GetString ("MIDIButtonActionPrev", "");
m_MIDIButtonActionNext = m_Properties.GetString ("MIDIButtonActionNext", "");
m_MIDIButtonActionBack = m_Properties.GetString ("MIDIButtonActionBack", "");
m_MIDIButtonActionSelect = m_Properties.GetString ("MIDIButtonActionSelect", "");
m_MIDIButtonActionHome = m_Properties.GetString ("MIDIButtonActionHome", "");

m_nMIDIButtonPgmUp = m_Properties.GetNumber ("MIDIButtonPgmUp", 0);
m_nMIDIButtonPgmDown = m_Properties.GetNumber ("MIDIButtonPgmDown", 0);
m_nMIDIButtonBankUp = m_Properties.GetNumber ("MIDIButtonBankUp", 0);
m_nMIDIButtonBankDown = m_Properties.GetNumber ("MIDIButtonBankDown", 0);
m_nMIDIButtonTGUp = m_Properties.GetNumber ("MIDIButtonTGUp", 0);
m_nMIDIButtonTGDown = m_Properties.GetNumber ("MIDIButtonTGDown", 0);

m_MIDIButtonActionPgmUp = m_Properties.GetString ("MIDIButtonActionPgmUp", "");
m_MIDIButtonActionPgmDown = m_Properties.GetString ("MIDIButtonActionPgmDown", "");
m_MIDIButtonActionBankUp = m_Properties.GetString ("MIDIButtonActionBankUp", "");
m_MIDIButtonActionBankDown = m_Properties.GetString ("MIDIButtonActionBankDown", "");
m_MIDIButtonActionTGUp = m_Properties.GetString ("MIDIButtonActionTGUp", "");
m_MIDIButtonActionTGDown = m_Properties.GetString ("MIDIButtonActionTGDown", "");

m_bEncoderEnabled = m_Properties.GetNumber ("EncoderEnabled", 0) != 0;
m_nEncoderPinClock = m_Properties.GetNumber ("EncoderPinClock", 10);
Expand Down Expand Up @@ -652,6 +666,31 @@ unsigned CConfig::GetMIDIButtonHome (void) const
return m_nMIDIButtonHome;
}

const char *CConfig::GetMIDIButtonActionPrev (void) const
{
return m_MIDIButtonActionPrev.c_str();
}

const char *CConfig::GetMIDIButtonActionNext (void) const
{
return m_MIDIButtonActionNext.c_str();
}

const char *CConfig::GetMIDIButtonActionBack (void) const
{
return m_MIDIButtonActionBack.c_str();
}

const char *CConfig::GetMIDIButtonActionSelect (void) const
{
return m_MIDIButtonActionSelect.c_str();
}

const char *CConfig::GetMIDIButtonActionHome (void) const
{
return m_MIDIButtonActionHome.c_str();
}

unsigned CConfig::GetMIDIButtonPgmUp (void) const
{
return m_nMIDIButtonPgmUp;
Expand Down Expand Up @@ -682,6 +721,36 @@ unsigned CConfig::GetMIDIButtonTGDown (void) const
return m_nMIDIButtonTGDown;
}

const char *CConfig::GetMIDIButtonActionPgmUp (void) const
{
return m_MIDIButtonActionPgmUp.c_str();
}

const char *CConfig::GetMIDIButtonActionPgmDown (void) const
{
return m_MIDIButtonActionPgmDown.c_str();
}

const char *CConfig::GetMIDIButtonActionBankUp (void) const
{
return m_MIDIButtonActionBankUp.c_str();
}

const char *CConfig::GetMIDIButtonActionBankDown (void) const
{
return m_MIDIButtonActionBankDown.c_str();
}

const char *CConfig::GetMIDIButtonActionTGUp (void) const
{
return m_MIDIButtonActionTGUp.c_str();
}

const char *CConfig::GetMIDIButtonActionTGDown (void) const
{
return m_MIDIButtonActionTGDown.c_str();
}

bool CConfig::GetEncoderEnabled (void) const
{
return m_bEncoderEnabled;
Expand Down
28 changes: 28 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,20 @@ class CConfig // Configuration for MiniDexed
// MIDI Button Navigation
unsigned GetMIDIButtonCh (void) const;
unsigned GetMIDIButtonNotes (void) const;

unsigned GetMIDIButtonPrev (void) const;
unsigned GetMIDIButtonNext (void) const;
unsigned GetMIDIButtonBack (void) const;
unsigned GetMIDIButtonSelect (void) const;
unsigned GetMIDIButtonHome (void) const;

// Action type for Midi buttons: "click", "doubleclick", "longpress", "dec", "inc", ""
const char *GetMIDIButtonActionPrev (void) const;
const char *GetMIDIButtonActionNext (void) const;
const char *GetMIDIButtonActionBack (void) const;
const char *GetMIDIButtonActionSelect (void) const;
const char *GetMIDIButtonActionHome (void) const;

// MIDI Button Program and TG Selection
unsigned GetMIDIButtonPgmUp (void) const;
unsigned GetMIDIButtonPgmDown (void) const;
Expand All @@ -224,6 +232,14 @@ class CConfig // Configuration for MiniDexed
unsigned GetMIDIButtonTGUp (void) const;
unsigned GetMIDIButtonTGDown (void) const;

// Action type for buttons: "click", "doubleclick", "longpress", "dec", "inc", ""
const char *GetMIDIButtonActionPgmUp (void) const;
const char *GetMIDIButtonActionPgmDown (void) const;
const char *GetMIDIButtonActionBankUp (void) const;
const char *GetMIDIButtonActionBankDown (void) const;
const char *GetMIDIButtonActionTGUp (void) const;
const char *GetMIDIButtonActionTGDown (void) const;

// KY-040 Rotary Encoder
// GPIO pin numbers are chip numbers, not header positions
bool GetEncoderEnabled (void) const;
Expand Down Expand Up @@ -326,6 +342,18 @@ class CConfig // Configuration for MiniDexed
std::string m_ButtonActionTGUp;
std::string m_ButtonActionTGDown;

std::string m_MIDIButtonActionPrev;
std::string m_MIDIButtonActionNext;
std::string m_MIDIButtonActionBack;
std::string m_MIDIButtonActionSelect;
std::string m_MIDIButtonActionHome;
std::string m_MIDIButtonActionPgmUp;
std::string m_MIDIButtonActionPgmDown;
std::string m_MIDIButtonActionBankUp;
std::string m_MIDIButtonActionBankDown;
std::string m_MIDIButtonActionTGUp;
std::string m_MIDIButtonActionTGDown;

unsigned m_nDoubleClickTimeout;
unsigned m_nLongPressTimeout;

Expand Down
12 changes: 11 additions & 1 deletion src/midipin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ LOGMODULE ("midipin");

CMIDIPin::CMIDIPin (unsigned nPinNumber)
: m_nPinNumber (nPinNumber),
m_nValue (HIGH)
m_nValue (HIGH),
m_nRawValue (MIDIPIN_CENTER)
{
}

Expand All @@ -38,6 +39,11 @@ unsigned CMIDIPin::Read (void)
return m_nValue;
}

unsigned CMIDIPin::ReadRaw (void)
{
return m_nRawValue;
}

void CMIDIPin::Write (unsigned nValue)
{
// Takes values in the MIDI controller range 0 to 127
Expand All @@ -50,6 +56,10 @@ void CMIDIPin::Write (unsigned nValue)
// "off"
m_nValue = HIGH;
}

// Save the raw value for INC and DEC
m_nRawValue = nValue;

return;
}

8 changes: 7 additions & 1 deletion src/midipin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#define MidiPinToCC(p) (((p)>=MIDI_PINS)?((p)-MIDI_PINS):0)
#define isMidiPin(p) (((p)>=MIDI_PINS)?1:0)

#define MIDIPIN_CENTER 64

class CMIDIPin
{
public:
Expand All @@ -42,14 +44,18 @@ class CMIDIPin
// Should be treated as a PULLED UP IO pin
// i.e. treated as "active low" (LOW) when pressed.
unsigned Read (void);


// returns the raw CC value
unsigned ReadRaw (void);

// MIDI CC values >=64 will set the MIDI pin to LOW ("on")
// MIDI CC values <= 63 will set the MIDI pin to HIGH ("off")
void Write (unsigned nValue);

private:
unsigned m_nPinNumber;
unsigned m_nValue;
unsigned m_nRawValue;
};

#endif
14 changes: 13 additions & 1 deletion src/minidexed.ini
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,40 @@ LongPressTimeout=400

# MIDI Button Navigation
# Specify MIDI CC to act as a button (0 = ununsed, so don't use CC 0)
# NB: Off < 64 < ON
# NB: Off < 64 < ON for longpress / click / doubleclick actions
# DEC < 64 < INC for dec / inc actions
# CC channel: 0=OFF; 1-16 MIDI Ch; >16 Omni
# If MIDIButtonNotes>0 then treat MIDIButton numbers as MIDI
# Note numbers, triggered with NoteOn/NoteOff, not CC numbers.
MIDIButtonCh=17
MIDIButtonNotes=0
# Arrow left
MIDIButtonPrev=46
MIDIButtonActionPrev=click
# Arrow right
MIDIButtonNext=47
MIDIButtonActionNext=click
# Arrow up
MIDIButtonBack=48
MIDIButtonActionBack=click
# Arrow down
MIDIButtonSelect=49
MIDIButtonActionSelect=click
# Home button
MIDIButtonHome=50
MIDIButtonActionHome=click
MIDIButtonPgmUp=51
MIDIButtonActionPgmUp=click
MIDIButtonPgmDown=52
MIDIButtonActionPgmDown=click
MIDIButtonBankUp=53
MIDIButtonActionBankUp=click
MIDIButtonBankDown=54
MIDIButtonActionBankDown=click
MIDIButtonTGUp=55
MIDIButtonActionTGUp=click
MIDIButtonTGDown=56
MIDIButtonActionTGDown=click

# KY-040 Rotary Encoder
EncoderEnabled=1
Expand Down
Loading