Skip to content

Commit

Permalink
Merge branch 'master' into notes-outline
Browse files Browse the repository at this point in the history
  • Loading branch information
kosua20 authored Aug 1, 2023
2 parents 8072a87 + a4f705e commit 6cf0e26
Show file tree
Hide file tree
Showing 25 changed files with 360 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
cmake-opts:
- os: windows-2019
cmake-opts: -A x64
- os: macos-10.15
- os: macos-11
cmake-opts:

runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
artifact_name: build/Release/MIDIVisualizer.exe
asset_name: MIDIVisualizer-windows-64bits.zip
ffmpeg-archive: ffmpeg-windows-64-static-lgpl.zip
- os: macos-10.15
- os: macos-11
cmake-opts:
artifact_name: build/MIDIVisualizer.app
asset_name: MIDIVisualizer-macos.zip
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
build*/
.DS_Store
.thumb
ext/
Expand All @@ -9,6 +10,7 @@ x64/
*.user
*.xcodeproj
*.xcuserstate
*.vscode
*/xcuserdata/*
dependencies/
libs/ffmpeg
2 changes: 1 addition & 1 deletion resources/shaders/flashes.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 330
#define SETS_COUNT 8
#define SETS_COUNT 12


in INTERFACE {
Expand Down
84 changes: 0 additions & 84 deletions resources/shaders/keys.frag

This file was deleted.

42 changes: 42 additions & 0 deletions resources/shaders/majorKeys.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#version 330

in INTERFACE {
vec2 uv;
} In ;

#define SETS_COUNT 12
#define MAJOR_COUNT 75

uniform bool highlightKeys;
uniform bool horizontalMode = false;
uniform float notesCount; // (maxNoteMajor - minNoteMajor + 1)
uniform int actives[128];
uniform int minNoteMajor;
uniform vec2 inverseScreenSize;
uniform vec3 edgeColor = vec3(0.0);

uniform vec3 majorColor[SETS_COUNT];

const int majorIds[MAJOR_COUNT] = int[](0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 17, 19, 21, 23, 24, 26, 28, 29, 31, 33, 35, 36, 38, 40, 41, 43, 45, 47, 48, 50, 52, 53, 55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72, 74, 76, 77, 79, 81, 83, 84, 86, 88, 89, 91, 93, 95, 96, 98, 100, 101, 103, 105, 107, 108, 110, 112, 113, 115, 117, 119, 120, 122, 124, 125, 127);

out vec4 fragColor;


void main(){

// White keys, and separators.
float widthScaling = horizontalMode ? inverseScreenSize.y : inverseScreenSize.x;
float majorUvX = fract(In.uv.x * notesCount);

// Edges on the sides
float centerIntensity = 1.0 - step( 1.0 - 2.0 * notesCount * widthScaling, abs(majorUvX * 2.0 - 1.0));

// If the current major key is active, the majorColor is specific.
int majorId = majorIds[clamp(int(In.uv.x * notesCount) + minNoteMajor, 0, 74)];
int cidMajor = actives[majorId];
vec3 frontColor = (highlightKeys && cidMajor >= 0) ? majorColor[cidMajor] : vec3(1.0);

// Mix.
fragColor.rgb = mix(edgeColor, frontColor, centerIntensity);
fragColor.a = 1.0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ out INTERFACE {
vec2 uv;
} Out ;

uniform float keyboardHeight = 0.25;
uniform bool horizontalMode = false;
uniform float keyboardHeight = 0.25;

vec2 flipIfNeeded(vec2 inPos){
return horizontalMode ? vec2(inPos.y, -inPos.x) : inPos;
Expand All @@ -16,10 +16,10 @@ vec2 flipIfNeeded(vec2 inPos){
void main(){
// Input are in -0.5,0.5
// We directly output the position.
// [-0.5, 0.5] to [-1, 2.0*keyboardHeight-1.0]
// [-0.5, 0.5] to [-1, -1+2.0*keyboardHeight]
float yShift = keyboardHeight * (2.0 * v.y + 1.0) - 1.0;

vec2 pos2D = vec2(v.x*2.0, yShift);
vec2 pos2D = vec2(v.x * 2.0, yShift);

gl_Position.xy = flipIfNeeded(pos2D);
gl_Position.zw = vec2(0.0, 1.0);
Expand Down
58 changes: 58 additions & 0 deletions resources/shaders/minorKeys.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#version 330

in INTERFACE {
vec2 uv;
float id;
} In ;

#define SETS_COUNT 12

uniform bool highlightKeys;
uniform bool horizontalMode = false;
uniform float keyboardHeight = 0.25;
uniform float notesCount; // (maxNoteMajor - minNoteMajor + 1)
uniform int minNoteMajor;
uniform vec2 inverseScreenSize;
uniform vec3 edgeColor = vec3(0.0);

uniform vec3 minorColor[SETS_COUNT];
uniform bool edgeOnMinors;
uniform float minorsHeight = 0.6;
uniform float minorsWidth = 1.0;

vec2 minorShift(int id){
if(id == 1 || id == 6){
return vec2(0.0, 0.3);
}
if(id == 3 || id == 10){
return vec2(0.3, 0.0);
}
return vec2(0.1,0.1);
}

out vec4 fragColor;


void main(){

// Center uvs
vec2 ndc = 2.0 * In.uv - 1.0;

float widthScaling = horizontalMode ? inverseScreenSize.y : inverseScreenSize.x;
float heightScaling = horizontalMode ? inverseScreenSize.x : inverseScreenSize.y;
float uvWidth = minorsWidth / float(notesCount) * 0.5;
float uvHeight = minorsHeight * keyboardHeight * 0.5;

// Edges on the sides and bottom.
float xStep = step(1.0 - 2.0 * widthScaling / uvWidth, abs(ndc.x));
float yStep = step(1.0 - 2.0 * heightScaling / uvHeight, -ndc.y);
float centerIntensity = edgeOnMinors ? ((1.0 - xStep) * (1.0 - yStep)) : 1.0;

// Key color changes when active.
int cidMinor = int(In.id);
vec3 frontColor = (highlightKeys && cidMinor >= 0) ? minorColor[cidMinor] : edgeColor;

// Mix
fragColor.rgb = mix(edgeColor, frontColor, centerIntensity);
fragColor.a = 1.0;
}
78 changes: 78 additions & 0 deletions resources/shaders/minorKeys.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#version 330

layout(location = 0) in vec2 v;

out INTERFACE {
vec2 uv;
float id;
} Out ;

uniform bool horizontalMode = false;
uniform float keyboardHeight = 0.25;
uniform float notesCount; // (maxNoteMajor - minNoteMajor + 1)
uniform int actives[128];
uniform int minNoteMajor;

uniform float minorsHeight = 0.6;
uniform float minorsWidth = 1.0;

vec2 flipIfNeeded(vec2 inPos){
return horizontalMode ? vec2(inPos.y, -inPos.x) : inPos;
}

#define MINOR_COUNT 53

const int minorIds[MINOR_COUNT] = int[](1, 3, 6, 8, 10, 13, 15, 18, 20, 22, 25, 27, 30, 32, 34, 37, 39, 42, 44, 46, 49, 51, 54, 56, 58, 61, 63, 66, 68, 70, 73, 75, 78, 80, 82, 85, 87, 90, 92, 94, 97, 99, 102, 104, 106, 109, 111, 114, 116, 118, 121, 123, 126);

const int noteDelta[12] = int[](0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6);


float minorShift(int id){
if(id == 1 || id == 6){
return -0.1;
}
if(id == 3 || id == 10){
return 0.1;
}
return 0.0;
}

void main(){

float noteWidth = 2.0 / notesCount;
// Size of the note : width, height based on duration and current speed.
vec2 noteSize = vec2(0.9 * noteWidth * minorsWidth, 2.0 * minorsHeight * keyboardHeight);

// Compute note shift.
// Horizontal shift based on note id, width of keyboard, and if the note is minor or not.
//float a = (1.0/(notesCount-1.0)) * (2.0 - 2.0/notesCount);
//float b = -1.0 + 1.0/notesCount;
// This should be in -1.0, 1.0.
// input: noteId is in [0 MAJOR_COUNT]
// we want minNote to -1+1/c, maxNote to 1-1/c
float a = 2.0;
float b = -notesCount + 1.0 - 2.0 * float(minNoteMajor);

int minorId = minorIds[gl_InstanceID];
int noteId = (minorId/12) * 7 + noteDelta[minorId % 12];
float horizLoc = (float(noteId) * a + b + 1.0) / notesCount;

float vertLoc = 2.0 * (1.0 - minorsHeight) * keyboardHeight - 1.0 + noteSize.y * 0.5;
vec2 noteShift = vec2(horizLoc, vertLoc);

noteShift.x += minorShift(minorId % 12) * noteSize.x;

// Output position.
gl_Position = vec4(flipIfNeeded(noteSize * v + noteShift), 0.0 , 1.0) ;

// Discard keys that are too close to the screen edges.
if(abs(noteShift.x) >= 1.0 - 0.5 * noteWidth){
gl_Position = vec4(-40000.0);
}

// Output the UV coordinates computed from the positions.
Out.uv = v.xy + 0.5;
// And the active channel if present.
Out.id = float(actives[minorId]);

}
2 changes: 1 addition & 1 deletion resources/shaders/notes.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 330
#define SETS_COUNT 8
#define SETS_COUNT 12

in INTERFACE {
vec2 uv;
Expand Down
16 changes: 15 additions & 1 deletion resources/shaders/notes.vert
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ out INTERFACE {
float channel;
} Out;

#define MAJOR_COUNT 75
const int minorIds[MAJOR_COUNT] = int[](1, 3, 0, 6, 8, 10, 0, 13, 15, 0, 18, 20, 22, 0, 25, 27, 0, 30, 32, 34, 0, 37, 39, 0, 42, 44, 46, 0, 49, 51, 0, 54, 56, 58, 0, 61, 63, 0, 66, 68, 70, 0, 73, 75, 0, 78, 80, 82, 0, 85, 87, 0, 90, 92, 94, 0, 97, 99, 0, 102, 104, 106, 0, 109, 111, 0, 114, 116, 118, 0, 121, 123, 0, 126, 0);

float minorShift(int id){
if(id == 1 || id == 6){
return -0.1;
}
if(id == 3 || id == 10){
return 0.1;
}
return 0.0;
}

void main(){

Expand All @@ -47,7 +59,9 @@ void main(){
float vertLoc = 2.0 * keyboardHeight - 1.0;
vertLoc += (reverseMode ? -1.0 : 1.0) * (Out.noteSize.y * 0.5 + mainSpeed * (id.y - time));
vec2 noteShift = vec2(horizLoc, vertLoc);


noteShift.x += id.w * minorShift(minorIds[int(id.x)] % 12) * Out.noteSize.x;

// Scale uv.
Out.uv = Out.noteSize * v;
Out.isMinor = id.w;
Expand Down
2 changes: 1 addition & 1 deletion resources/shaders/particles.vert
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 330
#define SETS_COUNT 8
#define SETS_COUNT 12

layout(location = 0) in vec2 v;

Expand Down
3 changes: 3 additions & 0 deletions src/helpers/Recorder.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Recorder.h"
#include "System.h"
#include "../rendering/State.h"

#include <imgui/imgui.h>
Expand Down Expand Up @@ -305,6 +306,7 @@ bool Recorder::drawGUI(float scale){

if(_config.format == Export::Format::PNG){
nfdresult_t result = NFD_PickFolder(NULL, &outPath);
System::forceLocale();
if(result == NFD_OKAY) {
_config.path = std::string(outPath);
shouldStart = true;
Expand All @@ -313,6 +315,7 @@ bool Recorder::drawGUI(float scale){
} else {
const std::string & ext = _formats.at(int(_config.format)).ext;
nfdresult_t result = NFD_SaveDialog(ext.c_str(), NULL, &outPath);
System::forceLocale();
if(result == NFD_OKAY) {
_config.path = std::string(outPath);
const std::string fullExt = "." + ext;
Expand Down
Loading

0 comments on commit 6cf0e26

Please sign in to comment.