first commit

This commit is contained in:
stuce-bot 2025-06-30 20:47:33 +02:00
commit 5893b00dd2
1669 changed files with 1982740 additions and 0 deletions

View file

@ -0,0 +1,179 @@
// Copyleft (c) 2012, Zach Vorhies
// Public domain, no rights reserved.
// This object holds a frame buffer and effects can be applied. This is a higher level
// object than the TCL class which this object uses for drawing.
//#include "./tcl.h"
#include <Arduino.h>
#include "../shared/color.h"
#include "../shared/framebuffer.h"
#include "../shared/settings.h"
#include "./LedRopeTCL.h"
#include "../shared/led_layout_array.h"
#include "FastLED.h"
#include "fl/dbg.h"
#include "fl/ui.h"
using namespace fl;
#define CHIPSET WS2812
#define PIN_DATA 1
#define PIN_CLOCK 2
namespace {
UIButton buttonAllWhite("All white");
ScreenMap init_screenmap() {
LedColumns cols = LedLayoutArray();
const int length = cols.length;
int sum = 0;
for (int i = 0; i < length; ++i) {
sum += cols.array[i];
}
ScreenMap screen_map(sum, 0.8f);
int curr_idx = 0;
for (int i = 0; i < length; ++i) {
int n = cols.array[i];
int stagger = i % 2 ? 4 : 0;
for (int j = 0; j < n; ++j) {
fl::vec2f xy(i*4, j*8 + stagger);
screen_map.set(curr_idx++, xy);
}
}
return screen_map;
}
}
///////////////////////////////////////////////////////////////////////////////
void LedRopeTCL::PreDrawSetup() {
if (!lazy_initialized_) {
// This used to do something, now it does nothing.
lazy_initialized_ = true;
}
}
///////////////////////////////////////////////////////////////////////////////
void LedRopeTCL::RawBeginDraw() {
PreDrawSetup();
led_buffer_.clear();
}
///////////////////////////////////////////////////////////////////////////////
void LedRopeTCL::RawDrawPixel(const Color3i& c) {
RawDrawPixel(c.r_, c.g_, c.b_);
}
///////////////////////////////////////////////////////////////////////////////
void LedRopeTCL::RawDrawPixel(byte r, byte g, byte b) {
if (led_buffer_.size() >= mScreenMap.getLength()) {
return;
}
if (buttonAllWhite.isPressed()) {
r = 0xff;
g = 0xff;
b = 0xff;
}
CRGB c(r, g, b);
led_buffer_.push_back(CRGB(r, g, b));
}
///////////////////////////////////////////////////////////////////////////////
void LedRopeTCL::RawDrawPixels(const Color3i& c, int n) {
for (int i = 0; i < n; ++i) {
RawDrawPixel(c);
}
}
///////////////////////////////////////////////////////////////////////////////
void LedRopeTCL::set_draw_offset(int val) {
draw_offset_ = constrain(val, 0, frame_buffer_.length());
}
///////////////////////////////////////////////////////////////////////////////
void LedRopeTCL::RawCommitDraw() {
FASTLED_WARN("\n\n############## COMMIT DRAW ################\n\n");
if (!controller_added_) {
controller_added_ = true;
CRGB* leds = led_buffer_.data();
size_t n_leds = led_buffer_.size();
FastLED.addLeds<APA102, PIN_DATA, PIN_CLOCK>(leds, n_leds).setScreenMap(mScreenMap);
}
FASTLED_WARN("FastLED.show");
FastLED.show();
}
///////////////////////////////////////////////////////////////////////////////
LedRopeTCL::LedRopeTCL(int n_pixels)
: draw_offset_(0), lazy_initialized_(false), frame_buffer_(n_pixels) {
mScreenMap = init_screenmap();
led_buffer_.reserve(mScreenMap.getLength());
}
///////////////////////////////////////////////////////////////////////////////
LedRopeTCL::~LedRopeTCL() {
}
///////////////////////////////////////////////////////////////////////////////
void LedRopeTCL::Draw() {
RawBeginDraw();
const Color3i* begin = GetIterator(0);
const Color3i* middle = GetIterator(draw_offset_);
const Color3i* end = GetIterator(length() - 1);
for (const Color3i* it = middle; it != end; ++it) {
RawDrawPixel(*it);
}
for (const Color3i* it = begin; it != middle; ++it) {
RawDrawPixel(*it);
}
RawCommitDraw();
}
///////////////////////////////////////////////////////////////////////////////
void LedRopeTCL::DrawSequentialRepeat(int repeat) {
RawBeginDraw();
const Color3i* begin = GetIterator(0);
const Color3i* middle = GetIterator(draw_offset_);
const Color3i* end = GetIterator(length());
for (const Color3i* it = middle; it != end; ++it) {
for (int i = 0; i < repeat; ++i) {
RawDrawPixel(it->r_, it->g_, it->b_);
}
}
for (const Color3i* it = begin; it != middle; ++it) {
for (int i = 0; i < repeat; ++i) {
RawDrawPixel(it->r_, it->g_, it->b_);
}
}
RawCommitDraw();
}
///////////////////////////////////////////////////////////////////////////////
void LedRopeTCL::DrawRepeat(const int* value_array, int array_length) {
RawBeginDraw();
// Make sure that the number of colors to repeat does not exceed the length
// of the rope.
const int len = MIN(array_length, frame_buffer_.length());
for (int i = 0; i < len; ++i) {
const Color3i* cur_color = GetIterator(i); // Current color.
const int repeat_count = value_array[i];
// Repeatedly send the same color down the led rope.
for (int k = 0; k < repeat_count; ++k) {
RawDrawPixel(cur_color->r_, cur_color->g_, cur_color->b_);
}
}
// Finish the drawing.
RawCommitDraw();
}

