mirror of https://github.com/probonopd/MiniDexed
Enable buttons on MIDI controllers to be used (#365)
* Initial commit for MIDI user interface button support. Status: first successful build. * Second try with more functionality plugged in and compiling... * First "it seems to work for me" version for initial testing of MIDI buttons. * Fix Off/Omni logic * Fix order of Prev/Next when initialising the button UI. Co-authored-by: Kevin <68612569+diyelectromusic@users.noreply.github.com>pull/366/head^2
parent
d53aeb40f5
commit
c7168d434f
@ -0,0 +1,55 @@ |
|||||||
|
//
|
||||||
|
// midipin.cpp
|
||||||
|
//
|
||||||
|
// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi
|
||||||
|
// Copyright (C) 2022 The MiniDexed Team
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
#include "midipin.h" |
||||||
|
#include <circle/logger.h> |
||||||
|
#include <assert.h> |
||||||
|
|
||||||
|
LOGMODULE ("midipin"); |
||||||
|
|
||||||
|
CMIDIPin::CMIDIPin (unsigned nPinNumber) |
||||||
|
: m_nPinNumber (nPinNumber), |
||||||
|
m_nValue (HIGH) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
CMIDIPin::~CMIDIPin (void) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
unsigned CMIDIPin::Read (void) |
||||||
|
{ |
||||||
|
return m_nValue; |
||||||
|
} |
||||||
|
|
||||||
|
void CMIDIPin::Write (unsigned nValue) |
||||||
|
{ |
||||||
|
// Takes values in the MIDI controller range 0 to 127
|
||||||
|
// and OFF < 64 < ON.
|
||||||
|
// Simulates a PULLUP IO pin, so "true" is LOW (0)
|
||||||
|
if (nValue >= 64) { |
||||||
|
// "on"
|
||||||
|
m_nValue = LOW; |
||||||
|
} else { |
||||||
|
// "off"
|
||||||
|
m_nValue = HIGH; |
||||||
|
} |
||||||
|
return; |
||||||
|
} |
||||||
|
|
@ -0,0 +1,54 @@ |
|||||||
|
//
|
||||||
|
// midipin.h
|
||||||
|
//
|
||||||
|
// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi
|
||||||
|
// Copyright (C) 2022 The MiniDexed Team
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
#ifndef _midipin_h |
||||||
|
#define _midipin_h |
||||||
|
|
||||||
|
#include <circle/gpiopin.h> |
||||||
|
#include <circle/types.h> |
||||||
|
|
||||||
|
// MIDI CC numbers go 0 to 127.
|
||||||
|
// Normal GPIO pins are below 100.
|
||||||
|
// So use a "pin number" of 128 + MIDI CC message for a "MIDI Pin"
|
||||||
|
#define MIDI_PINS 128 |
||||||
|
#define ccToMidiPin(c) ((c)+MIDI_PINS) |
||||||
|
#define MidiPinToCC(p) ((p)-MIDI_PINS) |
||||||
|
#define isMidiPin(p) (((p)>=MIDI_PINS)?1:0) |
||||||
|
|
||||||
|
class CMIDIPin |
||||||
|
{ |
||||||
|
public: |
||||||
|
CMIDIPin (unsigned nPinNumber); // pinNumber = ccToMidiPin (MIDI CC number)
|
||||||
|
~CMIDIPin (void); |
||||||
|
|
||||||
|
// Will return MP_HIGH or MP_LOW.
|
||||||
|
// Should be treated as a PULLED UP IO pin
|
||||||
|
// i.e. treated as "active low" (LOW) when pressed.
|
||||||
|
unsigned Read (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; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif |
Loading…
Reference in new issue