Skip to content

Commit

Permalink
v0.3.1 added new library event types
Browse files Browse the repository at this point in the history
  • Loading branch information
neroroxxx committed Oct 13, 2020
1 parent 4453fa8 commit 138397a
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 10 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=BMC
version=0.3.0
version=0.3.1
author=Nero Rox
maintainer=Nero Rox <info@roxxxtar.com>
sentence=Fully featured MIDI Controller Library with a Companion Editor App. For Teensy
Expand Down
2 changes: 1 addition & 1 deletion src/BMC-Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// BMC Version stored in EEPROM (for editor usage)
#define BMC_VERSION_MAJ 0
#define BMC_VERSION_MIN 3
#define BMC_VERSION_PATCH 0
#define BMC_VERSION_PATCH 1

//16 bits unsigned, LSB byte is minor, MSB byte is major
#define BMC_VERSION ((BMC_VERSION_MAJ<<8) | BMC_VERSION_MIN)
Expand Down
18 changes: 18 additions & 0 deletions src/BMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,24 @@ void BMC::update(){
#endif
#endif

#if BMC_MAX_LIBRARY > 0
if(library.changeAvailable()){
#if BMC_MAX_PAGES > 1
if(library.pageChanged()){
setPage(library.getPageChange());
}
#endif
if(library.bpmChanged()){
midiClock.setBpm(library.getBpmChange());
}
#if BMC_MAX_PIXEL_PROGRAMS > 0
if(library.pixelProgramChanged()){
pixelPrograms.setProgram(library.getPixelProgramChange());
}
#endif
}
#endif

//
#ifdef BMC_USE_CLICK_TRACK
// this is only used if the editor is connected, tells the editor app
Expand Down
5 changes: 5 additions & 0 deletions src/BMC.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@
#endif

// Includes
// main definitions for BMC
#include "utility/BMC-Def.h"
// the MIDI I/O object
#include "midi/BMC-Midi.h"
// the MIDI clock master/slave handler
#include "midi/BMC-MidiClock.h"
// the MIDI Active Sense master/slave handler
#include "midi/BMC-MidiActiveSense.h"
// the Editor MIDI I/O and EEPROM handler
#include "editor/BMC-Editor.h"

#if defined(BMC_USE_FAS)
Expand Down
7 changes: 5 additions & 2 deletions src/midi/BMC-MidiClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ class BMCMidiClock {
// set a flat that a beat has accured (24 PPQN)
flags.on(BMC_MIDI_CLOCK_FLAG_BEAT);
// check if the timer is active and has reached the 1000ms
if(bpmSetTimer.complete()){
// 250ms have passed since the last time the tempo changed
// also check if the BPM has changed, we'll store the previous bpm
// in tmpBpm
if(bpmSetTimer.complete() && tmpBpm!=bpm){
tmpBpm = bpm;
// 100ms have passed since the last time the tempo changed
// now callbacks can be triggered
BMC_PRINTLN("NEW BPM",bpm,"Received");
flags.on(BMC_MIDI_CLOCK_FLAG_BPM_CHANGED);
Expand Down
68 changes: 64 additions & 4 deletions src/utility/BMC-Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
#include "utility/BMC-CustomSysEx.h"
#endif

#define BMC_LIBRARY_FLAG_CHANGE_AVAILABLE 0
#define BMC_LIBRARY_FLAG_SET_PAGE 1
#define BMC_LIBRARY_FLAG_SET_BPM 2
#define BMC_LIBRARY_FLAG_SET_PIXEL_PROGRAM 3

class BMCLibrary {
public:
#if BMC_MAX_CUSTOM_SYSEX > 0
Expand All @@ -59,26 +64,51 @@ class BMCLibrary {
#endif
void send(bmcLibrary_t index){
uint8_t status = (global.library[index].event & 0xFF);
if(index < BMC_MAX_LIBRARY && status>0x7F){
if(status<0xF0){
if(index < BMC_MAX_LIBRARY){
if(status>127 && status<0xF0){
midi.send(global.library[index].event);
} else if(status>=0xF0 && status<=0xF2){
#if BMC_MAX_CUSTOM_SYSEX > 0
uint8_t ports = BMC_GET_BYTE(3, global.library[index].event);
sendCustomSysEx(index, status, ports);
#endif
} else if(status==1){// page
page = BMC_GET_BYTE(1, global.library[index].event);
flags.on(BMC_LIBRARY_FLAG_SET_PAGE);
flags.on(BMC_LIBRARY_FLAG_CHANGE_AVAILABLE);
} else if(status==2){// bmp
bpm = mergeDataBytes(global.library[index].event);
flags.on(BMC_LIBRARY_FLAG_SET_BPM);
flags.on(BMC_LIBRARY_FLAG_CHANGE_AVAILABLE);
} else if(status==3){// bmp
pixelProgram = BMC_GET_BYTE(1, global.library[index].event);
flags.on(BMC_LIBRARY_FLAG_SET_PIXEL_PROGRAM);
flags.on(BMC_LIBRARY_FLAG_CHANGE_AVAILABLE);
}

}
}
void sendWithDifferentPorts(bmcLibrary_t index, uint8_t ports){
uint8_t status = (global.library[index].event & 0xFF);
if(index < BMC_MAX_LIBRARY && status > 0x7F){
if(status<0xF0){
if(index < BMC_MAX_LIBRARY){
if(status>127 && status<0xF0){
midi.send((global.library[index].event & 0xFFFFFF) | ports<<24);
} else if(status>=0xF0 && status<=0xF2){
#if BMC_MAX_CUSTOM_SYSEX > 0
sendCustomSysEx(index, status, ports);
#endif
} else if(status==1){// page
page = BMC_GET_BYTE(1, global.library[index].event);
flags.on(BMC_LIBRARY_FLAG_SET_PAGE);
flags.on(BMC_LIBRARY_FLAG_CHANGE_AVAILABLE);
} else if(status==2){// bmp
bpm = mergeDataBytes(global.library[index].event);
flags.on(BMC_LIBRARY_FLAG_SET_BPM);
flags.on(BMC_LIBRARY_FLAG_CHANGE_AVAILABLE);
} else if(status==3){// bmp
pixelProgram = BMC_GET_BYTE(1, global.library[index].event);
flags.on(BMC_LIBRARY_FLAG_SET_PIXEL_PROGRAM);
flags.on(BMC_LIBRARY_FLAG_CHANGE_AVAILABLE);
}
}
}
Expand All @@ -91,6 +121,27 @@ class BMCLibrary {
send(index2);
send(index3);
}
bool changeAvailable(){
return flags.toggleIfTrue(BMC_LIBRARY_FLAG_CHANGE_AVAILABLE);
}
bool pageChanged(){
return flags.toggleIfTrue(BMC_LIBRARY_FLAG_SET_PAGE);
}
uint8_t getPageChange(){
return page;
}
bool bpmChanged(){
return flags.toggleIfTrue(BMC_LIBRARY_FLAG_SET_BPM);
}
uint16_t getBpmChange(){
return bpm;
}
bool pixelProgramChanged(){
return flags.toggleIfTrue(BMC_LIBRARY_FLAG_SET_PIXEL_PROGRAM);
}
uint8_t getPixelProgramChange(){
return pixelProgram;
}

// these are here to make it easier to access a library message from the outside
uint32_t getEvent(bmcLibrary_t n){
Expand Down Expand Up @@ -152,6 +203,15 @@ class BMCLibrary {
// reference to midi object from BMC
BMCMidi& midi;
bmcStoreGlobal& global;
BMCFlags <uint8_t> flags;
uint8_t page = 0;
uint8_t pixelProgram = 0;
uint16_t bpm = 0;

uint16_t mergeDataBytes(uint32_t t_event){
uint16_t b = (t_event>>8) & 0xFFFF;
return (BMC_GET_BYTE(0, b) & 0x7F) | ((BMC_GET_BYTE(1, b) & 0x7F)<<7);
}

#if BMC_MAX_CUSTOM_SYSEX > 0
BMCCustomSysEx& customSysEx;
Expand Down
4 changes: 2 additions & 2 deletions src/utility/BMC-Structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ struct BMCMidiEvent {
}
void setEvent(uint8_t port=0, uint8_t status=0, uint8_t channel=0, uint8_t data1=0, uint8_t data2=0){
// don't mask data2 to 7 bits since we can allow for 128 as a value to toggle
if(status<0xF0){
if(status>127 && status<0xF0){
status = ((status & 0xF0) | (channel & 0x0F));
}
event = BMC_MERGE_BYTES(port, data2, data1 & 0x7F, status);
Expand All @@ -202,7 +202,7 @@ struct BMCMidiEvent {
}
uint8_t getStatus(){
uint8_t status = BMC_GET_BYTE(0,event);
return (status < 0xF0) ? (status & 0xF0) : status;
return (status > 127 && status < 0xF0) ? (status & 0xF0) : status;
}
uint8_t getChannel(){
return BMC_GET_BYTE(0,event) & 0x0F;
Expand Down

0 comments on commit 138397a

Please sign in to comment.