View file

@ -0,0 +1,81 @@
// Copyleft (c) 2012, Zach Vorhies
// Public domain, no rights reserved.
// This object holds a frame buffer and effects can be applied. This is a higher level
// object than the TCL class which this object uses for drawing.
#ifndef LED_REPE_TCL_H_
#define LED_REPE_TCL_H_
#include <Arduino.h>
#include "../shared/color.h"
#include "../shared/framebuffer.h"
#include "../shared/led_rope_interface.h"
#include "fl/vector.h"
#include "crgb.h"
#include "fl/screenmap.h"
using namespace fl;
// LedRopeTCL is a C++ wrapper around the Total Control Lighting LED rope
// device driver (TCL.h). This wrapper includes automatic setup of the LED
// rope and allows the user to use a graphics-state like interface for
// talking to the rope. A copy of the rope led state is held in this class
// which makes blending operations easier. After all changes by the user
// are applied to the rope, the hardware is updated via an explicit Draw()
// command.
//
// Whole-rope blink Example:
// #include <SPI.h>
// #include <TCL.h> // From CoolNeon (https://bitbucket.org/devries/arduino-tcl)
// #include "LedRopeTCL.h"
// LedRopeTCL led_rope(100); // 100 led-strand.
//
// void setup() {} // No setup necessary for Led rope.
// void loop() {
// led_rope.FillColor(LedRopeTCL::Color3i::Black());
// led_rope.Draw();
// delay(1000);
// led_rope.FillColor(LedRopeTCL::Color3i::White());
// led_rope.Draw();
// delay(1000);
// }
class LedRopeTCL : public LedRopeInterface {
public:
LedRopeTCL(int n_pixels);
virtual ~LedRopeTCL();
void Draw();
void DrawSequentialRepeat(int repeat);
void DrawRepeat(const int* value_array, int array_length);
void set_draw_offset(int val);
virtual void Set(int i, const Color3i& c) {
frame_buffer_.Set(i, c);
}
Color3i* GetIterator(int i) {
return frame_buffer_.GetIterator(i);
}
int length() const { return frame_buffer_.length(); }
void RawBeginDraw();
void RawDrawPixel(const Color3i& c);
void RawDrawPixels(const Color3i& c, int n);
void RawDrawPixel(uint8_t r, uint8_t g, uint8_t b);
void RawCommitDraw();
protected:
void PreDrawSetup();
int draw_offset_ = 0;
bool lazy_initialized_;
FrameBuffer frame_buffer_;
bool controller_added_ = false;
fl::HeapVector<CRGB> led_buffer_;
fl::ScreenMap mScreenMap;
};
#endif // LED_REPE_TCL_H_

View file

@ -0,0 +1,115 @@
/*!
* @file MIDI.cpp
* Project Arduino MIDI Library
* @brief MIDI Library for the Arduino
* @author Francois Best
* @date 24/02/11
* @license MIT - Copyright (c) 2015 Francois Best
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "MIDI.h"
// -----------------------------------------------------------------------------
BEGIN_MIDI_NAMESPACE
/*! \brief Encode System Exclusive messages.
SysEx messages are encoded to guarantee transmission of data bytes higher than
127 without breaking the MIDI protocol. Use this static method to convert the
data you want to send.
\param inData The data to encode.
\param outSysEx The output buffer where to store the encoded message.
\param inLength The length of the input buffer.
\param inFlipHeaderBits True for Korg and other who store MSB in reverse order
\return The length of the encoded output buffer.
@see decodeSysEx
Code inspired from Ruin & Wesen's SysEx encoder/decoder - http://ruinwesen.com
*/
unsigned encodeSysEx(const byte* inData,
byte* outSysEx,
unsigned inLength,
bool inFlipHeaderBits)
{
unsigned outLength = 0; // Num bytes in output array.
byte count = 0; // Num 7bytes in a block.
outSysEx[0] = 0;
for (unsigned i = 0; i < inLength; ++i)
{
const byte data = inData[i];
const byte msb = data >> 7;
const byte body = data & 0x7f;
outSysEx[0] |= (msb << (inFlipHeaderBits ? count : (6 - count)));
outSysEx[1 + count] = body;
if (count++ == 6)
{
outSysEx += 8;
outLength += 8;
outSysEx[0] = 0;
count = 0;
}
}
return outLength + count + (count != 0 ? 1 : 0);
}
/*! \brief Decode System Exclusive messages.
SysEx messages are encoded to guarantee transmission of data bytes higher than
127 without breaking the MIDI protocol. Use this static method to reassemble
your received message.
\param inSysEx The SysEx data received from MIDI in.
\param outData The output buffer where to store the decrypted message.
\param inLength The length of the input buffer.
\param inFlipHeaderBits True for Korg and other who store MSB in reverse order
\return The length of the output buffer.
@see encodeSysEx @see getSysExArrayLength
Code inspired from Ruin & Wesen's SysEx encoder/decoder - http://ruinwesen.com
*/
unsigned decodeSysEx(const byte* inSysEx,
byte* outData,
unsigned inLength,
bool inFlipHeaderBits)
{
unsigned count = 0;
byte msbStorage = 0;
byte byteIndex = 0;
for (unsigned i = 0; i < inLength; ++i)
{
if ((i % 8) == 0)
{
msbStorage = inSysEx[i];
byteIndex = 6;
}
else
{
const byte body = inSysEx[i];
const byte shift = inFlipHeaderBits ? 6 - byteIndex : byteIndex;
const byte msb = byte(((msbStorage >> shift) & 1) << 7);
byteIndex--;
outData[count++] = msb | body;
}
}
return count;
}
END_MIDI_NAMESPACE

View file

