Skip to content

Commit 5036280

Browse files
committed
v0.1.7 updated pixel programs handling
1 parent f557bc3 commit 5036280

File tree

7 files changed

+47
-10
lines changed

7 files changed

+47
-10
lines changed

docs/leds-and-pixels.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ uint8_t getPixelCustomStateBrightness(uint8_t n);
199199
200200
uint32_t getPixelStates();
201201
202+
// available if pixel programs compiled
203+
// change the current pixel program
204+
void setPixelProgram(uint8_t t_program);
205+
206+
// available if pixel programs compiled
207+
// get the current pixel program
208+
uint8_t getPixelProgram();
209+
202210
// ** RGB PIXELS **
203211
204212
// get RgbPixel Data

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=BMC
2-
version=0.1.6
2+
version=0.1.7
33
author=Nero Rox
44
maintainer=Nero Rox <info@roxxxtar.com>
55
sentence=Fully featured MIDI Controller Library with a Companion Editor App. For Teensy

src/BMC-Api.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,16 @@ class BMCApi : public BMC {
10271027
uint32_t getPixelStates(){
10281028
return pixelStates;
10291029
}
1030+
#if BMC_MAX_PIXEL_PROGRAMS > 0
1031+
// change the current pixel program
1032+
void setPixelProgram(uint8_t t_program){
1033+
pixelPrograms.setProgram(t_program);
1034+
}
1035+
// get the current pixel program
1036+
uint8_t getPixelProgram(){
1037+
return pixelPrograms.getProgram();
1038+
}
1039+
#endif
10301040
#endif
10311041

10321042
#if BMC_MAX_RGB_PIXELS > 0

src/BMC-Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// BMC Version stored in EEPROM (for editor usage)
2424
#define BMC_VERSION_MAJ 0
2525
#define BMC_VERSION_MIN 1
26-
#define BMC_VERSION_PATCH 6
26+
#define BMC_VERSION_PATCH 7
2727

2828
//16 bits unsigned, LSB byte is minor, MSB byte is major
2929
#define BMC_VERSION ((BMC_VERSION_MAJ<<8) | BMC_VERSION_MIN)

src/BMC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void BMC::update(){
206206
readHardware();
207207

208208
#if BMC_MAX_PIXEL_PROGRAMS > 0
209-
pixelPrograms.update(midiClock.isEigthNote());
209+
pixelPrograms.update(midiClock.isEigthNote(), midiClock.isActive());
210210
#endif
211211

212212
// handle callbacks for presets and setlist

src/midi/BMC-MidiClock.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#define BMC_MIDI_CLOCK_FLAG_MASTER 0
2121
#define BMC_MIDI_CLOCK_FLAG_BEAT 1
2222
#define BMC_MIDI_CLOCK_FLAG_BPM_CHANGED 2
23-
#define BMC_MIDI_CLOCK_FLAG_EIGTH 3
23+
#define BMC_MIDI_CLOCK_FLAG_ACTIVE 3
24+
#define BMC_MIDI_CLOCK_FLAG_EIGTH 4
2425

2526
#define BMC_CLOCK_BPM_AVG 4
2627
#define BMC_MICROS_SECOND 0x3938700
@@ -51,6 +52,7 @@ class BMCMidiClock {
5152
}
5253
// If BMC is set to Master Clock
5354
if(isMaster()){
55+
flags.on(BMC_MIDI_CLOCK_FLAG_ACTIVE);
5456
// check if the timer is active and complete, in which case we assign
5557
// a new BPM, this timer is started when a new BPM is set via the API
5658
if(bpmSetTimer.complete()){
@@ -80,6 +82,11 @@ class BMCMidiClock {
8082
}
8183
}
8284
} else if(incoming && midi.isIncomingClockPort()){
85+
timeout.start(2000);
86+
flags.on(BMC_MIDI_CLOCK_FLAG_ACTIVE);
87+
if(timeout.complete()){
88+
flags.off(BMC_MIDI_CLOCK_FLAG_ACTIVE);
89+
}
8390
// the ticks variable is only used by the master clock
8491
ticks = 0;
8592
// the bmp calculator that a PPQN was received
@@ -121,6 +128,9 @@ class BMCMidiClock {
121128
}
122129
return bpmCalc.isEigthNote();
123130
}
131+
bool isActive(){
132+
return flags.read(BMC_MIDI_CLOCK_FLAG_ACTIVE);
133+
}
124134

125135
void setMaster(bool value){
126136
if(isMaster()!=value){
@@ -239,6 +249,7 @@ class BMCMidiClock {
239249
elapsedMicros masterTimer;
240250
BMCBpmCalculator bpmCalc;
241251
BMCTimer bpmSetTimer;
252+
BMCTimer timeout;
242253
void assignBpm(uint16_t tempo){
243254
if(isMaster() && BMCBpmCalculator::isValidBpm(tempo)){
244255
if(bpm!=tempo){

src/utility/BMC-PixelPrograms.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#include "utility/BMC-Def.h"
1111
#if BMC_MAX_PIXELS > 0 && BMC_MAX_PIXEL_PROGRAMS > 0
1212

13-
#define BMC_PIXEL_PROGRAMS_FLAG_BLACKOUT 0
13+
#define BMC_PIXEL_PROGRAMS_FLAG_ACTIVE 0
14+
#define BMC_PIXEL_PROGRAMS_FLAG_BLACKOUT 1
1415

1516
class BMCPixelPrograms {
1617
private:
@@ -26,15 +27,15 @@ class BMCPixelPrograms {
2627
void reassign(){
2728

2829
}
29-
void update(bool isEigthNote){
30-
if(isEigthNote){
30+
void update(bool t_eigth, bool t_active){
31+
if(t_eigth){
3132
eigthNotes++;
32-
if(eigthNotes>8){
33+
if(eigthNotes>16){
3334
eigthNotes = 1;
3435
}
3536
}
3637
uint8_t duration = ((global.pixelPrograms[program].events[currentItem]>>4)&0x0F)+1;
37-
38+
flags.write(BMC_PIXEL_PROGRAMS_FLAG_ACTIVE, t_active);
3839
if(eigthNotes == duration){
3940
currentItem++;
4041
if(currentItem >= global.pixelPrograms[program].length){
@@ -54,7 +55,7 @@ class BMCPixelPrograms {
5455
setBlackout(!flags.read(BMC_PIXEL_PROGRAMS_FLAG_BLACKOUT));
5556
}
5657
uint8_t getColor(){
57-
if(flags.read(BMC_PIXEL_PROGRAMS_FLAG_BLACKOUT)){
58+
if(isBlackout() || !isActive()){
5859
return 0;
5960
}
6061
return global.pixelPrograms[program].events[currentItem] & 0x0F;
@@ -66,8 +67,15 @@ class BMCPixelPrograms {
6667
if(t_value<BMC_MAX_PIXEL_PROGRAMS){
6768
program = t_value;
6869
currentItem = 0;
70+
eigthNotes = 0;
6971
}
7072
}
73+
bool isBlackout(){
74+
return flags.read(BMC_PIXEL_PROGRAMS_FLAG_BLACKOUT);
75+
}
76+
bool isActive(){
77+
return flags.read(BMC_PIXEL_PROGRAMS_FLAG_ACTIVE);
78+
}
7179
void scrollUp(bool endless, uint8_t min, uint8_t max){
7280
scroll(true, endless, min, max);
7381
}

0 commit comments

Comments
 (0)