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.
99 lines
3.5 KiB
99 lines
3.5 KiB
//Standard lib
|
|
#include <stdio.h>
|
|
#include <math.h>
|
|
|
|
//Third party
|
|
#include "raylib.h"
|
|
|
|
//Our own files
|
|
#include "constants.h"
|
|
#include "programstate.h"
|
|
#include "drawhelper.h"
|
|
#include "draw_activity.h"
|
|
|
|
|
|
static int screenWidth;
|
|
static int screenHeight;
|
|
|
|
static int radius = 80;
|
|
const float distanceFactor = 2.5;
|
|
static int xOffset;
|
|
static int yOffset;
|
|
|
|
extern ProgramState programState;
|
|
|
|
static float fadeout[VIS_PORTS];
|
|
|
|
|
|
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
|
|
screenWidth = GetScreenWidth();
|
|
screenHeight = GetScreenHeight();
|
|
|
|
xOffset = (int)(screenWidth/2) - (VIS_PORTS_SQRT/2)*radius*distanceFactor;
|
|
yOffset = (int)(screenHeight/2) - (VIS_PORTS_SQRT/2)*radius*distanceFactor;
|
|
|
|
programState.modeDescription = "Each port is one polygon.\nNumber of sites equals active notes.\nThere is no time-dimension.";
|
|
}
|
|
|
|
|
|
void drawShape(Vector2 center, int port, float rotation) {
|
|
//DrawPolyLines(Vector2 center, int sides, float radius, float rotation, Color color);
|
|
|
|
//float fadeValue = pow(sinf(rotation / 180 * PI), 2); //sine wants radians, not degree
|
|
//float fadeValue = (float)(GetRandomValue(1,10)-5.0f) / 100.0f + 1.0f; //sparkle
|
|
//Color color = Fade(programState.colors[port], fadeValue);
|
|
|
|
Color border = Fade(BLACK, fadeout[port]);
|
|
Color color = Fade(programState.colors[port], fadeout[port]);
|
|
|
|
if (programState.portActivity[port] < 3) {
|
|
//DrawCircleV(Vector2 center, float radius, Color color);
|
|
DrawCircleV(center, radius*0.7+NOTE_BORDER, border);
|
|
DrawCircleV(center, radius*0.7, color);
|
|
}
|
|
else {
|
|
DrawPoly(center, programState.portActivity[port], radius+NOTE_BORDER*2, rotation, border);
|
|
DrawPoly(center, programState.portActivity[port], radius, rotation, color);
|
|
}
|
|
}
|
|
|
|
void draw_activity(Note *allGUINotes, int redrawNeeded) {
|
|
float ft = GetFrameTime();
|
|
int bpmFactor = programState.bpm/40 * programState.bpm/20; //exponential curve. The higher bpm the faster we get. Below 90 it should feel really slow
|
|
float rotation = fmod(GetTime() * bpmFactor * 5, 360.0f);
|
|
|
|
if (redrawNeeded) {
|
|
reposition(allGUINotes);
|
|
}
|
|
|
|
for (int port=0; port<VIS_PORTS; port++) {
|
|
|
|
int portRow = port / VIS_PORTS_SQRT;
|
|
int portColumn = port % VIS_PORTS_SQRT;
|
|
int blockY = portRow * radius * distanceFactor;
|
|
int blockX = portColumn * radius * distanceFactor;
|
|
Vector2 center = (Vector2){ xOffset + blockX + radius, yOffset + blockY + radius };
|
|
|
|
if (programState.showPortBackground && portShouldDraw(port)) {
|
|
DrawCircleV(center, radius-NOTE_BORDER, programState.colors[backgroundLight]);
|
|
}
|
|
|
|
if (programState.portActivity[port] > 0) {
|
|
//printf("port %i notes %i\n", port, programState.portActivity[port]);
|
|
fadeout[port] = 1.0f;
|
|
drawShape(center, port, rotation);
|
|
|
|
}
|
|
else if (fadeout[port] > 0.0f) {
|
|
if (fadeout[port] == 1.0f) { fadeout[port] = 0.999; } //begin countdown
|
|
fadeout[port] = calculateCountdown(fadeout[port], ft);
|
|
drawShape(center, port, rotation);
|
|
}
|
|
|
|
if (programState.showConnectedPortnames) {
|
|
drawJackPortName(programState.connectedPortNames[port], xOffset+blockX, yOffset+blockY, 18, RAYWHITE, false); //text, x, y, int fontsize, color, vertical
|
|
}
|
|
}
|
|
}
|
|
|