From ac681b452db1b1372be2874c64ff852c3f9391fe Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sat, 5 Jan 2019 12:33:42 +0100 Subject: [PATCH] Added I2rCS LCD library. Added parts of additional MIDI ports - not readyyet. --- LiquidCrystalPlus_I2C.h | 88 +++++++++++++++++++++++++++++++++++++++++ MicroMDAPiano.ino | 49 +++++++++++++++++++++-- config.h | 4 +- 3 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 LiquidCrystalPlus_I2C.h diff --git a/LiquidCrystalPlus_I2C.h b/LiquidCrystalPlus_I2C.h new file mode 100644 index 0000000..38be128 --- /dev/null +++ b/LiquidCrystalPlus_I2C.h @@ -0,0 +1,88 @@ +/* + MicroDexed + + MicroDexed is a port of the Dexed sound engine + (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield. + Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android + + (c)2018 H. Wirtz + + 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include // https://www.arduinolibraries.info/libraries/liquid-crystal-i2-c + +#ifndef LIQUIDCRYSTALPLUS_I2C_H_INCLUDED +#define LIQUIDCRYSTALPLUS_I2C_H_INCLUDED + +#define STRING_BUF_SIZE 21 + +class LiquidCrystalPlus_I2C : public LiquidCrystal_I2C +{ + public: + + using LiquidCrystal_I2C::LiquidCrystal_I2C; + + void show(uint8_t y, uint8_t x, uint8_t fs, char *str) + { + _show(y, x, fs, str, false, false); + } + + void show(uint8_t y, uint8_t x, uint8_t fs, long num) + { + char _buf10[STRING_BUF_SIZE]; + + _show(y, x, fs, itoa(num, _buf10, 10), true, true); + } + + private: + void _show(uint8_t pos_y, uint8_t pos_x, uint8_t field_size, char *str, bool justify_right, bool fill_zero) + { + { + char tmp[STRING_BUF_SIZE]; + char *s = tmp; + uint8_t l = strlen(str); + + memset(tmp, 0, sizeof(tmp)); + if (fill_zero == true) + memset(tmp, '0', field_size); + else + memset(tmp, 0x20, field_size - 1); // blank + + if (l > field_size) + l = field_size; + + if (justify_right == true) + s += field_size - l; + + strncpy(s, str, l); + + setCursor(pos_x, pos_y); + print(tmp); + +#ifdef DEBUG + Serial.print(pos_y, DEC); + Serial.print(F("/")); + Serial.print(pos_x, DEC); + Serial.print(F(": [")); + Serial.print(tmp); + Serial.println(F("]")); +#endif + } + } +}; + +#endif diff --git a/MicroMDAPiano.ino b/MicroMDAPiano.ino index 7030950..3eaf2d2 100644 --- a/MicroMDAPiano.ino +++ b/MicroMDAPiano.ino @@ -1,3 +1,28 @@ +/* + MicroMDAEPiano + + MicroDexed is a port of the Dexed sound engine + (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield. + Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android + + (c)2018 H. Wirtz + + 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "config.h" #include #include #include @@ -7,14 +32,16 @@ #include #include "mdaEPiano.h" #include "mdaEPianoData.h" -#include "config.h" +#if defined(USBCON) +#include +#endif #ifdef USE_ONBOARD_USB_HOST #include #endif #ifndef MASTER_KEY_MIDI // selecting sounds by encoder, button and display #include #include -#include +#include "LiquidCrystalPlus_I2C.h" #endif #ifndef MASTER_KEY_MIDI @@ -82,6 +109,12 @@ MIDI_CREATE_INSTANCE(HardwareSerial, MIDI_DEVICE, midi_serial); USBHost usb_host; MIDIDevice midi_usb(usb_host); #endif +#if defined(USBCON) +static const unsigned sUsbTransportBufferSize = 16; +typedef midi::UsbTransport UsbTransport; +UsbTransport sUsbTransport; +MIDI_CREATE_INSTANCE(UsbTransport, sUsbTransport, midi_onboard_usb); +#endif #ifdef TEST_NOTE IntervalTimer sched_note_on; @@ -102,8 +135,8 @@ void setup() lcd.noAutoscroll(); lcd.clear(); lcd.display(); - lcd.show(0, 0, 20, "MicroDexed"); - + lcd.show(0, 0, 20, "MicroMDAEPiano"); + lcd.show(1, 0, 16, "(c)parasiTstudio"); enc1.write(INITIAL_ENC1_VALUE); #endif @@ -123,11 +156,19 @@ void setup() // start up USB host #ifdef USE_ONBOARD_USB_HOST usb_host.begin(); + Serial.println(F("USB-MIDI enabled.")); +#endif + + // check for onboard USB-MIDI +#if defined(USBCON) + midi_onboard_usb.begin(); + Serial.println(F("Onboard USB-MIDI enabled.")); #endif #ifdef MIDI_DEVICE // Start serial MIDI midi_serial.begin(DEFAULT_MIDI_CHANNEL); + Serial.println(F("Serial MIDI enabled")); #endif // start audio card diff --git a/config.h b/config.h index 2272d58..6b23591 100644 --- a/config.h +++ b/config.h @@ -44,9 +44,11 @@ #else #define NVOICES 16 // Yes #endif +#define USBCON 1 // enabling onboard MIDI via programing connector +#define MIDI_MERGE_THRU 1 // Master key handling (comment for disabling) -#define MASTER_KEY_MIDI MIDI_C7 +//#define MASTER_KEY_MIDI MIDI_C7 #define MASTER_NUM1 MIDI_C2 // Debug output