@ -0,0 +1,308 @@
/*!
* @file MIDI.h
* Project Arduino MIDI Library
* @brief MIDI Library for the Arduino
* @author Francois Best, lathoub
* @date 24/02/11
* @license MIT - Copyright (c) 2015 Francois Best
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "midi_Defs.h"
#include "midi_Platform.h"
#include "midi_Settings.h"
#include "midi_Message.h"
#include "serialMIDI.h"
// -----------------------------------------------------------------------------
BEGIN_MIDI_NAMESPACE
#define MIDI_LIBRARY_VERSION 0x050000
#define MIDI_LIBRARY_VERSION_MAJOR 5
#define MIDI_LIBRARY_VERSION_MINOR 0
#define MIDI_LIBRARY_VERSION_PATCH 0
/*! \brief The main class for MIDI handling.
It is templated over the type of serial port to provide abstraction from
the hardware interface, meaning you can use HardwareSerial, SoftwareSerial
or ak47's Uart classes. The only requirement is that the class implements
the begin, read, write and available methods.
*/
template<class Transport, class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
class MidiInterface
{
public:
typedef _Settings Settings;
typedef _Platform Platform;
typedef Message<Settings::SysExMaxSize> MidiMessage;
public:
inline MidiInterface(Transport&);
inline ~MidiInterface();
public:
void begin(Channel inChannel = 1);
// -------------------------------------------------------------------------
// MIDI Output
public:
inline void sendNoteOn(DataByte inNoteNumber,
DataByte inVelocity,
Channel inChannel);
inline void sendNoteOff(DataByte inNoteNumber,
DataByte inVelocity,
Channel inChannel);
inline void sendProgramChange(DataByte inProgramNumber,
Channel inChannel);
inline void sendControlChange(DataByte inControlNumber,
DataByte inControlValue,
Channel inChannel);
inline void sendPitchBend(int inPitchValue, Channel inChannel);
inline void sendPitchBend(double inPitchValue, Channel inChannel);
inline void sendPolyPressure(DataByte inNoteNumber,
DataByte inPressure,
Channel inChannel) __attribute__ ((deprecated));
inline void sendAfterTouch(DataByte inPressure,
Channel inChannel);
inline void sendAfterTouch(DataByte inNoteNumber,
DataByte inPressure,
Channel inChannel);
inline void sendSysEx(unsigned inLength,
const byte* inArray,
bool inArrayContainsBoundaries = false);
inline void sendTimeCodeQuarterFrame(DataByte inTypeNibble,
DataByte inValuesNibble);
inline void sendTimeCodeQuarterFrame(DataByte inData);
inline void sendSongPosition(unsigned inBeats);
inline void sendSongSelect(DataByte inSongNumber);
inline void sendTuneRequest();
inline void sendCommon(MidiType inType, unsigned = 0);
inline void sendClock() { sendRealTime(Clock); };
inline void sendStart() { sendRealTime(Start); };
inline void sendStop() { sendRealTime(Stop); };
inline void sendTick() { sendRealTime(Tick); };
inline void sendContinue() { sendRealTime(Continue); };
inline void sendActiveSensing() { sendRealTime(ActiveSensing); };
inline void sendSystemReset() { sendRealTime(SystemReset); };
inline void sendRealTime(MidiType inType);
inline void beginRpn(unsigned inNumber,
Channel inChannel);
inline void sendRpnValue(unsigned inValue,
Channel inChannel);
inline void sendRpnValue(byte inMsb,
byte inLsb,
Channel inChannel);
inline void sendRpnIncrement(byte inAmount,
Channel inChannel);
inline void sendRpnDecrement(byte inAmount,
Channel inChannel);
inline void endRpn(Channel inChannel);
inline void beginNrpn(unsigned inNumber,
Channel inChannel);
inline void sendNrpnValue(unsigned inValue,
Channel inChannel);
inline void sendNrpnValue(byte inMsb,
byte inLsb,
Channel inChannel);
inline void sendNrpnIncrement(byte inAmount,
Channel inChannel);
inline void sendNrpnDecrement(byte inAmount,
Channel inChannel);
inline void endNrpn(Channel inChannel);
inline void send(const MidiMessage&);
public:
void send(MidiType inType,
DataByte inData1,
DataByte inData2,
Channel inChannel);
// -------------------------------------------------------------------------
// MIDI Input
public:
inline bool read();
inline bool read(Channel inChannel);
public:
inline MidiType getType() const;
inline Channel getChannel() const;
inline DataByte getData1() const;
inline DataByte getData2() const;
inline const byte* getSysExArray() const;
inline unsigned getSysExArrayLength() const;
inline bool check() const;
public:
inline Channel getInputChannel() const;
inline void setInputChannel(Channel inChannel);
public:
static inline MidiType getTypeFromStatusByte(byte inStatus);
static inline Channel getChannelFromStatusByte(byte inStatus);
static inline bool isChannelMessage(MidiType inType);
// -------------------------------------------------------------------------
// Input Callbacks
public:
inline void setHandleMessage(void (*fptr)(const MidiMessage&)) { mMessageCallback = fptr; };
inline void setHandleError(ErrorCallback fptr) { mErrorCallback = fptr; }
inline void setHandleNoteOff(NoteOffCallback fptr) { mNoteOffCallback = fptr; }
inline void setHandleNoteOn(NoteOnCallback fptr) { mNoteOnCallback = fptr; }
inline void setHandleAfterTouchPoly(AfterTouchPolyCallback fptr) { mAfterTouchPolyCallback = fptr; }
inline void setHandleControlChange(ControlChangeCallback fptr) { mControlChangeCallback = fptr; }
inline void setHandleProgramChange(ProgramChangeCallback fptr) { mProgramChangeCallback = fptr; }
inline void setHandleAfterTouchChannel(AfterTouchChannelCallback fptr) { mAfterTouchChannelCallback = fptr; }
inline void setHandlePitchBend(PitchBendCallback fptr) { mPitchBendCallback = fptr; }
inline void setHandleSystemExclusive(SystemExclusiveCallback fptr) { mSystemExclusiveCallback = fptr; }
inline void setHandleTimeCodeQuarterFrame(TimeCodeQuarterFrameCallback fptr) { mTimeCodeQuarterFrameCallback = fptr; }
inline void setHandleSongPosition(SongPositionCallback fptr) { mSongPositionCallback = fptr; }
inline void setHandleSongSelect(SongSelectCallback fptr) { mSongSelectCallback = fptr; }
inline void setHandleTuneRequest(TuneRequestCallback fptr) { mTuneRequestCallback = fptr; }
inline void setHandleClock(ClockCallback fptr) { mClockCallback = fptr; }
inline void setHandleStart(StartCallback fptr) { mStartCallback = fptr; }
inline void setHandleTick(TickCallback fptr) { mTickCallback = fptr; }
inline void setHandleContinue(ContinueCallback fptr) { mContinueCallback = fptr; }
inline void setHandleStop(StopCallback fptr) { mStopCallback = fptr; }
inline void setHandleActiveSensing(ActiveSensingCallback fptr) { mActiveSensingCallback = fptr; }
inline void setHandleSystemReset(SystemResetCallback fptr) { mSystemResetCallback = fptr; }
inline void disconnectCallbackFromType(MidiType inType);
private:
void launchCallback();
void (*mMessageCallback)(const MidiMessage& message) = nullptr;
ErrorCallback mErrorCallback = nullptr;
NoteOffCallback mNoteOffCallback = nullptr;
NoteOnCallback mNoteOnCallback = nullptr;
AfterTouchPolyCallback mAfterTouchPolyCallback = nullptr;
ControlChangeCallback mControlChangeCallback = nullptr;
ProgramChangeCallback mProgramChangeCallback = nullptr;
AfterTouchChannelCallback mAfterTouchChannelCallback = nullptr;
PitchBendCallback mPitchBendCallback = nullptr;
SystemExclusiveCallback mSystemExclusiveCallback = nullptr;
TimeCodeQuarterFrameCallback mTimeCodeQuarterFrameCallback = nullptr;
SongPositionCallback mSongPositionCallback = nullptr;
SongSelectCallback mSongSelectCallback = nullptr;
TuneRequestCallback mTuneRequestCallback = nullptr;
ClockCallback mClockCallback = nullptr;
StartCallback mStartCallback = nullptr;
TickCallback mTickCallback = nullptr;
ContinueCallback mContinueCallback = nullptr;
StopCallback mStopCallback = nullptr;
ActiveSensingCallback mActiveSensingCallback = nullptr;
SystemResetCallback mSystemResetCallback = nullptr;
// -------------------------------------------------------------------------
// MIDI Soft Thru
public:
inline Thru::Mode getFilterMode() const;
inline bool getThruState() const;
inline void turnThruOn(Thru::Mode inThruFilterMode = Thru::Full);
inline void turnThruOff();
inline void setThruFilterMode(Thru::Mode inThruFilterMode);
private:
void thruFilter(byte inChannel);
// -------------------------------------------------------------------------
// MIDI Parsing
private:
bool parse();
inline void handleNullVelocityNoteOnAsNoteOff();
inline bool inputFilter(Channel inChannel);
inline void resetInput();
inline void UpdateLastSentTime();
// -------------------------------------------------------------------------
// Transport
public:
Transport* getTransport() { return &mTransport; };
private:
Transport& mTransport;
// -------------------------------------------------------------------------
// Internal variables
private:
Channel mInputChannel;
StatusByte mRunningStatus_RX;
StatusByte mRunningStatus_TX;
byte mPendingMessage[3];
unsigned mPendingMessageExpectedLength;
unsigned mPendingMessageIndex;
unsigned mCurrentRpnNumber;
unsigned mCurrentNrpnNumber;
bool mThruActivated : 1;
Thru::Mode mThruFilterMode : 7;
MidiMessage mMessage;
unsigned long mLastMessageSentTime;
unsigned long mLastMessageReceivedTime;
unsigned long mSenderActiveSensingPeriodicity;
bool mReceiverActiveSensingActivated;
int8_t mLastError;
private:
inline StatusByte getStatus(MidiType inType,
Channel inChannel) const;
};
// -----------------------------------------------------------------------------
unsigned encodeSysEx(const byte* inData,
byte* outSysEx,
unsigned inLength,
bool inFlipHeaderBits = false);
unsigned decodeSysEx(const byte* inSysEx,
byte* outData,
unsigned inLength,
bool inFlipHeaderBits = false);
END_MIDI_NAMESPACE
#include "MIDI.hpp"

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,157 @@
#pragma once
#include <Arduino.h>
#include "fl/ui.h"
#include "fl/dbg.h"
using namespace fl;
// Done by hand. Old school.
class ToggleButton {
public:
ToggleButton(int pin) : pin_(pin), on_(false), debounce_timestamp_(0), changed_(false) {
pinMode(pin_, OUTPUT);
digitalWrite(pin_, LOW);
delay(1);
}
// true - button is pressed.
bool Read() {
Update(millis());
return changed_;
}
void Update(uint32_t time_now) {
if ((time_now - debounce_timestamp_) < 150) {
changed_ = false;
return;
}
int val = Read_Internal();
changed_ = on_ != val;
if (changed_) { // Has the toggle switch changed?
on_ = val; // Set the new toggle switch value.
// Protect against debouncing artifacts by putting a 200ms delay from the
// last time the value changed.
if ((time_now - debounce_timestamp_) > 150) {
//++curr_val_; // ... and increment the value.
debounce_timestamp_ = time_now;
}
}
}
private:
bool Read_Internal() {
// Toggle the pin back to INPUT and take a reading.
pinMode(pin_, INPUT);
bool on = (digitalRead(pin_) == HIGH);
// Switch the pin back to output so that we can enable the
// pulldown resister.
pinMode(pin_, OUTPUT);
digitalWrite(pin_, LOW);
return on;
}
int pin_;
bool on_;
uint32_t debounce_timestamp_;
bool changed_;
};
// This is the new type that is built into the midi shield.
class MidiShieldButton {
public:
MidiShieldButton(int pin) : pin_(pin) {
pinMode(pin_, INPUT_PULLUP);
delay(1);
}
bool Read() {
// Toggle the pin back to INPUT and take a reading.
int val = digitalRead(pin_) == LOW;
return val;
}
private:
int pin_;
};
class Potentiometer {
public:
Potentiometer(int sensor_pin) : sensor_pin_(sensor_pin) {}
float Read() {
float avg = 0.0;
// Filter by reading the value multiple times and taking
// the average.
for (int i = 0; i < 8; ++i) {
avg += analogRead(sensor_pin_);
}
avg = avg / 8.0f;
return avg;
}
private:
int sensor_pin_;
};
typedef MidiShieldButton DigitalButton;
class CountingButton {
public:
explicit CountingButton(int but_pin) : button_(but_pin), curr_val_(0), mButton("Counting UIButton") {
debounce_timestamp_ = millis();
on_ = Read();
}
void Update(uint32_t time_now) {
bool clicked = mButton.clicked();
bool val = Read() || mButton.clicked();
bool changed = val != on_;
if (clicked) {
++curr_val_;
debounce_timestamp_ = time_now;
return;
}
if (changed) { // Has the toggle switch changed?
on_ = val; // Set the new toggle switch value.
// Protect against debouncing artifacts by putting a 200ms delay from the
// last time the value changed.
if ((time_now - debounce_timestamp_) > 16) {
if (on_) {
++curr_val_; // ... and increment the value.
}
debounce_timestamp_ = time_now;
}
}
}
int curr_val() const { return curr_val_; }
private:
bool Read() {
return button_.Read();
}
DigitalButton button_;
bool on_;
int curr_val_;
unsigned long debounce_timestamp_;
UIButton mButton;
};
class ColorSelector {
public:
ColorSelector(int sensor_pin) : but_(sensor_pin) {}
void Update() {
but_.Update(millis());
}
int curr_val() const { return but_.curr_val() % 7; }
private:
CountingButton but_;
};

