mirror of https://github.com/probonopd/MiniDexed
Restructure code and add new features (#37)
* Make synth parameters configurable * Add class CConfig, which holds the configuration * Add template config file minidexed.ini * Register panic handler in CKernel to allow to display assertions * Fix: Performance timer did not show correct percent value with HDMI * Add class CDexedAdapter Some Dexed methods require to be guarded from being interrupted by other Dexed calls. This is done in the class CDexedAdapter. * Add class CUserInterface The user interface should be implemented here. As a start it supports showing the program number and name on the LCD display. The LCD output is buffered, so that LCD writes from an IRQ handler are possible. * Move MIDI handling from CMiniDexed to specific classes * CMIDIDevice is the generic MIDI handler * CMIDIKeyboard handles USB audio class MIDI devices * CSerialMIDIDevice handles the serial MIDI device * Now all MIDI inputs can work simultaneous * Program change and bank select work with serial MIDI * Add headers to all files * Include voices.c in sysexfileloader.cpp * Cleanup Makefile * Support headless operation on Raspberry Pi 4 Some code cleanup for src/kernel.* * Code cleanup for src/minidexed.* Move implementation of constructors to minidexed.cpp Reorder member variables * Support multiple USB MIDI inputs at once * Maximum 2 inputs on Raspberry Pi 1-3 * Maximum 4 inputs on Raspberry Pi 4 * Suppress frequent messages in MIDI dump * Use minidexed.txt * Document `SoundDevice` in `minidexed.ini` Co-authored-by: probonopd <probonopd@users.noreply.github.com>pull/40/head
parent
6baba1eb7e
commit
8be0781b49
@ -0,0 +1,132 @@ |
|||||||
|
//
|
||||||
|
// config.cpp
|
||||||
|
//
|
||||||
|
// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi
|
||||||
|
// Copyright (C) 2022 The MiniDexed Team
|
||||||
|
//
|
||||||
|
// Original author of this class:
|
||||||
|
// R. Stange <rsta2@o2online.de>
|
||||||
|
//
|
||||||
|
// 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 "config.h" |
||||||
|
|
||||||
|
CConfig::CConfig (FATFS *pFileSystem) |
||||||
|
: m_Properties ("minidexed.ini", pFileSystem) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
CConfig::~CConfig (void) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void CConfig::Load (void) |
||||||
|
{ |
||||||
|
m_Properties.Load (); |
||||||
|
|
||||||
|
m_SoundDevice = m_Properties.GetString ("SoundDevice", "pwm"); |
||||||
|
|
||||||
|
m_nSampleRate = m_Properties.GetNumber ("SampleRate", 48000); |
||||||
|
m_nChunkSize = m_Properties.GetNumber ("ChunkSize", m_SoundDevice == "hdmi" ? 384*6 : 256); |
||||||
|
m_nDACI2CAddress = m_Properties.GetNumber ("DACI2CAddress", 0); |
||||||
|
|
||||||
|
m_nMIDIBaudRate = m_Properties.GetNumber ("MIDIBaudRate", 31250); |
||||||
|
|
||||||
|
m_bLCDEnabled = m_Properties.GetNumber ("LCDEnabled", 0) != 0; |
||||||
|
m_nLCDPinEnable = m_Properties.GetNumber ("LCDPinEnable", 17); |
||||||
|
m_nLCDPinRegisterSelect = m_Properties.GetNumber ("LCDPinRegisterSelect", 18); |
||||||
|
m_nLCDPinReadWrite = m_Properties.GetNumber ("LCDPinReadWrite", 19); |
||||||
|
m_nLCDPinData4 = m_Properties.GetNumber ("LCDPinData4", 22); |
||||||
|
m_nLCDPinData5 = m_Properties.GetNumber ("LCDPinData5", 23); |
||||||
|
m_nLCDPinData6 = m_Properties.GetNumber ("LCDPinData6", 24); |
||||||
|
m_nLCDPinData7 = m_Properties.GetNumber ("LCDPinData7", 25); |
||||||
|
|
||||||
|
m_bMIDIDumpEnabled = m_Properties.GetNumber ("MIDIDumpEnabled", 0) != 0; |
||||||
|
m_bProfileEnabled = m_Properties.GetNumber ("ProfileEnabled", 0) != 0; |
||||||
|
} |
||||||
|
|
||||||
|
const char *CConfig::GetSoundDevice (void) const |
||||||
|
{ |
||||||
|
return m_SoundDevice.c_str (); |
||||||
|
} |
||||||
|
|
||||||
|
unsigned CConfig::GetSampleRate (void) const |
||||||
|
{ |
||||||
|
return m_nSampleRate; |
||||||
|
} |
||||||
|
|
||||||
|
unsigned CConfig::GetChunkSize (void) const |
||||||
|
{ |
||||||
|
return m_nChunkSize; |
||||||
|
} |
||||||
|
|
||||||
|
unsigned CConfig::GetDACI2CAddress (void) const |
||||||
|
{ |
||||||
|
return m_nDACI2CAddress; |
||||||
|
} |
||||||
|
|
||||||
|
unsigned CConfig::GetMIDIBaudRate (void) const |
||||||
|
{ |
||||||
|
return m_nMIDIBaudRate; |
||||||
|
} |
||||||
|
|
||||||
|
bool CConfig::GetLCDEnabled (void) const |
||||||
|
{ |
||||||
|
return m_bLCDEnabled; |
||||||
|
} |
||||||
|
|
||||||
|
unsigned CConfig::GetLCDPinEnable (void) const |
||||||
|
{ |
||||||
|
return m_nLCDPinEnable; |
||||||
|
} |
||||||
|
|
||||||
|
unsigned CConfig::GetLCDPinRegisterSelect (void) const |
||||||
|
{ |
||||||
|
return m_nLCDPinRegisterSelect; |
||||||
|
} |
||||||
|
|
||||||
|
unsigned CConfig::GetLCDPinReadWrite (void) const |
||||||
|
{ |
||||||
|
return m_nLCDPinReadWrite; |
||||||
|
} |
||||||
|
|
||||||
|
unsigned CConfig::GetLCDPinData4 (void) const |
||||||
|
{ |
||||||
|
return m_nLCDPinData4; |
||||||
|
} |
||||||
|
|
||||||
|
unsigned CConfig::GetLCDPinData5 (void) const |
||||||
|
{ |
||||||
|
return m_nLCDPinData5; |
||||||
|
} |
||||||
|
|
||||||
|
unsigned CConfig::GetLCDPinData6 (void) const |
||||||
|
{ |
||||||
|
return m_nLCDPinData6; |
||||||
|
} |
||||||
|
|
||||||
|
unsigned CConfig::GetLCDPinData7 (void) const |
||||||
|
{ |
||||||
|
return m_nLCDPinData7; |
||||||
|
} |
||||||
|
|
||||||
|
bool CConfig::GetMIDIDumpEnabled (void) const |
||||||
|
{ |
||||||
|
return m_bMIDIDumpEnabled; |
||||||
|
} |
||||||
|
|
||||||
|
bool CConfig::GetProfileEnabled (void) const |
||||||
|
{ |
||||||
|
return m_bProfileEnabled; |
||||||
|
} |
@ -0,0 +1,97 @@ |
|||||||
|
//
|
||||||
|
// config.h
|
||||||
|
//
|
||||||
|
// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi
|
||||||
|
// Copyright (C) 2022 The MiniDexed Team
|
||||||
|
//
|
||||||
|
// Original author of this class:
|
||||||
|
// R. Stange <rsta2@o2online.de>
|
||||||
|
//
|
||||||
|
// 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 _config_h |
||||||
|
#define _config_h |
||||||
|
|
||||||
|
#include <fatfs/ff.h> |
||||||
|
#include <Properties/propertiesfatfsfile.h> |
||||||
|
#include <string> |
||||||
|
|
||||||
|
class CConfig // Configuration for MiniDexed
|
||||||
|
{ |
||||||
|
public: |
||||||
|
static const unsigned MaxNotes = 16; // polyphony
|
||||||
|
|
||||||
|
#if RASPPI <= 3 |
||||||
|
static const unsigned MaxUSBMIDIDevices = 2; |
||||||
|
#else |
||||||
|
static const unsigned MaxUSBMIDIDevices = 4; |
||||||
|
#endif |
||||||
|
|
||||||
|
static const unsigned LCDColumns = 16; // HD44780 LCD
|
||||||
|
static const unsigned LCDRows = 2; |
||||||
|
|
||||||
|
public: |
||||||
|
CConfig (FATFS *pFileSystem); |
||||||
|
~CConfig (void); |
||||||
|
|
||||||
|
void Load (void); |
||||||
|
|
||||||
|
// Sound device
|
||||||
|
const char *GetSoundDevice (void) const; |
||||||
|
unsigned GetSampleRate (void) const; |
||||||
|
unsigned GetChunkSize (void) const; |
||||||
|
unsigned GetDACI2CAddress (void) const; // 0 for auto probing
|
||||||
|
|
||||||
|
// MIDI
|
||||||
|
unsigned GetMIDIBaudRate (void) const; |
||||||
|
|
||||||
|
// HD44780 LCD
|
||||||
|
// GPIO pin numbers are chip numbers, not header positions
|
||||||
|
bool GetLCDEnabled (void) const; |
||||||
|
unsigned GetLCDPinEnable (void) const; |
||||||
|
unsigned GetLCDPinRegisterSelect (void) const; |
||||||
|
unsigned GetLCDPinReadWrite (void) const; // set to 0 if not connected
|
||||||
|
unsigned GetLCDPinData4 (void) const; |
||||||
|
unsigned GetLCDPinData5 (void) const; |
||||||
|
unsigned GetLCDPinData6 (void) const; |
||||||
|
unsigned GetLCDPinData7 (void) const; |
||||||
|
|
||||||
|
// Debug
|
||||||
|
bool GetMIDIDumpEnabled (void) const; |
||||||
|
bool GetProfileEnabled (void) const; |
||||||
|
|
||||||
|
private: |
||||||
|
CPropertiesFatFsFile m_Properties; |
||||||
|
|
||||||
|
std::string m_SoundDevice; |
||||||
|
unsigned m_nSampleRate; |
||||||
|
unsigned m_nChunkSize; |
||||||
|
unsigned m_nDACI2CAddress; |
||||||
|
|
||||||
|
unsigned m_nMIDIBaudRate; |
||||||
|
|
||||||
|
bool m_bLCDEnabled; |
||||||
|
unsigned m_nLCDPinEnable; |
||||||
|
unsigned m_nLCDPinRegisterSelect; |
||||||
|
unsigned m_nLCDPinReadWrite; |
||||||
|
unsigned m_nLCDPinData4; |
||||||
|
unsigned m_nLCDPinData5; |
||||||
|
unsigned m_nLCDPinData6; |
||||||
|
unsigned m_nLCDPinData7; |
||||||
|
|
||||||
|
bool m_bMIDIDumpEnabled; |
||||||
|
bool m_bProfileEnabled; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif |
@ -0,0 +1,70 @@ |
|||||||
|
//
|
||||||
|
// dexedadapter.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 _dexedadapter_h |
||||||
|
#define _dexedadapter_h |
||||||
|
|
||||||
|
#include <synth_dexed.h> |
||||||
|
#include <circle/spinlock.h> |
||||||
|
#include <stdint.h> |
||||||
|
|
||||||
|
// Some Dexed methods require to be guarded from being interrupted
|
||||||
|
// by other Dexed calls. This is done herein.
|
||||||
|
|
||||||
|
class CDexedAdapter : public Dexed |
||||||
|
{ |
||||||
|
public: |
||||||
|
CDexedAdapter (uint8_t maxnotes, int rate) |
||||||
|
: Dexed (maxnotes, rate) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void loadVoiceParameters (uint8_t* data) |
||||||
|
{ |
||||||
|
m_SpinLock.Acquire (); |
||||||
|
Dexed::loadVoiceParameters (data); |
||||||
|
m_SpinLock.Release (); |
||||||
|
} |
||||||
|
|
||||||
|
void keyup (int16_t pitch) |
||||||
|
{ |
||||||
|
m_SpinLock.Acquire (); |
||||||
|
Dexed::keyup (pitch); |
||||||
|
m_SpinLock.Release (); |
||||||
|
} |
||||||
|
|
||||||
|
void keydown (int16_t pitch, uint8_t velo) |
||||||
|
{ |
||||||
|
m_SpinLock.Acquire (); |
||||||
|
Dexed::keydown (pitch, velo); |
||||||
|
m_SpinLock.Release (); |
||||||
|
} |
||||||
|
|
||||||
|
void getSamples (uint16_t n_samples, int16_t* buffer) |
||||||
|
{ |
||||||
|
m_SpinLock.Acquire (); |
||||||
|
Dexed::getSamples (n_samples, buffer); |
||||||
|
m_SpinLock.Release (); |
||||||
|
} |
||||||
|
|
||||||
|
private: |
||||||
|
CSpinLock m_SpinLock; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif |
@ -0,0 +1,150 @@ |
|||||||
|
//
|
||||||
|
// mididevice.cpp
|
||||||
|
//
|
||||||
|
// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi
|
||||||
|
// Copyright (C) 2022 The MiniDexed Team
|
||||||
|
//
|
||||||
|
// Original author of this class:
|
||||||
|
// R. Stange <rsta2@o2online.de>
|
||||||
|
//
|
||||||
|
// 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 "mididevice.h" |
||||||
|
#include "minidexed.h" |
||||||
|
#include "config.h" |
||||||
|
#include <stdio.h> |
||||||
|
#include <assert.h> |
||||||
|
|
||||||
|
#define MIDI_NOTE_OFF 0b1000 |
||||||
|
#define MIDI_NOTE_ON 0b1001 |
||||||
|
#define MIDI_AFTERTOUCH 0b1010 // TODO
|
||||||
|
#define MIDI_CONTROL_CHANGE 0b1011 |
||||||
|
#define MIDI_CC_BANK_SELECT_MSB 0 // TODO
|
||||||
|
#define MIDI_CC_BANK_SELECT_LSB 32 |
||||||
|
#define MIDI_PROGRAM_CHANGE 0b1100 |
||||||
|
#define MIDI_PITCH_BEND 0b1110 |
||||||
|
|
||||||
|
#define MIDI_TIMING_CLOCK 0xF8 |
||||||
|
#define MIDI_ACTIVE_SENSING 0xFE |
||||||
|
|
||||||
|
CMIDIDevice::CMIDIDevice (CMiniDexed *pSynthesizer, CConfig *pConfig) |
||||||
|
: m_pSynthesizer (pSynthesizer), |
||||||
|
m_pConfig (pConfig) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
CMIDIDevice::~CMIDIDevice (void) |
||||||
|
{ |
||||||
|
m_pSynthesizer = 0; |
||||||
|
} |
||||||
|
|
||||||
|
void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsigned nCable) |
||||||
|
{ |
||||||
|
assert (m_pSynthesizer != 0); |
||||||
|
|
||||||
|
// The packet contents are just normal MIDI data - see
|
||||||
|
// https://www.midi.org/specifications/item/table-1-summary-of-midi-message
|
||||||
|
|
||||||
|
if (m_pConfig->GetMIDIDumpEnabled ()) |
||||||
|
{ |
||||||
|
switch (nLength) |
||||||
|
{ |
||||||
|
case 1: |
||||||
|
if ( pMessage[0] != MIDI_TIMING_CLOCK |
||||||
|
&& pMessage[0] != MIDI_ACTIVE_SENSING) |
||||||
|
{ |
||||||
|
printf ("MIDI %u: %02X\n", nCable, (unsigned) pMessage[0]); |
||||||
|
} |
||||||
|
break; |
||||||
|
|
||||||
|
case 2: |
||||||
|
printf ("MIDI %u: %02X %02X\n", nCable, |
||||||
|
(unsigned) pMessage[0], (unsigned) pMessage[1]); |
||||||
|
break; |
||||||
|
|
||||||
|
case 3: |
||||||
|
printf ("MIDI %u: %02X %02X %02X\n", nCable, |
||||||
|
(unsigned) pMessage[0], (unsigned) pMessage[1], |
||||||
|
(unsigned) pMessage[2]); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (nLength < 2) |
||||||
|
{ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
u8 ucStatus = pMessage[0]; |
||||||
|
// TODO: u8 ucChannel = ucStatus & 0x0F;
|
||||||
|
u8 ucType = ucStatus >> 4; |
||||||
|
u8 ucKeyNumber = pMessage[1]; |
||||||
|
u8 ucVelocity = pMessage[2]; |
||||||
|
|
||||||
|
switch (ucType) |
||||||
|
{ |
||||||
|
case MIDI_NOTE_ON: |
||||||
|
if (nLength < 3) |
||||||
|
{ |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
if (ucVelocity > 0) |
||||||
|
{ |
||||||
|
if (ucVelocity <= 127) |
||||||
|
{ |
||||||
|
m_pSynthesizer->keydown (ucKeyNumber, ucVelocity); |
||||||
|
} |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
m_pSynthesizer->keyup (ucKeyNumber); |
||||||
|
} |
||||||
|
break; |
||||||
|
|
||||||
|
case MIDI_NOTE_OFF: |
||||||
|
if (nLength < 3) |
||||||
|
{ |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
m_pSynthesizer->keyup (ucKeyNumber); |
||||||
|
break; |
||||||
|
|
||||||
|
case MIDI_CONTROL_CHANGE: |
||||||
|
if (nLength < 3) |
||||||
|
{ |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
switch (pMessage[1]) |
||||||
|
{ |
||||||
|
case MIDI_CC_BANK_SELECT_LSB: |
||||||
|
m_pSynthesizer->BankSelectLSB (pMessage[2]); |
||||||
|
break; |
||||||
|
} |
||||||
|
break; |
||||||
|
|
||||||
|
case MIDI_PROGRAM_CHANGE: |
||||||
|
m_pSynthesizer->ProgramChange (pMessage[1]); |
||||||
|
break; |
||||||
|
|
||||||
|
case MIDI_PITCH_BEND: |
||||||
|
m_pSynthesizer->setPitchbend (pMessage[1]); |
||||||
|
break; |
||||||
|
|
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
//
|
||||||
|
// mididevice.h
|
||||||
|
//
|
||||||
|
// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi
|
||||||
|
// Copyright (C) 2022 The MiniDexed Team
|
||||||
|
//
|
||||||
|
// Original author of this class:
|
||||||
|
// R. Stange <rsta2@o2online.de>
|
||||||
|
//
|
||||||
|
// 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 _mididevice_h |
||||||
|
#define _mididevice_h |
||||||
|
|
||||||
|
#include "config.h" |
||||||
|
#include <circle/types.h> |
||||||
|
|
||||||
|
class CMiniDexed; |
||||||
|
|
||||||
|
class CMIDIDevice |
||||||
|
{ |
||||||
|
public: |
||||||
|
CMIDIDevice (CMiniDexed *pSynthesizer, CConfig *pConfig); |
||||||
|
~CMIDIDevice (void); |
||||||
|
|
||||||
|
protected: |
||||||
|
void MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsigned nCable = 0); |
||||||
|
|
||||||
|
private: |
||||||
|
CMiniDexed *m_pSynthesizer; |
||||||
|
CConfig *m_pConfig; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif |
@ -0,0 +1,105 @@ |
|||||||
|
//
|
||||||
|
// midikeyboard.cpp
|
||||||
|
//
|
||||||
|
// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi
|
||||||
|
// Copyright (C) 2022 The MiniDexed Team
|
||||||
|
//
|
||||||
|
// Original author of this class:
|
||||||
|
// R. Stange <rsta2@o2online.de>
|
||||||
|
//
|
||||||
|
// 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 "midikeyboard.h" |
||||||
|
#include <circle/devicenameservice.h> |
||||||
|
#include <assert.h> |
||||||
|
|
||||||
|
CMIDIKeyboard *CMIDIKeyboard::s_pThis[MaxInstances] = {0}; |
||||||
|
|
||||||
|
TMIDIPacketHandler * const CMIDIKeyboard::s_pMIDIPacketHandler[MaxInstances] = |
||||||
|
{ |
||||||
|
MIDIPacketHandler0, |
||||||
|
MIDIPacketHandler1, |
||||||
|
MIDIPacketHandler2, |
||||||
|
MIDIPacketHandler3 |
||||||
|
}; |
||||||
|
|
||||||
|
CMIDIKeyboard::CMIDIKeyboard (CMiniDexed *pSynthesizer, CConfig *pConfig, unsigned nInstance) |
||||||
|
: CMIDIDevice (pSynthesizer, pConfig), |
||||||
|
m_nInstance (nInstance), |
||||||
|
m_pMIDIDevice (0) |
||||||
|
{ |
||||||
|
assert (m_nInstance < MaxInstances); |
||||||
|
s_pThis[m_nInstance] = this; |
||||||
|
|
||||||
|
m_DeviceName.Format ("umidi%u", nInstance+1); |
||||||
|
} |
||||||
|
|
||||||
|
CMIDIKeyboard::~CMIDIKeyboard (void) |
||||||
|
{ |
||||||
|
assert (m_nInstance < MaxInstances); |
||||||
|
s_pThis[m_nInstance] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
void CMIDIKeyboard::Process (boolean bPlugAndPlayUpdated) |
||||||
|
{ |
||||||
|
if (!bPlugAndPlayUpdated) |
||||||
|
{ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if (m_pMIDIDevice == 0) |
||||||
|
{ |
||||||
|
m_pMIDIDevice = |
||||||
|
(CUSBMIDIDevice *) CDeviceNameService::Get ()->GetDevice (m_DeviceName, FALSE); |
||||||
|
if (m_pMIDIDevice != 0) |
||||||
|
{ |
||||||
|
assert (m_nInstance < MaxInstances); |
||||||
|
m_pMIDIDevice->RegisterPacketHandler (s_pMIDIPacketHandler[m_nInstance]); |
||||||
|
|
||||||
|
m_pMIDIDevice->RegisterRemovedHandler (DeviceRemovedHandler, this); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void CMIDIKeyboard::MIDIPacketHandler0 (unsigned nCable, u8 *pPacket, unsigned nLength) |
||||||
|
{ |
||||||
|
assert (s_pThis[0] != 0); |
||||||
|
s_pThis[0]->MIDIMessageHandler (pPacket, nLength, nCable); |
||||||
|
} |
||||||
|
|
||||||
|
void CMIDIKeyboard::MIDIPacketHandler1 (unsigned nCable, u8 *pPacket, unsigned nLength) |
||||||
|
{ |
||||||
|
assert (s_pThis[1] != 0); |
||||||
|
s_pThis[1]->MIDIMessageHandler (pPacket, nLength, nCable); |
||||||
|
} |
||||||
|
|
||||||
|
void CMIDIKeyboard::MIDIPacketHandler2 (unsigned nCable, u8 *pPacket, unsigned nLength) |
||||||
|
{ |
||||||
|
assert (s_pThis[2] != 0); |
||||||
|
s_pThis[2]->MIDIMessageHandler (pPacket, nLength, nCable); |
||||||
|
} |
||||||
|
|
||||||
|
void CMIDIKeyboard::MIDIPacketHandler3 (unsigned nCable, u8 *pPacket, unsigned nLength) |
||||||
|
{ |
||||||
|
assert (s_pThis[3] != 0); |
||||||
|
s_pThis[3]->MIDIMessageHandler (pPacket, nLength, nCable); |
||||||
|
} |
||||||
|
|
||||||
|
void CMIDIKeyboard::DeviceRemovedHandler (CDevice *pDevice, void *pContext) |
||||||
|
{ |
||||||
|
CMIDIKeyboard *pThis = static_cast<CMIDIKeyboard *> (pContext); |
||||||
|
assert (pThis != 0); |
||||||
|
|
||||||
|
pThis->m_pMIDIDevice = 0; |
||||||
|
} |
@ -0,0 +1,65 @@ |
|||||||
|
//
|
||||||
|
// midikeyboard.h
|
||||||
|
//
|
||||||
|
// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi
|
||||||
|
// Copyright (C) 2022 The MiniDexed Team
|
||||||
|
//
|
||||||
|
// Original author of this class:
|
||||||
|
// R. Stange <rsta2@o2online.de>
|
||||||
|
//
|
||||||
|
// 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 _midikeyboard_h |
||||||
|
#define _midikeyboard_h |
||||||
|
|
||||||
|
#include "mididevice.h" |
||||||
|
#include "config.h" |
||||||
|
#include <circle/usb/usbmidi.h> |
||||||
|
#include <circle/device.h> |
||||||
|
#include <circle/string.h> |
||||||
|
#include <circle/types.h> |
||||||
|
|
||||||
|
class CMiniDexed; |
||||||
|
|
||||||
|
class CMIDIKeyboard : public CMIDIDevice |
||||||
|
{ |
||||||
|
public: |
||||||
|
static const unsigned MaxInstances = 4; |
||||||
|
|
||||||
|
public: |
||||||
|
CMIDIKeyboard (CMiniDexed *pSynthesizer, CConfig *pConfig, unsigned nInstance = 0); |
||||||
|
~CMIDIKeyboard (void); |
||||||
|
|
||||||
|
void Process (boolean bPlugAndPlayUpdated); |
||||||
|
|
||||||
|
private: |
||||||
|
static void MIDIPacketHandler0 (unsigned nCable, u8 *pPacket, unsigned nLength); |
||||||
|
static void MIDIPacketHandler1 (unsigned nCable, u8 *pPacket, unsigned nLength); |
||||||
|
static void MIDIPacketHandler2 (unsigned nCable, u8 *pPacket, unsigned nLength); |
||||||
|
static void MIDIPacketHandler3 (unsigned nCable, u8 *pPacket, unsigned nLength); |
||||||
|
|
||||||
|
static void DeviceRemovedHandler (CDevice *pDevice, void *pContext); |
||||||
|
|
||||||
|
private: |
||||||
|
unsigned m_nInstance; |
||||||
|
CString m_DeviceName; |
||||||
|
|
||||||
|
CUSBMIDIDevice * volatile m_pMIDIDevice; |
||||||
|
|
||||||
|
static CMIDIKeyboard *s_pThis[MaxInstances]; |
||||||
|
|
||||||
|
static TMIDIPacketHandler * const s_pMIDIPacketHandler[MaxInstances]; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif |
@ -1,117 +1,104 @@ |
|||||||
//
|
//
|
||||||
// minidexed.h
|
// minidexed.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 _minidexed_h |
#ifndef _minidexed_h |
||||||
#define _minidexed_h |
#define _minidexed_h |
||||||
|
|
||||||
#include <synth_dexed.h> |
#include "dexedadapter.h" |
||||||
|
#include "config.h" |
||||||
|
#include "userinterface.h" |
||||||
|
#include "sysexfileloader.h" |
||||||
|
#include "midikeyboard.h" |
||||||
|
#include "pckeyboard.h" |
||||||
|
#include "serialmididevice.h" |
||||||
|
#include "perftimer.h" |
||||||
#include <stdint.h> |
#include <stdint.h> |
||||||
#include <math.h> |
#include <circle/types.h> |
||||||
#include <circle/interrupt.h> |
#include <circle/interrupt.h> |
||||||
#include <circle/i2cmaster.h> |
#include <circle/i2cmaster.h> |
||||||
#include <circle/usb/usbmidi.h> |
|
||||||
#include <circle/serial.h> |
|
||||||
#include <circle/types.h> |
|
||||||
#include <circle/pwmsoundbasedevice.h> |
#include <circle/pwmsoundbasedevice.h> |
||||||
#include <circle/i2ssoundbasedevice.h> |
#include <circle/i2ssoundbasedevice.h> |
||||||
#include <circle/hdmisoundbasedevice.h> |
#include <circle/hdmisoundbasedevice.h> |
||||||
#include "sysexfileloader.h" |
|
||||||
#include "pckeyboard.h" |
|
||||||
#include <display/hd44780device.h> |
|
||||||
|
|
||||||
#define SAMPLE_RATE 48000 |
class CMiniDexed : public CDexedAdapter |
||||||
|
{ |
||||||
|
public: |
||||||
|
CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt); |
||||||
|
|
||||||
#define CHUNK_SIZE (256) |
virtual bool Initialize (void); |
||||||
#define CHUNK_SIZE_HDMI (384 * 6) |
|
||||||
|
|
||||||
#define DAC_I2C_ADDRESS 0 // I2C slave address of the DAC (0 for auto probing)
|
void Process (bool bPlugAndPlayUpdated); |
||||||
|
|
||||||
// HD44780 LCD configuration
|
void BankSelectLSB (unsigned nBankLSB); |
||||||
#define COLUMNS 16 |
void ProgramChange (unsigned nProgram); |
||||||
#define ROWS 2 |
|
||||||
// GPIO pins (Brcm numbering)
|
|
||||||
#define EN_PIN 17 // Enable
|
|
||||||
#define RS_PIN 18 // Register Select
|
|
||||||
#define RW_PIN 19 // Read/Write (set to 0 if not connected)
|
|
||||||
#define D4_PIN 22 // Data 4
|
|
||||||
#define D5_PIN 23 // Data 5
|
|
||||||
#define D6_PIN 24 // Data 6
|
|
||||||
#define D7_PIN 25 // Data 7
|
|
||||||
|
|
||||||
class CMiniDexed : public Dexed |
private: |
||||||
{ |
CConfig *m_pConfig; |
||||||
public: |
|
||||||
CMiniDexed(uint8_t max_notes, uint16_t sample_rate, CInterruptSystem *pInterrupt) |
CUserInterface m_UI; |
||||||
: Dexed(max_notes,(int)sample_rate), |
CSysExFileLoader m_SysExFileLoader; |
||||||
m_pMIDIDevice (0), |
|
||||||
m_PCKeyboard (this), |
CMIDIKeyboard *m_pMIDIKeyboard[CConfig::MaxUSBMIDIDevices]; |
||||||
m_Serial (pInterrupt, TRUE), |
CPCKeyboard m_PCKeyboard; |
||||||
m_bUseSerial (FALSE), |
CSerialMIDIDevice m_SerialMIDI; |
||||||
m_nSerialState (0), |
bool m_bUseSerial; |
||||||
m_LCD (COLUMNS, ROWS, D4_PIN, D5_PIN, D6_PIN, D7_PIN, EN_PIN, RS_PIN, RW_PIN) |
|
||||||
{ |
protected: |
||||||
s_pThis = this; |
CPerformanceTimer m_GetChunkTimer; |
||||||
}; |
bool m_bProfileEnabled; |
||||||
|
|
||||||
virtual bool Initialize (void); |
|
||||||
void Process(boolean bPlugAndPlayUpdated); |
|
||||||
private: |
|
||||||
void LCDWrite (const char *pString); |
|
||||||
protected: |
|
||||||
static void MIDIPacketHandler (unsigned nCable, u8 *pPacket, unsigned nLength); |
|
||||||
static void KeyStatusHandlerRaw (unsigned char ucModifiers, const unsigned char RawKeys[6]); |
|
||||||
static void ChangeProgram(unsigned program); |
|
||||||
static void USBDeviceRemovedHandler (CDevice *pDevice, void *pContext); |
|
||||||
CUSBMIDIDevice * volatile m_pMIDIDevice; |
|
||||||
CPCKeyboard m_PCKeyboard; |
|
||||||
CSerialDevice m_Serial; |
|
||||||
boolean m_bUseSerial; |
|
||||||
unsigned m_nSerialState; |
|
||||||
u8 m_SerialMessage[3]; |
|
||||||
CSysExFileLoader m_SysExFileLoader; |
|
||||||
private: |
|
||||||
CHD44780Device m_LCD; |
|
||||||
|
|
||||||
static CMiniDexed *s_pThis; |
|
||||||
}; |
}; |
||||||
|
|
||||||
|
//// PWM //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class CMiniDexedPWM : public CMiniDexed, public CPWMSoundBaseDevice |
class CMiniDexedPWM : public CMiniDexed, public CPWMSoundBaseDevice |
||||||
{ |
{ |
||||||
public: |
public: |
||||||
CMiniDexedPWM(uint8_t max_notes, uint16_t sample_rate, CInterruptSystem *pInterrupt) |
CMiniDexedPWM (CConfig *pConfig, CInterruptSystem *pInterrupt); |
||||||
: CMiniDexed(max_notes,(int)sample_rate, pInterrupt), |
|
||||||
CPWMSoundBaseDevice (pInterrupt, sample_rate, CHUNK_SIZE) |
bool Initialize (void); |
||||||
{ |
|
||||||
} |
unsigned GetChunk (u32 *pBuffer, unsigned nChunkSize); |
||||||
|
|
||||||
bool Initialize (void); |
|
||||||
unsigned GetChunk (u32 *pBuffer, unsigned nChunkSize); |
|
||||||
}; |
}; |
||||||
|
|
||||||
|
//// I2S //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class CMiniDexedI2S : public CMiniDexed, public CI2SSoundBaseDevice |
class CMiniDexedI2S : public CMiniDexed, public CI2SSoundBaseDevice |
||||||
{ |
{ |
||||||
public: |
public: |
||||||
CMiniDexedI2S(uint8_t max_notes, uint16_t sample_rate, CInterruptSystem *pInterrupt, CI2CMaster *pI2CMaster) |
CMiniDexedI2S (CConfig *pConfig, CInterruptSystem *pInterrupt, |
||||||
: CMiniDexed(max_notes,(int)sample_rate, pInterrupt), |
CI2CMaster *pI2CMaster); |
||||||
CI2SSoundBaseDevice (pInterrupt, sample_rate, CHUNK_SIZE, FALSE, pI2CMaster, DAC_I2C_ADDRESS) |
|
||||||
{ |
bool Initialize (void); |
||||||
} |
|
||||||
|
unsigned GetChunk (u32 *pBuffer, unsigned nChunkSize); |
||||||
bool Initialize (void); |
|
||||||
unsigned GetChunk (u32 *pBuffer, unsigned nChunkSize); |
|
||||||
}; |
}; |
||||||
|
|
||||||
|
//// HDMI /////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class CMiniDexedHDMI : public CMiniDexed, public CHDMISoundBaseDevice |
class CMiniDexedHDMI : public CMiniDexed, public CHDMISoundBaseDevice |
||||||
{ |
{ |
||||||
public: |
public: |
||||||
CMiniDexedHDMI(uint8_t max_notes, uint16_t sample_rate, CInterruptSystem *pInterrupt) |
CMiniDexedHDMI (CConfig *pConfig, CInterruptSystem *pInterrupt); |
||||||
: CMiniDexed(max_notes,(int)sample_rate, pInterrupt), |
|
||||||
CHDMISoundBaseDevice (pInterrupt, sample_rate, CHUNK_SIZE_HDMI) |
bool Initialize (void); |
||||||
{ |
|
||||||
} |
unsigned GetChunk (u32 *pBuffer, unsigned nChunkSize); |
||||||
|
|
||||||
bool Initialize (void); |
|
||||||
unsigned GetChunk (u32 *pBuffer, unsigned nChunkSize); |
|
||||||
}; |
}; |
||||||
|
|
||||||
#endif |
#endif |
||||||
|
@ -0,0 +1,26 @@ |
|||||||
|
# |
||||||
|
# minidexed.ini |
||||||
|
# |
||||||
|
|
||||||
|
# Sound device |
||||||
|
SoundDevice=pwm |
||||||
|
SampleRate=48000 |
||||||
|
#ChunkSize=256 |
||||||
|
DACI2CAddress=0 |
||||||
|
|
||||||
|
# MIDI |
||||||
|
MIDIBaudRate=31250 |
||||||
|
|
||||||
|
# HD44780 LCD |
||||||
|
LCDEnabled=1 |
||||||
|
LCDPinEnable=17 |
||||||
|
LCDPinRegisterSelect=18 |
||||||
|
LCDPinReadWrite=19 |
||||||
|
LCDPinData4=22 |
||||||
|
LCDPinData5=23 |
||||||
|
LCDPinData6=24 |
||||||
|
LCDPinData7=25 |
||||||
|
|
||||||
|
# Debug |
||||||
|
MIDIDumpEnabled=1 |
||||||
|
ProfileEnabled=1 |
@ -0,0 +1,98 @@ |
|||||||
|
//
|
||||||
|
// serialmididevice.cpp
|
||||||
|
//
|
||||||
|
// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi
|
||||||
|
// Copyright (C) 2022 The MiniDexed Team
|
||||||
|
//
|
||||||
|
// Original author of this class:
|
||||||
|
// R. Stange <rsta2@o2online.de>
|
||||||
|
//
|
||||||
|
// 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 "serialmididevice.h" |
||||||
|
#include <assert.h> |
||||||
|
|
||||||
|
CSerialMIDIDevice::CSerialMIDIDevice (CMiniDexed *pSynthesizer, CInterruptSystem *pInterrupt, |
||||||
|
CConfig *pConfig) |
||||||
|
: CMIDIDevice (pSynthesizer, pConfig), |
||||||
|
m_pConfig (pConfig), |
||||||
|
m_Serial (pInterrupt, TRUE), |
||||||
|
m_nSerialState (0) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
CSerialMIDIDevice::~CSerialMIDIDevice (void) |
||||||
|
{ |
||||||
|
m_nSerialState = 255; |
||||||
|
} |
||||||
|
|
||||||
|
boolean CSerialMIDIDevice::Initialize (void) |
||||||
|
{ |
||||||
|
assert (m_pConfig); |
||||||
|
return m_Serial.Initialize (m_pConfig->GetMIDIBaudRate ()); |
||||||
|
} |
||||||
|
|
||||||
|
void CSerialMIDIDevice::Process (void) |
||||||
|
{ |
||||||
|
// Read serial MIDI data
|
||||||
|
u8 Buffer[100]; |
||||||
|
int nResult = m_Serial.Read (Buffer, sizeof Buffer); |
||||||
|
if (nResult <= 0) |
||||||
|
{ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// Process MIDI messages
|
||||||
|
// See: https://www.midi.org/specifications/item/table-1-summary-of-midi-message
|
||||||
|
for (int i = 0; i < nResult; i++) |
||||||
|
{ |
||||||
|
u8 uchData = Buffer[i]; |
||||||
|
|
||||||
|
switch (m_nSerialState) |
||||||
|
{ |
||||||
|
case 0: |
||||||
|
MIDIRestart: |
||||||
|
if ( (uchData & 0x80) == 0x80 // status byte, all channels
|
||||||
|
&& (uchData & 0xF0) != 0xF0) // ignore system messages
|
||||||
|
{ |
||||||
|
m_SerialMessage[m_nSerialState++] = uchData; |
||||||
|
} |
||||||
|
break; |
||||||
|
|
||||||
|
case 1: |
||||||
|
case 2: |
||||||
|
if (uchData & 0x80) // got status when parameter expected
|
||||||
|
{ |
||||||
|
m_nSerialState = 0; |
||||||
|
|
||||||
|
goto MIDIRestart; |
||||||
|
} |
||||||
|
|
||||||
|
m_SerialMessage[m_nSerialState++] = uchData; |
||||||
|
|
||||||
|
if ( (m_SerialMessage[0] & 0xE0) == 0xC0 |
||||||
|
|| m_nSerialState == 3) // message is complete
|
||||||
|
{ |
||||||
|
MIDIMessageHandler (m_SerialMessage, m_nSerialState); |
||||||
|
|
||||||
|
m_nSerialState = 0; |
||||||
|
} |
||||||
|
break; |
||||||
|
|
||||||
|
default: |
||||||
|
assert (0); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,52 @@ |
|||||||
|
//
|
||||||
|
// serialmididevice.h
|
||||||
|
//
|
||||||
|
// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi
|
||||||
|
// Copyright (C) 2022 The MiniDexed Team
|
||||||
|
//
|
||||||
|
// Original author of this class:
|
||||||
|
// R. Stange <rsta2@o2online.de>
|
||||||
|
//
|
||||||
|
// 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 _serialmididevice_h |
||||||
|
#define _serialmididevice_h |
||||||
|
|
||||||
|
#include "mididevice.h" |
||||||
|
#include "config.h" |
||||||
|
#include <circle/interrupt.h> |
||||||
|
#include <circle/serial.h> |
||||||
|
#include <circle/types.h> |
||||||
|
|
||||||
|
class CMiniDexed; |
||||||
|
|
||||||
|
class CSerialMIDIDevice : public CMIDIDevice |
||||||
|
{ |
||||||
|
public: |
||||||
|
CSerialMIDIDevice (CMiniDexed *pSynthesizer, CInterruptSystem *pInterrupt, CConfig *pConfig); |
||||||
|
~CSerialMIDIDevice (void); |
||||||
|
|
||||||
|
boolean Initialize (void); |
||||||
|
|
||||||
|
void Process (void); |
||||||
|
|
||||||
|
private: |
||||||
|
CConfig *m_pConfig; |
||||||
|
|
||||||
|
CSerialDevice m_Serial; |
||||||
|
unsigned m_nSerialState; |
||||||
|
u8 m_SerialMessage[3]; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif |
@ -0,0 +1,107 @@ |
|||||||
|
//
|
||||||
|
// userinterface.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 "userinterface.h" |
||||||
|
#include "minidexed.h" |
||||||
|
#include <circle/logger.h> |
||||||
|
#include <circle/string.h> |
||||||
|
#include <stdio.h> |
||||||
|
#include <string.h> |
||||||
|
#include <assert.h> |
||||||
|
|
||||||
|
LOGMODULE ("ui"); |
||||||
|
|
||||||
|
CUserInterface::CUserInterface (CMiniDexed *pMiniDexed, CConfig *pConfig) |
||||||
|
: m_pMiniDexed (pMiniDexed), |
||||||
|
m_pConfig (pConfig), |
||||||
|
m_pLCD (0), |
||||||
|
m_pLCDBuffered (0) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
CUserInterface::~CUserInterface (void) |
||||||
|
{ |
||||||
|
delete m_pLCDBuffered; |
||||||
|
delete m_pLCD; |
||||||
|
} |
||||||
|
|
||||||
|
bool CUserInterface::Initialize (void) |
||||||
|
{ |
||||||
|
assert (m_pConfig); |
||||||
|
|
||||||
|
if (m_pConfig->GetLCDEnabled ()) |
||||||
|
{ |
||||||
|
m_pLCD = new CHD44780Device (CConfig::LCDColumns, CConfig::LCDRows, |
||||||
|
m_pConfig->GetLCDPinData4 (), |
||||||
|
m_pConfig->GetLCDPinData5 (), |
||||||
|
m_pConfig->GetLCDPinData6 (), |
||||||
|
m_pConfig->GetLCDPinData7 (), |
||||||
|
m_pConfig->GetLCDPinEnable (), |
||||||
|
m_pConfig->GetLCDPinRegisterSelect (), |
||||||
|
m_pConfig->GetLCDPinReadWrite ()); |
||||||
|
assert (m_pLCD); |
||||||
|
|
||||||
|
if (!m_pLCD->Initialize ()) |
||||||
|
{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
m_pLCDBuffered = new CWriteBufferDevice (m_pLCD); |
||||||
|
assert (m_pLCDBuffered); |
||||||
|
|
||||||
|
LCDWrite ("\x1B[?25l"); // cursor off
|
||||||
|
|
||||||
|
LOGDBG ("LCD initialized"); |
||||||
|
} |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
void CUserInterface::Process (void) |
||||||
|
{ |
||||||
|
if (m_pLCDBuffered) |
||||||
|
{ |
||||||
|
m_pLCDBuffered->Update (); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void CUserInterface::ProgramChanged (unsigned nProgram) |
||||||
|
{ |
||||||
|
nProgram++; // MIDI numbering starts with 0, user interface with 1
|
||||||
|
|
||||||
|
// fetch program name from Dexed instance
|
||||||
|
char ProgramName[11]; |
||||||
|
memset (ProgramName, 0, sizeof ProgramName); |
||||||
|
assert (m_pMiniDexed); |
||||||
|
m_pMiniDexed->setName (ProgramName); |
||||||
|
|
||||||
|
printf ("Loading voice %u: \"%s\"\n", nProgram, ProgramName); |
||||||
|
|
||||||
|
CString String; |
||||||
|
String.Format ("\n\r%u\n\r%s", nProgram, ProgramName); |
||||||
|
LCDWrite (String); |
||||||
|
} |
||||||
|
|
||||||
|
void CUserInterface::LCDWrite (const char *pString) |
||||||
|
{ |
||||||
|
if (m_pLCDBuffered) |
||||||
|
{ |
||||||
|
m_pLCDBuffered->Write (pString, strlen (pString)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,52 @@ |
|||||||
|
//
|
||||||
|
// userinterface.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 _userinterface_h |
||||||
|
#define _userinterface_h |
||||||
|
|
||||||
|
#include "config.h" |
||||||
|
#include <display/hd44780device.h> |
||||||
|
#include <circle/writebuffer.h> |
||||||
|
|
||||||
|
class CMiniDexed; |
||||||
|
|
||||||
|
class CUserInterface |
||||||
|
{ |
||||||
|
public: |
||||||
|
CUserInterface (CMiniDexed *pMiniDexed, CConfig *pConfig); |
||||||
|
~CUserInterface (void); |
||||||
|
|
||||||
|
bool Initialize (void); |
||||||
|
|
||||||
|
void Process (void); |
||||||
|
|
||||||
|
void ProgramChanged (unsigned nProgram); // 0 .. 127
|
||||||
|
|
||||||
|
private: |
||||||
|
void LCDWrite (const char *pString); // Print to optional HD44780 display
|
||||||
|
|
||||||
|
private: |
||||||
|
CMiniDexed *m_pMiniDexed; |
||||||
|
CConfig *m_pConfig; |
||||||
|
|
||||||
|
CHD44780Device *m_pLCD; |
||||||
|
CWriteBufferDevice *m_pLCDBuffered; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif |
Loading…
Reference in new issue