You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
4.0 KiB
103 lines
4.0 KiB
//Standard lib
|
|
|
|
//Third party
|
|
#include "raylib.h"
|
|
|
|
//Our own files
|
|
#include "constants.h"
|
|
#include "programstate.h"
|
|
#include "drawhelper.h"
|
|
#include "draw_xports_ypitches.h"
|
|
|
|
/* Each port is a column, ordered from left to right
|
|
* Each pitch is a rectangle in that column. midi note 0 on the bottom to 127 on top
|
|
* The screen does not move or scroll. Notes fade out and make room for the next note-on.
|
|
*/
|
|
|
|
extern ProgramState programState;
|
|
|
|
static Rectangle backgroundRects[VIS_PORTS]; // 4 floats: x, y, w, h
|
|
|
|
static void reposition(Note *allGUINotes) {
|
|
//This is both init and update. We only call it internally, the name of the function doesn't matter.
|
|
//Once guaranteed called on program start and then each window resize
|
|
int screenWidth = GetScreenWidth();
|
|
int screenHeight = GetScreenHeight();
|
|
int xOffset = (int)(screenWidth/2) - (int)((VIS_PORTS*NOTE_LONG_SIDE)/2);
|
|
//int yOffset = -1 * ((int)(screenWidth/2) - ((programState.pitchMax - programState.pitchMin +1 ) * NOTE_SMALL_SIDE))/2;
|
|
int yOffset = -1 * ((int)(screenHeight/2) - (60 * NOTE_SMALL_SIDE)/2); //we want all tracks around the center.
|
|
|
|
programState.modeDescription = "Each port is a vertical column.\n\
|
|
Each pitch is one square, going from top highest\nto bottomw lowest.\n\
|
|
\n\
|
|
The higher the velocity of a note the more\nvibrant its color.\n\
|
|
\n\
|
|
Notes are only lit up when they are played.\n\
|
|
There is no time-dimension.";
|
|
|
|
for (int port=0; port<VIS_PORTS; port++) {
|
|
backgroundRects[port].x = xOffset + port*(NOTE_LONG_SIDE + NOTE_GAP) - NOTE_GAP/2;
|
|
backgroundRects[port].y = yOffset + (127-programState.pitchMax) * NOTE_SMALL_SIDE;
|
|
backgroundRects[port].width = (float)NOTE_LONG_SIDE;
|
|
backgroundRects[port].height = (programState.pitchMax - programState.pitchMin +1 ) * NOTE_SMALL_SIDE;
|
|
|
|
for (int midiPitch=0; midiPitch<128; midiPitch++) { //We prepare the full range of pitches, but the main loop will only activate the current pitch range.
|
|
allGUINotes[port*128 + midiPitch].x = xOffset + port*(NOTE_LONG_SIDE + NOTE_GAP);
|
|
allGUINotes[port*128 + midiPitch].y = yOffset + (127-midiPitch) * NOTE_SMALL_SIDE ;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void drawBackground() {
|
|
//Each port is one track
|
|
//The background rects already have their positions and dimensions set.
|
|
if (programState.showPortBackground) {
|
|
for (int port=0; port<VIS_PORTS; port++) {
|
|
if (portShouldDraw(port)) {
|
|
DrawRectangleRec(backgroundRects[port], programState.colors[backgroundLight]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void draw_xports_ypitches(Note *allGUINotes, int redrawNeeded) {
|
|
Note * nt;
|
|
float ft = GetFrameTime();
|
|
|
|
if (redrawNeeded) {
|
|
reposition(allGUINotes);
|
|
}
|
|
|
|
//Z-Order is created by call-order. First is bottom.
|
|
drawBackground();
|
|
|
|
|
|
if (programState.showConnectedPortnames) {
|
|
for (int port=0; port<VIS_PORTS; port++) {
|
|
nt = &allGUINotes[port*128+programState.pitchMin]; // bottom left note of each port
|
|
drawJackPortName(programState.connectedPortNames[port], nt->x, nt->y+20, 18, RAYWHITE, true); //text, x, y, int fontsize, color, vertical
|
|
}
|
|
}
|
|
|
|
if (programState.showPitchMarker) {
|
|
for (int port=0; port<VIS_PORTS; port++) {
|
|
if (portShouldDraw(port)) {
|
|
nt = &allGUINotes[port*128 + programState.pitchMarkerValue];
|
|
Rectangle rec = (Rectangle){nt->x, nt->y, NOTE_LONG_SIDE-NOTE_BORDER, NOTE_SMALL_SIDE-NOTE_BORDER};
|
|
DrawRectangleRounded(rec, 0.5, 8, programState.colors[backgroundLighter]);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
for (int port=0; port<VIS_PORTS; port++) {
|
|
for (int midiPitch=programState.pitchMin; midiPitch<=programState.pitchMax; midiPitch++) {
|
|
nt = &allGUINotes[port*128 + midiPitch];
|
|
if (nt->active) {
|
|
reduceCountdown(nt, ft); //handles 0.0 and 1.0 as special cases
|
|
drawNoteRect(nt, 1, 0); //note, rotated, square. Will not draw if countdown == 0
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|