From 363c28710fa5a8376e0e8f3b7c93eec821b49c6a Mon Sep 17 00:00:00 2001
From: probonopd <probonopd@users.noreply.github.com>
Date: Tue, 26 Apr 2022 08:34:44 +0200
Subject: [PATCH 1/4] Reinstate MIDI_CC_DETUNE_LEVEL (#171)

Accidentally got reverted
https://github.com/probonopd/MiniDexed/pull/150#issuecomment-1108599164
---
 src/mididevice.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/mididevice.cpp b/src/mididevice.cpp
index 837d8e9..47f3f11 100644
--- a/src/mididevice.cpp
+++ b/src/mididevice.cpp
@@ -208,7 +208,15 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign
 					break;
 
 				case MIDI_CC_DETUNE_LEVEL:
-					m_pSynthesizer->SetMasterTune (maplong (pMessage[2], 0, 127, -99, 99), nTG);
+					if (pMessage[2] == 0)
+					{
+						// "0 to 127, with 0 being no celeste (detune) effect applied at all."
+						m_pSynthesizer->SetMasterTune (0, nTG);
+					}
+					else
+					{
+						m_pSynthesizer->SetMasterTune (maplong (pMessage[2], 1, 127, -99, 99), nTG);
+					}
 					break;
 
 				case MIDI_CC_ALL_SOUND_OFF:

From 42a79dc6998660777a94ffd4b26a8db9a9e9b87e Mon Sep 17 00:00:00 2001
From: probonopd <probonopd@users.noreply.github.com>
Date: Tue, 26 Apr 2022 22:33:43 +0200
Subject: [PATCH 2/4] getsysex.sh

[ci skip]
---
 README.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index c85b061..1b7d27c 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@ MiniDexed is a FM synthesizer closely modeled on the famous DX7 by a well-known
 - [x] Runs on all Raspberry Pi models (except Pico); see below for details
 - [x] Produces sound on the headphone jack, HDMI display or [audio extractor](https://github.com/probonopd/MiniDexed/wiki/Hardware#hdmi-to-audio) (better), or a [dedicated DAC](https://github.com/probonopd/MiniDexed/wiki/Hardware#i2c-dac) (best)
 - [x] Supports multiple voices through Program Change and Bank Change LSB/MSB MIDI messages
-- [x] Loads `.syx` files from SD card (e.g., using `getsysex.sh` or from [Dexed_cart_1.0.zip](http://hsjp.eu/downloads/Dexed/Dexed_cart_1.0.zip))
+- [x] Loads voices from `.syx` files from SD card (e.g., using `getsysex.sh` or from [Dexed_cart_1.0.zip](http://hsjp.eu/downloads/Dexed/Dexed_cart_1.0.zip))
 - [x] Menu structure on optional [HD44780 display](https://www.berrybase.de/sensoren-module/displays/alphanumerische-displays/alphanumerisches-lcd-16x2-gr-252-n/gelb) and rotary encoder
 - [x] Runs up to 8 Dexed instances simultaneously (like in a TX816) and mixes their output together
 - [x] Allows for each Dexed instance to be detuned and stereo shifted
@@ -45,6 +45,7 @@ Video about this project by [Floyd Steinberg](https://www.youtube.com/watch?v=Z3
 * Boot
 * Start playing
 * If the system seems to become unresponsive after a few seconds, remove `usbspeed=full` from `cmdline.txt` and repeat ([details](https://github.com/probonopd/MiniDexed/issues/39))
+* Optionally, put voices in `.syx` files onto the SD card (e.g., using `getsysex.sh`)
 * See the Wiki for [Menu](https://github.com/probonopd/MiniDexed/wiki/Menu) operation
 * If something is unclear or does not work, don't hesitate to [ask](https://github.com/probonopd/MiniDexed/discussions/)!
 

From 0721b608f9fecce6c371feebaf261f975a725b07 Mon Sep 17 00:00:00 2001
From: probonopd <probonopd@users.noreply.github.com>
Date: Tue, 26 Apr 2022 23:16:18 +0200
Subject: [PATCH 3/4] adafruit

[ci skip]
---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 1b7d27c..ac78dea 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
 
 ![minidexed](https://user-images.githubusercontent.com/2480569/161813414-bb156a1c-efec-44c0-802a-8926412a08e0.jpg)
 
-MiniDexed is a FM synthesizer closely modeled on the famous DX7 by a well-known Japanese manufacturer running on a bare metal Raspberry Pi (without a Linux kernel or operating system). On Raspberry Pi 2 and larger, it can run 8 tone generators, not unlike the TX816/TX802 (8 DX7 instances without the keyboard in one box). [Featured on HACKADAY](https://hackaday.com/2022/04/19/bare-metal-gives-this-pi-some-classic-synths/).
+MiniDexed is a FM synthesizer closely modeled on the famous DX7 by a well-known Japanese manufacturer running on a bare metal Raspberry Pi (without a Linux kernel or operating system). On Raspberry Pi 2 and larger, it can run 8 tone generators, not unlike the TX816/TX802 (8 DX7 instances without the keyboard in one box). [Featured by HACKADAY](https://hackaday.com/2022/04/19/bare-metal-gives-this-pi-some-classic-synths/) and [adafruit](https://blog.adafruit.com/2022/04/25/free-yamaha-dx7-synth-emulator-on-a-raspberry-pi/).
 
 ## Features
 

From 4850c3a19dc919cae6681379cc4228159a13f755 Mon Sep 17 00:00:00 2001
From: probonopd <probonopd@users.noreply.github.com>
Date: Sat, 30 Apr 2022 22:45:34 +0200
Subject: [PATCH 4/4] Support Running Status MIDI messages (#194)

Reference: https://www.lim.di.unimi.it/IEEE/MIDI/SOT5.HTM#Running-

https://github.com/probonopd/MiniDexed/discussions/170#discussioncomment-2663922
Thanks @arsamus
---
 src/serialmididevice.cpp | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/serialmididevice.cpp b/src/serialmididevice.cpp
index 2c11a33..b03dfad 100644
--- a/src/serialmididevice.cpp
+++ b/src/serialmididevice.cpp
@@ -59,6 +59,8 @@ void CSerialMIDIDevice::Process (void)
 
 	// Process MIDI messages
 	// See: https://www.midi.org/specifications/item/table-1-summary-of-midi-message
+	// "Running status" see: https://www.lim.di.unimi.it/IEEE/MIDI/SOT5.HTM#Running-	
+	
 	for (int i = 0; i < nResult; i++)
 	{
 		u8 uchData = Buffer[i];
@@ -76,6 +78,7 @@ void CSerialMIDIDevice::Process (void)
 
 		case 1:
 		case 2:
+		DATABytes:
 			if (uchData & 0x80)			// got status when parameter expected
 			{
 				m_nSerialState = 0;
@@ -90,7 +93,20 @@ void CSerialMIDIDevice::Process (void)
 			{
 				MIDIMessageHandler (m_SerialMessage, m_nSerialState);
 
+				m_nSerialState = 4; // State 4 for test if 4th byte is a status byte or a data byte 
+			}
+			break;
+		case 4:
+			
+			if ((uchData & 0x80) == 0)  // true data byte, false status byte
+			{
+				m_nSerialState = 1;
+				goto DATABytes;
+			}
+			else 
+			{
 				m_nSerialState = 0;
+				goto MIDIRestart; 
 			}
 			break;