View file

@ -0,0 +1,232 @@
/*!
* @file midi_Defs.h
* Project Arduino MIDI Library
* @brief MIDI Library for the Arduino - Definitions
* @author Francois Best, lathoub
* @date 24/02/11
* @license MIT - Copyright (c) 2015 Francois Best
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "midi_Namespace.h"
#if ARDUINO
#include <Arduino.h>
#else
#include <inttypes.h>
typedef uint8_t byte;
#endif
BEGIN_MIDI_NAMESPACE
// -----------------------------------------------------------------------------
#define MIDI_CHANNEL_OMNI 0
#define MIDI_CHANNEL_OFF 17 // and over
#define MIDI_PITCHBEND_MIN -8192
#define MIDI_PITCHBEND_MAX 8191
/*! Receiving Active Sensing
*/
static const uint16_t ActiveSensingTimeout = 300;
// -----------------------------------------------------------------------------
// Type definitions
typedef byte StatusByte;
typedef byte DataByte;
typedef byte Channel;
typedef byte FilterMode;
// -----------------------------------------------------------------------------
// Errors
static const uint8_t ErrorParse = 0;
static const uint8_t ErrorActiveSensingTimeout = 1;
static const uint8_t WarningSplitSysEx = 2;
// -----------------------------------------------------------------------------
// Aliasing
using ErrorCallback = void (*)(int8_t);
using NoteOffCallback = void (*)(Channel channel, byte note, byte velocity);
using NoteOnCallback = void (*)(Channel channel, byte note, byte velocity);
using AfterTouchPolyCallback = void (*)(Channel channel, byte note, byte velocity);
using ControlChangeCallback = void (*)(Channel channel, byte, byte);
using ProgramChangeCallback = void (*)(Channel channel, byte);
using AfterTouchChannelCallback = void (*)(Channel channel, byte);
using PitchBendCallback = void (*)(Channel channel, int);
using SystemExclusiveCallback = void (*)(byte * array, unsigned size);
using TimeCodeQuarterFrameCallback = void (*)(byte data);
using SongPositionCallback = void (*)(unsigned beats);
using SongSelectCallback = void (*)(byte songnumber);
using TuneRequestCallback = void (*)(void);
using ClockCallback = void (*)(void);
using StartCallback = void (*)(void);
using TickCallback = void (*)(void);
using ContinueCallback = void (*)(void);
using StopCallback = void (*)(void);
using ActiveSensingCallback = void (*)(void);
using SystemResetCallback = void (*)(void);
// -----------------------------------------------------------------------------
/*! Enumeration of MIDI types */
enum MidiType: uint8_t
{
InvalidType = 0x00, ///< For notifying errors
NoteOff = 0x80, ///< Channel Message - Note Off
NoteOn = 0x90, ///< Channel Message - Note On
AfterTouchPoly = 0xA0, ///< Channel Message - Polyphonic AfterTouch
ControlChange = 0xB0, ///< Channel Message - Control Change / Channel Mode
ProgramChange = 0xC0, ///< Channel Message - Program Change
AfterTouchChannel = 0xD0, ///< Channel Message - Channel (monophonic) AfterTouch
PitchBend = 0xE0, ///< Channel Message - Pitch Bend
SystemExclusive = 0xF0, ///< System Exclusive
SystemExclusiveStart = SystemExclusive, ///< System Exclusive Start
TimeCodeQuarterFrame = 0xF1, ///< System Common - MIDI Time Code Quarter Frame
SongPosition = 0xF2, ///< System Common - Song Position Pointer
SongSelect = 0xF3, ///< System Common - Song Select
Undefined_F4 = 0xF4,
Undefined_F5 = 0xF5,
TuneRequest = 0xF6, ///< System Common - Tune Request
SystemExclusiveEnd = 0xF7, ///< System Exclusive End
Clock = 0xF8, ///< System Real Time - Timing Clock
Undefined_F9 = 0xF9,
Tick = Undefined_F9, ///< System Real Time - Timing Tick (1 tick = 10 milliseconds)
Start = 0xFA, ///< System Real Time - Start
Continue = 0xFB, ///< System Real Time - Continue
Stop = 0xFC, ///< System Real Time - Stop
Undefined_FD = 0xFD,
ActiveSensing = 0xFE, ///< System Real Time - Active Sensing
SystemReset = 0xFF, ///< System Real Time - System Reset
};
// -----------------------------------------------------------------------------
/*! Enumeration of Thru filter modes */
struct Thru
{
enum Mode
{
Off = 0, ///< Thru disabled (nothing passes through).
Full = 1, ///< Fully enabled Thru (every incoming message is sent back).
SameChannel = 2, ///< Only the messages on the Input Channel will be sent back.
DifferentChannel = 3, ///< All the messages but the ones on the Input Channel will be sent back.
};
};
// -----------------------------------------------------------------------------
/*! \brief Enumeration of Control Change command numbers.
See the detailed controllers numbers & description here:
http://www.somascape.org/midi/tech/spec.html#ctrlnums
*/
enum MidiControlChangeNumber: uint8_t
{
// High resolution Continuous Controllers MSB (+32 for LSB) ----------------
BankSelect = 0,
ModulationWheel = 1,
BreathController = 2,
// CC3 undefined
FootController = 4,
PortamentoTime = 5,
DataEntryMSB = 6,
ChannelVolume = 7,
Balance = 8,
// CC9 undefined
Pan = 10,
ExpressionController = 11,
EffectControl1 = 12,
EffectControl2 = 13,
// CC14 undefined
// CC15 undefined
GeneralPurposeController1 = 16,
GeneralPurposeController2 = 17,
GeneralPurposeController3 = 18,
GeneralPurposeController4 = 19,
DataEntryLSB = 38,
// Switches ----------------------------------------------------------------
Sustain = 64,
Portamento = 65,
Sostenuto = 66,
SoftPedal = 67,
Legato = 68,
Hold = 69,
// Low resolution continuous controllers -----------------------------------
SoundController1 = 70, ///< Synth: Sound Variation FX: Exciter On/Off
SoundController2 = 71, ///< Synth: Harmonic Content FX: Compressor On/Off
SoundController3 = 72, ///< Synth: Release Time FX: Distortion On/Off
SoundController4 = 73, ///< Synth: Attack Time FX: EQ On/Off
SoundController5 = 74, ///< Synth: Brightness FX: Expander On/Off
SoundController6 = 75, ///< Synth: Decay Time FX: Reverb On/Off
SoundController7 = 76, ///< Synth: Vibrato Rate FX: Delay On/Off
SoundController8 = 77, ///< Synth: Vibrato Depth FX: Pitch Transpose On/Off
SoundController9 = 78, ///< Synth: Vibrato Delay FX: Flange/Chorus On/Off
SoundController10 = 79, ///< Synth: Undefined FX: Special Effects On/Off
GeneralPurposeController5 = 80,
GeneralPurposeController6 = 81,
GeneralPurposeController7 = 82,
GeneralPurposeController8 = 83,
PortamentoControl = 84,
// CC85 to CC90 undefined
Effects1 = 91, ///< Reverb send level
Effects2 = 92, ///< Tremolo depth
Effects3 = 93, ///< Chorus send level
Effects4 = 94, ///< Celeste depth
Effects5 = 95, ///< Phaser depth
DataIncrement = 96,
DataDecrement = 97,
NRPNLSB = 98, ///< Non-Registered Parameter Number (LSB)
NRPNMSB = 99, ///< Non-Registered Parameter Number (MSB)
RPNLSB = 100, ///< Registered Parameter Number (LSB)
RPNMSB = 101, ///< Registered Parameter Number (MSB)
// Channel Mode messages ---------------------------------------------------
AllSoundOff = 120,
ResetAllControllers = 121,
LocalControl = 122,
AllNotesOff = 123,
OmniModeOff = 124,
OmniModeOn = 125,
MonoModeOn = 126,
PolyModeOn = 127
};
struct RPN
{
enum RegisteredParameterNumbers: uint16_t
{
PitchBendSensitivity = 0x0000,
ChannelFineTuning = 0x0001,
ChannelCoarseTuning = 0x0002,
SelectTuningProgram = 0x0003,
SelectTuningBank = 0x0004,
ModulationDepthRange = 0x0005,
NullFunction = (0x7f << 7) + 0x7f,
};
};
END_MIDI_NAMESPACE

