Skip to content

Commit

Permalink
fixed beatcount example + bug + cleanup infoPanels
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsijben committed Apr 18, 2024
1 parent f8a8bf5 commit d365339
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 90 deletions.
2 changes: 1 addition & 1 deletion examples/ArduinoControls/all_controls/all_controls.pde
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void draw() {

noFill();
if (ac.getPushButton(0)) fill(255, 0, 0);
if (ac.getPushButton(1)) fill(0, 255, 0);
if (ac.getPushButtonOnce(1)) fill(0, 255, 0); //only green for 1 frame
if (ac.getPushButton(2)) fill(0, 0, 255);

//show ellipse at relative smoothed potentiometer value (prevents jumping around)
Expand Down
7 changes: 4 additions & 3 deletions examples/BPM_Timings/adsr/adsr.pde
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ PImage img;
void setup() {
size(500, 500);
bpm = new BeatsPerMinute(this);
bpm.showInfoPanel();
img = loadImage("adsr.png");
imageMode(CENTER);
textAlign(CENTER,CENTER);
textAlign(CENTER, CENTER);
textSize(40);
stroke(50);
fill(0);
Expand All @@ -46,7 +47,7 @@ void draw() {
text("1", width/5, height/2 - 100);
s = lerp(0, 100, bpm.linear());
circle(width/5, height/2, s);

// fast attack, no decay, no release
// so very fast progression (in 20% of the time of 1 beat) from 0 to 1, and keep it at 1 for the remainder of the time
text("2", width/5 * 2, height/2 - 100);
Expand All @@ -58,7 +59,7 @@ void draw() {
s = lerp(0, 100, bpm.adsr(attackDuration, decayDuration, sustainLevel, releaseDuration, durationInBeats));
// s = lerp(0, 100, bpm.adsr(0.2)); // this has the same effect because all other values are default values
circle(width/5 * 2, height/2, s);

// slow attack, fast release
// slowly progress (in 80% of the time of 1 beat) from 0 to 1, and quickly progress from 1 to 0
text("3", width/5 * 3, height/2 - 100);
Expand Down
1 change: 1 addition & 0 deletions examples/BPM_Timings/basic/basic.pde
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void setup() {
size(500, 500);
bpm = new BeatsPerMinute(this);
bpm.setBPM(30);

}

void draw() {
Expand Down
10 changes: 3 additions & 7 deletions examples/BPM_Timings/beatcount/beatcount.pde
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ BeatsPerMinute bpm;
void setup() {
size(500, 500);
bpm = new BeatsPerMinute(this)
//.setBPM(120)
//.showInfoPanel()
//.setInfoPanelY(200)
//.setInfoPanelKey('o')
//.disableKeyPress()
;
}

void draw() {
surface.setTitle(bpm.setSurfaceTitle());
surface.setTitle(bpm.getSurfaceTitle());

background(100);
textAlign(CENTER, CENTER);
textSize(20);
text(bpm.setSurfaceTitle(), width/2, 50);
text(bpm.getSurfaceTitle(), width/2, 50);
textSize(30);
text("The beatcount is: " + (int) bpm.beatCount, width/2, height/2);
text("The beatcount is: " + (int) bpm.getBeatCount(), width/2, height/2);
}
1 change: 1 addition & 0 deletions examples/FrequencyAnalyzer/basics/basics.pde
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void setup() {
//.setAudioInputMode(AudioInputMode.AUDIO_FILE, 128) // also set bufferSize, needs to be power of 2. Lower amount means less audio resolution and decreasing delay
//.setAudioInputMode(AudioInputMode.LINE_IN)
.setAudioOutputMode(AudioOutputMode.MONO)
.showInfoPanel()
;
}

Expand Down
20 changes: 20 additions & 0 deletions noteToSelf.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ ln -s ../../../src/bpm/library/arduinocontrols/LEDMode.java ./examples/ArduinoCo
ln -s ../../../src/bpm/library/arduinocontrols/Potentiometer.java ./examples/ArduinoControls/basics/Potentiometer.java
ln -s ../../../src/bpm/library/arduinocontrols/PushButton.java ./examples/ArduinoControls/basics/PushButton.java
ln -s ../../../src/bpm/library/InfoPanel.java ./examples/ArduinoControls/basics/InfoPanel.java
ln -s ../../../src/bpm/library/arduinocontrols/ArduinoControls.java ./examples/ArduinoControls/all_controls/ArduinoControls.java
ln -s ../../../src/bpm/library/arduinocontrols/LED.java ./examples/ArduinoControls/all_controls/LED.java
ln -s ../../../src/bpm/library/arduinocontrols/LEDMode.java ./examples/ArduinoControls/all_controls/LEDMode.java
ln -s ../../../src/bpm/library/arduinocontrols/Potentiometer.java ./examples/ArduinoControls/all_controls/Potentiometer.java
ln -s ../../../src/bpm/library/arduinocontrols/PushButton.java ./examples/ArduinoControls/all_controls/PushButton.java
ln -s ../../../src/bpm/library/InfoPanel.java ./examples/ArduinoControls/all_controls/InfoPanel.java
ln -s ../../../src/bpm/library/arduinocontrols/ArduinoControls.java ./examples/ArduinoControls/smoothing/ArduinoControls.java
ln -s ../../../src/bpm/library/arduinocontrols/LED.java ./examples/ArduinoControls/smoothing/LED.java
ln -s ../../../src/bpm/library/arduinocontrols/LEDMode.java ./examples/ArduinoControls/smoothing/LEDMode.java
ln -s ../../../src/bpm/library/arduinocontrols/Potentiometer.java ./examples/ArduinoControls/smoothing/Potentiometer.java
ln -s ../../../src/bpm/library/arduinocontrols/PushButton.java ./examples/ArduinoControls/smoothing/PushButton.java
ln -s ../../../src/bpm/library/InfoPanel.java ./examples/ArduinoControls/smoothing/InfoPanel.java
```
FrequencyAnalyzer examples:
```
Expand Down Expand Up @@ -110,8 +124,14 @@ ln -s ../../../src/bpm/library/InfoPanel.java ./examples/FrequencyAnalyzer/stere
```
BPM_Timing examples:
```
ln -s ../../../src/bpm/library/beatsperminute/BeatsPerMinute.java ./examples/BPM_Timings/adsr/BeatsPerMinute.java
ln -s ../../../src/bpm/library/InfoPanel.java ./examples/BPM_Timings/adsr/InfoPanel.java
ln -s ../../../src/bpm/library/beatsperminute/BeatsPerMinute.java ./examples/BPM_Timings/adsrSquares/BeatsPerMinute.java
ln -s ../../../src/bpm/library/InfoPanel.java ./examples/BPM_Timings/adsrSquares/InfoPanel.java
ln -s ../../../src/bpm/library/beatsperminute/BeatsPerMinute.java ./examples/BPM_Timings/animatedSVG/BeatsPerMinute.java
ln -s ../../../src/bpm/library/InfoPanel.java ./examples/BPM_Timings/animatedSVG/InfoPanel.java
ln -s ../../../src/bpm/library/beatsperminute/BeatsPerMinute.java ./examples/BPM_Timings/basic/BeatsPerMinute.java
ln -s ../../../src/bpm/library/InfoPanel.java ./examples/BPM_Timings/basic/InfoPanel.java
ln -s ../../../src/bpm/library/beatsperminute/BeatsPerMinute.java ./examples/BPM_Timings/beatcount/BeatsPerMinute.java
ln -s ../../../src/bpm/library/InfoPanel.java ./examples/BPM_Timings/beatcount/InfoPanel.java
ln -s ../../../src/bpm/library/beatsperminute/BeatsPerMinute.java ./examples/BPM_Timings/colorPalettes/BeatsPerMinute.java
Expand Down
4 changes: 2 additions & 2 deletions resources/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ source.repository=https://github.com/vincentsijben/bpm-tmings-for-processing.git
# This is used to compare different versions of the same Library, and check if
# an update is available.

library.version=17
library.version=18


# The version as the user will see it.

library.prettyVersion=1.2.3
library.prettyVersion=1.2.4


# The min and max revision of Processing compatible with your Library.
Expand Down
3 changes: 2 additions & 1 deletion src/bpm/library/InfoPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ public class InfoPanel {
private boolean keyPressedActionTaken;
public boolean enableKeyPress;


public InfoPanel(PApplet parent) {
this.parent = parent;
this.x = 0;
this.y = 0;
this.w = parent.width;
this.h = 100;
this.h = 150;
this.keyboardKey = 'i';
this.show = Boolean.FALSE;
this.keyPressedActionTaken = false;
Expand Down
50 changes: 25 additions & 25 deletions src/bpm/library/arduinocontrols/ArduinoControls.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,28 +292,31 @@ public void draw() {
// popMatrix in registermethod draw()
this.parent.popMatrix();
this.parent.popStyle();
this.parent.hint(PConstants.DISABLE_DEPTH_TEST);
if (this.infoPanel.show) {
//System.out.println(""+this.infoPanel.x + this.infoPanel.y + this.infoPanel.w + this.infoPanel.h);
boolean portrait = false; //this.infoPanelLocation[2] < this.infoPanelLocation[3];

if (this.infoPanel.show) {
this.parent.hint(PConstants.DISABLE_DEPTH_TEST);

// put the parents imageMode temporarily to CORNER
this.parent.pushStyle();
this.parent.imageMode(PConstants.CORNER);
//

PGraphics overlay = this.infoPanel.overlay;
overlay.beginDraw();
overlay.background(0, 200);
overlay.background(0, 170);
overlay.noStroke();
overlay.fill(255);
if (portrait) {
for (int i=0; i<this.pushbuttons.size(); i++) overlay.text("getPushButton("+i+ "): " + this.getPushButton(i), 5, 15+i*20);
for (int i=0; i<this.potentiometers.size(); i++) overlay.text("getPotentiometer("+i+ "): " + PApplet.nf(this.getPotentiometer(i), 0, 2) + " raw: " + this.potentiometers.get(i).value, 5, 115+i*20);
} else {
for (int i=0; i<this.pushbuttons.size(); i++) overlay.text("getPushButton("+i+ "): " + this.getPushButton(i), 5, 15+i*20);
for (int i=0; i<this.potentiometers.size(); i++) overlay.text("getPotentiometer("+i+ "): " + PApplet.nf(this.getPotentiometer(i), 0, 2) + " raw: " + this.potentiometers.get(i).value, 185, 15+i*20);
}
overlay.textSize(18);
for (int i=0; i<this.pushbuttons.size(); i++) overlay.text("getPushButton("+i+ "): " + this.getPushButton(i), 10, 25+i*20);
for (int i=0; i<this.pushbuttons.size(); i++) overlay.text("getPushButtonOnce("+i+ "): " + this.getPushButtonOnce(i), 10, 85+i*20);
for (int i=0; i<this.potentiometers.size(); i++) overlay.text("getPotentiometer("+i+ "): " + PApplet.nf(this.getPotentiometer(i), 0, 2) + " raw: " + this.potentiometers.get(i).value, 245, 25+i*20);
for (int i=0; i<this.potentiometers.size(); i++) overlay.text("getPotentiometer("+i+ ", 0.02): " + PApplet.nf(this.getPotentiometer(i, 0.02f), 0, 2) + " raw: " + this.potentiometers.get(i).value, 245, 85+i*20);
overlay.endDraw();

this.parent.image(overlay, this.infoPanel.x, this.infoPanel.y, this.infoPanel.w, this.infoPanel.h); // Draw the overlay onto the main canvas
this.parent.image(overlay, this.infoPanel.x, this.infoPanel.y); // Draw the overlay onto the main canvas
this.parent.popStyle();
this.parent.hint(PConstants.ENABLE_DEPTH_TEST);
}
this.parent.hint(PConstants.ENABLE_DEPTH_TEST);
}


Expand All @@ -327,19 +330,16 @@ public void draw() {

public void post() {
// https://github.com/benfry/processing4/wiki/Library-Basics
// you cant draw in post() but its perfect for resetting the inputButtonsOnce array:

// you cant draw in post() but its perfect for resetting the inputButtonsOnce array which needs to be done at the end of the draw cycle:
if (this.parent.frameCount != this.lastFrameCount) for (PushButton button : pushbuttons) button.pressedOnce = false;
}

public void pre() {

if (this.parent.frameCount != this.lastFrameCount) for (PushButton button : pushbuttons) button.pressedOnce = false;

// make sure everything in the main sketch is wrapped inside pushMatrix and popMatrix, so the infopanel is always shown top left, even in 3D mode
// pushMatrix in registermethod pre()
// popMatrix in registermethod draw()
this.parent.pushMatrix();
this.parent.pushStyle();
}
// make sure everything in the main sketch is wrapped inside pushMatrix and popMatrix, so the infopanel is always shown top left, even in 3D mode
// pushMatrix in registermethod pre()
// popMatrix in registermethod draw()
this.parent.pushMatrix();
this.parent.pushStyle();
}
}

52 changes: 21 additions & 31 deletions src/bpm/library/beatsperminute/BeatsPerMinute.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
todo: //processing doesn't like transparancy in 3D for the overlay
//see https://www.reddit.com/r/processing/comments/59r0le/problems_with_transparency_in_3d/
*/

package bpm.library.beatsperminute;

import bpm.library.InfoPanel;
Expand Down Expand Up @@ -70,8 +65,7 @@ public BeatsPerMinute(PApplet parent) {
this.setBPM(60);
this.millis_start = parent.millis();
this.infoPanel = new InfoPanel(parent);
this.infoPanel.h = parent.height;
this.infoPanel.overlay = parent.createGraphics(parent.width, parent.height);
this.infoPanel.overlay = parent.createGraphics(190, 440);
this.enableKeyPress = true;
this.keyPressedActionTaken = false;

Expand Down Expand Up @@ -267,48 +261,44 @@ public void draw() {
// popMatrix in registermethod draw()
this.parent.popMatrix();
this.parent.popStyle();
this.parent.hint(PConstants.DISABLE_DEPTH_TEST);

if (this.infoPanel.show) {
this.parent.pushMatrix();
this.parent.hint(PConstants.DISABLE_DEPTH_TEST);

// put the parents imageMode temporarily to CORNER
this.parent.pushStyle();
// this.parent.translate(0,0);
this.parent.imageMode(PConstants.CORNER);
//

PGraphics overlay = this.infoPanel.overlay;
overlay.beginDraw();
overlay.pushMatrix();
overlay.pushStyle();
overlay.rectMode(PConstants.CORNER);
overlay.textAlign(PConstants.LEFT, PConstants.CENTER);
overlay.stroke(0);
overlay.fill(255, 100);
overlay.rect(0, 0, 190, 440);
overlay.fill(0);
overlay.textSize(20);
overlay.background(0, 170);
overlay.noStroke();
overlay.fill(255);
overlay.textSize(18);
overlay.text("BPM: " + this.bpm, 10, 20);
overlay.text("beatDuration: " + Math.floor(this.beatDuration), 10, 40);
overlay.text("beatCount: " + this.beatCount, 10, 60);
overlay.text("frameRate: " + (int)(this.parent.frameRate), 10, 80);

overlay.textSize(12);
overlay.text("every 1 beat", 12, 108);
if (this.every_once[1]) overlay.fill(0);
else overlay.fill(255);
overlay.ellipse(90, 108, 10, 10);
overlay.stroke(255);
if (this.every_once[1]) overlay.fill(255);
else overlay.noFill();
overlay.ellipse(90, 105, 10, 10);
for (int i=2; i<this.every.length; i++) {
overlay.fill(0);
overlay.fill(255);
overlay.text("every " + i + " beat", 12, 88 + i*20);
if (this.every[i]) overlay.fill(0);
else overlay.fill(255);
overlay.ellipse(90, 88 + i*20, 10, 10);
if (this.every[i]) overlay.fill(255);
else overlay.noFill();
overlay.ellipse(90, 84 + i*20, 10, 10);
}
overlay.popStyle();
overlay.popMatrix();
overlay.endDraw();
this.parent.image(overlay, this.infoPanel.x, this.infoPanel.y, this.infoPanel.w, this.infoPanel.h); // Draw the overlay onto the main canvas
this.parent.image(overlay, this.infoPanel.x, this.infoPanel.y); // Draw the overlay onto the main canvas
this.parent.popStyle();
this.parent.popMatrix();
this.parent.hint(PConstants.ENABLE_DEPTH_TEST);
}
this.parent.hint(PConstants.ENABLE_DEPTH_TEST);
}


Expand Down
54 changes: 34 additions & 20 deletions src/bpm/library/frequencyanalyzer/FrequencyAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,27 +299,40 @@ public void draw() {
// popMatrix in registermethod draw()
this.parent.popMatrix();
this.parent.popStyle();
this.parent.hint(PConstants.DISABLE_DEPTH_TEST);



if (this.infoPanel.show) {
this.parent.hint(PConstants.DISABLE_DEPTH_TEST);

// put the parents imageMode temporarily to CORNER
this.parent.pushStyle();
this.parent.imageMode(PConstants.CORNER);
//

PGraphics overlay = this.infoPanel.overlay;
overlay.beginDraw();
overlay.fill(200, 127);
overlay.background(0, 170);
overlay.noStroke();
overlay.rect(0, 0, overlay.width, overlay.height);

for (int i = 0; i < this.avgSize(); i++) {
float xR = (i * overlay.width) / this.avgSize();
float yR = 100;


float yR = 150;

overlay.fill(255);
this.maxVal = 100;

if (this.currentOutputMode == AudioOutputMode.STEREO) {
overlay.rect(xR, yR, overlay.width / this.avgSize()/2, PApplet.lerp(0, -100, this.getAvgRawLeft(i)));
overlay.rect(xR + overlay.width / this.avgSize()/2, yR, overlay.width / this.avgSize()/2, PApplet.lerp(0, -100, this.getAvgRawRight(i)));
float h = PApplet.lerp(0, -100, this.getAvgRawLeft(i));
h = PApplet.constrain(h, -100, 0);
overlay.rect(xR, yR, overlay.width / this.avgSize()/2, h);
h = PApplet.lerp(0, -100, this.getAvgRawRight(i));
h = PApplet.constrain(h, -100, 0);
overlay.rect(xR + overlay.width / this.avgSize()/2, yR, overlay.width / this.avgSize()/2, h);
} else {
overlay.rect(xR, yR, overlay.width / this.avgSize(), PApplet.lerp(0, -100, this.getAvgRaw(i)));
float h = PApplet.lerp(0, -100, this.getAvgRaw(i));
h = PApplet.constrain(h, -100, 0);
overlay.rect(xR, yR, overlay.width / this.avgSize(), h);
}

overlay.fill(255, 0, 0);
Expand All @@ -336,22 +349,23 @@ public void draw() {
overlay.text(i, xR + (overlay.width / this.avgSize() / 2), yR-6);
}
overlay.fill(255);
overlay.textSize(25);
overlay.textAlign(PApplet.LEFT);
overlay.text(PApplet.round(this.parent.frameRate), 20, 30);
overlay.textAlign(PApplet.CENTER);
overlay.text("maxVal: " + PApplet.round(maxVal), this.parent.width/2, 30);
overlay.textSize(16);
overlay.textAlign(PApplet.LEFT);

//overlay.textAlign(PApplet.CENTER);
//overlay.text("maxVal: " + PApplet.round(maxVal), this.parent.width/2, 30);
//overlay.textAlign(PApplet.LEFT);
String s = "selected mode: " + this.currentInputMode;
float posX = overlay.width-overlay.textWidth(s)-10;
overlay.text(s, posX, 30);
if (this.currentInputMode == AudioInputMode.AUDIO_FILE && audioPlayer != null) overlay.text("muted: " + audioPlayer.isMuted(), posX, 60);
//else overlay.text("monitoring: " + (audioInput.isMonitoring() ? "on": "off"), posX, 60);
else overlay.text("monitoring: " + (currentInputSource.isMonitoring() ? "on": "off"), posX, 60);
overlay.text(s, 15, 30);
if (this.currentInputMode == AudioInputMode.AUDIO_FILE && audioPlayer != null) overlay.text("muted: " + audioPlayer.isMuted(), overlay.width-120, 30);
//else overlay.text("monitoring: " + (audioInput.isMonitoring() ? "on": "off"), overlay.width-120, 30);
else overlay.text("monitoring: " + (currentInputSource.isMonitoring() ? "on": "off"), overlay.width-120, 30);
overlay.endDraw();
this.parent.image(overlay, this.infoPanel.x, this.infoPanel.y, this.infoPanel.w, this.infoPanel.h); // Draw the overlay onto the main canvas

this.parent.popStyle();
this.parent.hint(PConstants.ENABLE_DEPTH_TEST);
}
this.parent.hint(PConstants.ENABLE_DEPTH_TEST);
}


Expand Down

0 comments on commit d365339

Please sign in to comment.