Shapes not spinning smoothly
in
Programming Questions
•
1 year ago
Hello,
I'm working on a project involving multiple percussionists and midi triggers. The idea is to show a background video of different shapes moving around and then have some of those shapes move and/or new shapes appear on the screen depending on which drum is hit and how hard. At this point, when a note happens, a shape appears on the screen and spins depending on the pitch and velocity. The spinning seems kind of jerky to me though. Any thoughts on how to get smoother movement? Thanks very much.
I'm working on a project involving multiple percussionists and midi triggers. The idea is to show a background video of different shapes moving around and then have some of those shapes move and/or new shapes appear on the screen depending on which drum is hit and how hard. At this point, when a note happens, a shape appears on the screen and spins depending on the pitch and velocity. The spinning seems kind of jerky to me though. Any thoughts on how to get smoother movement? Thanks very much.
- /* Creates an ArrayList of LinkedLists to hold the note data.
If three different pitch values are allowed (or three different drum trigger inputs),
an ArrayList of 3 linked lists is created. Each linked list holds the 5 most recent
note events for its pitch value.*/
import themidibus.*; //Midi library
MidiBus myBus; // The MidiBus
int numStreams = 3; //Number of MIDI inputs
int numNotes = 5; //Maximum number of notes shown at any given time per MIDI input
boolean noteEvent = false;
ArrayList< LinkedList<Note>> streams;
LinkedList<Note> currentStream;
Note[] newNotes;
void setup() {
streams = new ArrayList< LinkedList< Note >>();
newNotes = new Note[numStreams];
size(854, 480);
noStroke();
smooth();
rectMode(CENTER);
for (int i = 0; i < numStreams; i++) {
currentStream = new LinkedList<Note>();
streams.add(currentStream);
}
myBus = new MidiBus(this, -1, "Java Sound Synthesizer");
}
void draw() {
background(0);
for (LinkedList<Note> y : streams) {
for (Note z : y) {
z.display(); //display each Note and update its rotation and opacity
}
}
if (noteEvent == true) { //if note events have happened since last time through draw, update the appropriate linked lists
for (int i = 0; i < numStreams; i++) {
if (newNotes[i] != null) {
(streams.get(i)).add(newNotes[i]);
while ((streams.get(i)).size() > numNotes) {
(streams.get(i)).remove();
}
newNotes[i] = null;
}
}
noteEvent = false;
}
}
void keyPressed() { //using keyboard keys a, s, and d in this version
int channel = 0;
int pitch = 0;
int velocity = 100;
if (key == 'a') {
pitch = 48;
noteOn(channel, pitch, velocity);
}
if (key == 's') {
pitch = 49;
noteOn(channel, pitch, velocity);
}
if (key == 'd') {
pitch = 50;
noteOn(channel, pitch, velocity);
}
}
void noteOn(int channel, int pitch, int velocity) {
// Receive a noteOn
if (pitch == 48) {
noteEvent = true;
newNotes[0] = new Note(pitch, velocity);
} else if (pitch == 49) {
noteEvent = true;
newNotes[1] = new Note(pitch, velocity);
} else if (pitch == 50) {
noteEvent = true;
newNotes[2] = new Note(pitch, velocity);
}
}
void noteOff(int channel, int pitch, int velocity) {
// Receive a noteOff
}
void controllerChange(int channel, int number, int value) {
// Receive a controllerChange
}
class Note {
float opacity;
float pitch, velocity;
float xpos, ypos;
float angle;
Note(float pitchIn, float velocityIn) {
opacity = 255;
pitch = pitchIn;
velocity = velocityIn;
xpos = pitch * 110 - 5000;
ypos = 900 - velocity * 7;
angle = 0;
}
void display() {
fill(255, opacity);
pushMatrix();
translate(xpos, ypos);
rotate(radians(angle)); // not necessary for circles
if (pitch == 48) {
ellipse(0, 0, velocity, velocity);
}
if (pitch == 49) {
rect(0, 0, velocity, velocity);
}
if (pitch == 50) {
triangle(0, (-2*velocity)/3, sqrt(velocity*velocity/3), velocity/3, -sqrt(velocity*velocity/3), velocity/3);
}
popMatrix();
if (opacity > 0) {
angle += (.04 * velocity) + 1;
opacity -= 5;
} else {
opacity = 0;
}
}
}
1