View file

@ -0,0 +1,105 @@
/*!
* @file midi_Message.h
* Project Arduino MIDI Library
* @brief MIDI Library for the Arduino - Message struct definition
* @author Francois Best
* @date 11/06/14
* @license MIT - Copyright (c) 2015 Francois Best
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "midi_Namespace.h"
#include "midi_Defs.h"
#ifndef ARDUINO
#include <string.h>
#endif
BEGIN_MIDI_NAMESPACE
/*! The Message structure contains decoded data of a MIDI message
read from the serial port with read()
*/
template<unsigned SysExMaxSize>
struct Message
{
/*! Default constructor
\n Initializes the attributes with their default values.
*/
inline Message()
: channel(0)
, type(MIDI_NAMESPACE::InvalidType)
, data1(0)
, data2(0)
, valid(false)
{
memset(sysexArray, 0, sSysExMaxSize * sizeof(DataByte));
}
/*! The maximum size for the System Exclusive array.
*/
static const unsigned sSysExMaxSize = SysExMaxSize;
/*! The MIDI channel on which the message was recieved.
\n Value goes from 1 to 16.
*/
Channel channel;
/*! The type of the message
(see the MidiType enum for types reference)
*/
MidiType type;
/*! The first data byte.
\n Value goes from 0 to 127.
*/
DataByte data1;
/*! The second data byte.
If the message is only 2 bytes long, this one is null.
\n Value goes from 0 to 127.
*/
DataByte data2;
/*! System Exclusive dedicated byte array.
\n Array length is stocked on 16 bits,
in data1 (LSB) and data2 (MSB)
*/
DataByte sysexArray[sSysExMaxSize];
/*! This boolean indicates if the message is valid or not.
There is no channel consideration here,
validity means the message respects the MIDI norm.
*/
bool valid;
/*! Total Length of the message.
*/
unsigned length;
inline unsigned getSysExSize() const
{
const unsigned size = unsigned(data2) << 8 | data1;
return size > sSysExMaxSize ? sSysExMaxSize : size;
}
};
END_MIDI_NAMESPACE

