Raylib 3
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.

107 lines
4.4 KiB

//Standard lib
#include <stdio.h>
//Third party
#include "raylib.h"
//Our own files
#include "constants.h"
#include "programstate.h"
#include "drawhelper.h"
#include "draw_xpitches_yports.h"
/* Each port is a track, which are ordered top to bottom
* Each pitch is a rectangle in that track. midi note 0 on the left to 127 on the right.
* 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)(60*(NOTE_SMALL_SIDE+NOTE_GAP)); //we want all tracks around the center.
int yOffset = (int)(screenHeight/2) - (int)(VIS_PORTS*(NOTE_LONG_SIDE+NOTE_GAP))/2; //we want all tracks around the center.
programState.modeDescription = "Each port is a horizontal track.\n\
Each pitch is one square, going from left lowest\nto right highest.\n\
The higher the velocity of a note the more\nvibrant its color.\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 + programState.pitchMin * (NOTE_SMALL_SIDE + NOTE_GAP/2);
backgroundRects[port].y = (float)(yOffset + port*NOTE_LONG_SIDE + port*NOTE_GAP*2 - NOTE_GAP);
backgroundRects[port].width = (programState.pitchMax-programState.pitchMin+1)*(NOTE_SMALL_SIDE + NOTE_GAP/2);
backgroundRects[port].height = (float)NOTE_LONG_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 + midiPitch*(NOTE_SMALL_SIDE + NOTE_GAP/2);
allGUINotes[port*128 + midiPitch].y = yOffset + port*NOTE_LONG_SIDE + port*NOTE_GAP*2;
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_xpitches_yports(Note *allGUINotes, int redrawNeeded) {
Note * nt;
float ft = GetFrameTime();
if (redrawNeeded) {
//Z-Order is created by call-order. First is bottom.
if (programState.showConnectedPortnames) {
for (int port=0; port<VIS_PORTS; port++) {
nt = &allGUINotes[port*128+programState.pitchMin]; // choose note where to start writing
drawJackPortName(programState.connectedPortNames[port], nt->x, nt->y, 18, RAYWHITE, false); //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_SMALL_SIDE-NOTE_BORDER, NOTE_LONG_SIDE-NOTE_BORDER};
DrawRectangleRounded(rec, 0.5, 8, programState.colors[backgroundLighter]);
//Debug: Show 0 and 127
//DrawLine(allGUINotes[0].x, 0, allGUINotes[0].x, GetScreenHeight(), RAYWHITE); //(int startPosX, int startPosY, int endPosX, int endPosY, Color color);
//DrawLine(allGUINotes[127].x, 0, allGUINotes[127].x, GetScreenHeight(), RAYWHITE); //(int startPosX, int startPosY, int endPosX, int endPosY, Color color);
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, 0, 0); //note, rotated, square. Will not draw if countdown == 0