View file

@ -0,0 +1,38 @@
/*!
* @file midi_Namespace.h
* Project Arduino MIDI Library
* @brief MIDI Library for the Arduino - Namespace declaration
* @author Francois Best
* @date 24/02/11
* @license MIT - Copyright (c) 2015 Francois Best
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#define MIDI_NAMESPACE midi
#define BEGIN_MIDI_NAMESPACE namespace MIDI_NAMESPACE {
#define END_MIDI_NAMESPACE }
#define USING_NAMESPACE_MIDI using namespace MIDI_NAMESPACE;
BEGIN_MIDI_NAMESPACE
END_MIDI_NAMESPACE

View file

@ -0,0 +1,51 @@
/*!
* @file midi_Platform.h
* Project Arduino MIDI Library
* @brief MIDI Library for the Arduino - Platform
* @license MIT - Copyright (c) 2015 Francois Best
* @author lathoub
* @date 22/03/20
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "midi_Defs.h"
BEGIN_MIDI_NAMESPACE
#if ARDUINO
// DefaultPlatform is the Arduino Platform
struct DefaultPlatform
{
static unsigned long now() { return ::millis(); };
};
#else
struct DefaultPlatform
{
static unsigned long now() { return 0; };
};
#endif
END_MIDI_NAMESPACE

View file

@ -0,0 +1,104 @@
/*!
* @file midi_Settings.h
* Project Arduino MIDI Library
* @brief MIDI Library for the Arduino - Settings
* @author Francois Best
* @date 24/02/11
* @license MIT - Copyright (c) 2015 Francois Best
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "midi_Defs.h"
BEGIN_MIDI_NAMESPACE
/*! \brief Default Settings for the MIDI Library.
To change the default settings, don't edit them there, create a subclass and
override the values in that subclass, then use the MIDI_CREATE_CUSTOM_INSTANCE
macro to create your instance. The settings you don't override will keep their
default value. Eg:
\code{.cpp}
struct MySettings : public midi::DefaultSettings
{
static const unsigned SysExMaxSize = 1024; // Accept SysEx messages up to 1024 bytes long.
};
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial2, midi, MySettings);
\endcode
*/
struct DefaultSettings
{
/*! Running status enables short messages when sending multiple values
of the same type and channel.\n
Must be disabled to send USB MIDI messages to a computer
Warning: does not work with some hardware, enable with caution.
*/
static const bool UseRunningStatus = false;
/*! NoteOn with 0 velocity should be handled as NoteOf.\n
Set to true to get NoteOff events when receiving null-velocity NoteOn messages.\n
Set to false to get NoteOn events when receiving null-velocity NoteOn messages.
*/
static const bool HandleNullVelocityNoteOnAsNoteOff = true;
/*! Setting this to true will make MIDI.read parse only one byte of data for each
call when data is available. This can speed up your application if receiving
a lot of traffic, but might induce MIDI Thru and treatment latency.
*/
static const bool Use1ByteParsing = true;
/*! Maximum size of SysEx receivable. Decrease to save RAM if you don't expect
to receive SysEx, or adjust accordingly.
*/
static const unsigned SysExMaxSize = 128;
/*! Global switch to turn on/off sender ActiveSensing
Set to true to send ActiveSensing
Set to false will not send ActiveSensing message (will also save memory)
*/
static const bool UseSenderActiveSensing = false;
/*! Global switch to turn on/off receiver ActiveSensing
Set to true to check for message timeouts (via ErrorCallback)
Set to false will not check if chained device are still alive (if they use ActiveSensing) (will also save memory)
*/
static const bool UseReceiverActiveSensing = false;
/*! Active Sensing is intended to be sent
repeatedly by the sender to tell the receiver that a connection is alive. Use
of this message is optional. When initially received, the
receiver will expect to receive another Active Sensing
message each 300ms (max), and if it does not then it will
assume that the connection has been terminated. At
termination, the receiver will turn off all voices and return to
normal (non- active sensing) operation.
Typical value is 250 (ms) - an Active Sensing command is send every 250ms.
(All Roland devices send Active Sensing every 250ms)
Setting this field to 0 will disable sending MIDI active sensing.
*/
static const uint16_t SenderActiveSensingPeriodicity = 0;
};
END_MIDI_NAMESPACE

View file

@ -0,0 +1,125 @@
/*!
* @file serialMIDI.h
* Project Arduino MIDI Library
* @brief MIDI Library for the Arduino - Platform
* @license MIT - Copyright (c) 2015 Francois Best
* @author lathoub, Francois Best
* @date 22/03/20
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "midi_Namespace.h"
BEGIN_MIDI_NAMESPACE
struct DefaultSerialSettings
{
/*! Override the default MIDI baudrate to transmit over USB serial, to
a decoding program such as Hairless MIDI (set baudrate to 115200)\n
http://projectgus.github.io/hairless-midiserial/
*/
static const long BaudRate = 31250;
};
template <class SerialPort, class _Settings = DefaultSerialSettings>
class SerialMIDI
{
typedef _Settings Settings;
public:
SerialMIDI(SerialPort& inSerial)
: mSerial(inSerial)
{
};
public:
static const bool thruActivated = true;
void begin()
{
// Initialise the Serial port
#if defined(AVR_CAKE)
mSerial. template open<Settings::BaudRate>();
#else
mSerial.begin(Settings::BaudRate);
#endif
}
bool beginTransmission(MidiType)
{
return true;
};
void write(byte value)
{
mSerial.write(value);
};
void endTransmission()
{
};
byte read()
{
return mSerial.read();
};
unsigned available()
{
return mSerial.available();
};
private:
SerialPort& mSerial;
};
/*! \brief Create an instance of the library attached to a serial port.
You can use HardwareSerial or SoftwareSerial for the serial port.
Example: MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, midi2);
Then call midi2.begin(), midi2.read() etc..
*/
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \
MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
#if defined(ARDUINO_SAM_DUE) || defined(USBCON) || defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
// Leonardo, Due and other USB boards use Serial1 by default.
#define MIDI_CREATE_DEFAULT_INSTANCE() \
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
#else
/*! \brief Create an instance of the library with default name, serial port
and settings, for compatibility with sketches written with pre-v4.2 MIDI Lib,
or if you don't bother using custom names, serial port or settings.
*/
#define MIDI_CREATE_DEFAULT_INSTANCE() \
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI);
#endif
/*! \brief Create an instance of the library attached to a serial port with
custom settings.
@see DefaultSettings
@see MIDI_CREATE_INSTANCE
*/
#define MIDI_CREATE_CUSTOM_INSTANCE(Type, SerialPort, Name, Settings) \
MIDI_NAMESPACE::SerialMIDI<Type, Settings> serial##Name(SerialPort);\
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type, Settings>> Name((MIDI_NAMESPACE::SerialMIDI<Type, Settings>&)serial##Name);
END_MIDI_NAMESPACE

View file

@ -0,0 +1,84 @@
#include "../shared/defs.h"
#if ENABLE_SKETCH
#include "./ui_state.h"
#include "shared/Painter.h"
#include "fl/dbg.h"
#include <Arduino.h>
//#define UI_V1 // Based off the old midi shield with hand assmebled buttons.
#define UI_V2 // Based on a new midi shield with buttons. https://learn.sparkfun.com/tutorials/midi-shield-hookup-guide
#define UI_DBG
#ifdef __STM32F1__
// Missing A-type pins, just use digital pins mapped to analog.
#define PIN_POT_COLOR_SENSOR D3
#define PIN_POT_VEL_SENSOR D4
#else
#define PIN_POT_COLOR_SENSOR A3
#define PIN_POT_VEL_SENSOR A4
#endif
#define PIN_VIS_SELECT 2
#define PIN_COLOR_SELECT 4
Potentiometer velocity_pot(PIN_POT_VEL_SENSOR);
Potentiometer color_pot(PIN_POT_COLOR_SENSOR);
float read_color_selector() {
return color_pot.Read();
}
float read_velocity_bias() {
return velocity_pot.Read();
}
//DigitalButton custom_notecolor_select(4);
ColorSelector color_selector(PIN_COLOR_SELECT);
CountingButton vis_selector(PIN_VIS_SELECT);
void ui_init() {
}
ui_state ui_update(uint32_t now_ms, uint32_t delta_ms) {
ui_state out;
vis_selector.Update(now_ms);
color_selector.Update();
int32_t curr_val = vis_selector.curr_val();
FASTLED_DBG("curr_val: " << curr_val);
out.color_scheme = color_selector.curr_val();
//bool notecolor_on = custom_notecolor_select.Read();
//Serial.print("color selector: "); Serial.println(out.color_scheme);
//float velocity = read_velocity_bias();
//float color_selector = read_color_selector();
//Serial.print("velocity: "); Serial.print(velocity); Serial.print(", color_selector: "); Serial.print(color_selector);
//if (notecolor_on) {
// Serial.print(", notecolor_on: "); Serial.print(notecolor_on);
//}
//Serial.print("color_scheme: "); Serial.print(out.color_scheme); Serial.print(", vis selector: "); Serial.print(curr_val);
//Serial.println("");
//Serial.print("curr_val: "); Serial.print(curr_val);// Serial.print(", button state: "); Serial.println(vis_selector.button_.curr_val());;
out.which_visualizer = static_cast<Painter::VisState>(curr_val % Painter::kNumVisStates);
return out;
}
#endif // ENABLE_SKETCH

View file

@ -0,0 +1,21 @@
#pragma once
#include <Arduino.h>
#include "buttons.h"
extern ColorSelector color_selector;
extern CountingButton vis_selector;
struct ui_state {
ui_state() { memset(this, 0, sizeof(*this)); }
int which_visualizer;
int color_scheme;
//float color_wheel_pos;
//float velocity_bias_pos; // default to 1.0f for buttons missing velocity.
};
void ui_init();
ui_state ui_update(uint32_t now_ms, uint32_t delta_ms);