Skip to content

Flesh out the function defs and track struct #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ BUILDDIR = build

TOOLS = tools

SOURCES += src/app.c
SOURCES += src/app.c src/sequencer.c

INCLUDES += -Iinclude -I

Expand Down
57 changes: 57 additions & 0 deletions include/channel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef CHANNEL_H
#define CHANNEL_H

#include "app.h"

#define SEQUENCE_MAX_LENGTH 32
#define NOTES_MAX_RANGE 32

typedef struct Track
{
// Gates
u32 euclidSequenceFlags;
u8 euclidSequenceLength;
u8 euclidSequencePosition;

u8 euclidDensity;
u8 euclidOffset;

// Notes
u32 turingMachineSequenceShiftRegister;
u8 turingMachineSequenceLength;
u8 turingMachineSequencePosition;

u8 turingMachineScale;
u8 turingMachineRandom;

u8 previousNote;
u16 quantizerValues;
u8 accentsOn;
u8 sequenceMutesArray;

u32 quantizedNotesArray;

// Misc
u8 midiChannelsFlags;
u8 octave;
u8 isMuted;
u8 resolution;
u8 resolutionCounter;

// UI
u8 uiEuclidSequenceLength;
u8 uiEuclidDensity;
u8 uiEuclidOffset;

u8 uiTuringMachineSequenceLength;
u8 uiTuringMachineSequenceScale;
u8 uiTuringMachineSequenceRandom;

u16 uiQuantizer;

u8 red;
u8 green;
u8 blue;
} Track;

#endif
138 changes: 138 additions & 0 deletions include/sequencer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#ifndef SEQUENCER_H
#define SEQUENCER_H

#include "app.h"

// Sequencer
#define MS_PER_MIN 60000
#define CLOCK_RATE 24 // 4 == 16th notes, 8 == 32nd notes, 24 == fuck_knows
#define NUM_TRACKS 8
#define EXTERNAL_CLOCK 0
#define INTERNAL_CLOCK 1
#define DEFAULT_OCTAVE 3
#define SEQUENCER_STOPPED 0
#define SEQUENCER_PLAYING 1

// UI
#define TRACK_VIEW 0
#define CHANNEL_VIEW 1
#define RESOLUTION_VIEW 2
#define SEQUENCE_MUTES_VIEW 3

void initialize();

u8 getSyncMode();

void toggleSyncMode();

void toggleAccents();

void setSequencerState(u8 state);

void setCurrentView(u8 view);

void handlePadEvent(u8 type, u8 index, u8 value);

void setTempoIncrease();

void setTempoDecrease();

void setOctaveDown();

void setOctaveUp();

void setMuteValue(u8 track);

void selectTrack(u8 track);

void setEuclidPatternLength(u8 bitNumber);

void setEuclidDensity(u8 bitNumber);

void setEuclidOffset(u8 bitNumber);

void setTuringMachinePatternLength(u8 bitNumber);

void setTuringMachineScale(u8 bitNumber);

void setTuringMachineRandom(u8 bitNumber);

void setChannel(u8 index);

void setResolution(u8 index, u8 value);

void setMute(u8 index);

void toggleQuantizerBlackKeysValue(u8 note);

void toggleQuantizerWhiteKeysValue(u8 note);

void updateQuantizedNotesArray();

void calculateEuclideanRhythm();

u8 getTempo();

void setMsPerClock();

u8 getMsPerClock();

void zeroCounters();

void handleMidiInput(u8 port, u8 status, u8 d1, u8 d2);

void handleNextPulse();

void incrementSequencerTrack(u8 trackNumber);

u8 nextGate(u8 trackNumber);

u8 nextNote(u8 trackNumber);

void insertRandom(u8 trackNumber);

u8 getQuantizedNote(u8 trackNumber, u8 note);

void playNote(u8 trackNumber, u8 note);

void killNote(u8 trackNumber, u8 note);

void killNotes(u8 trackNumber);

void updateUi();

void renderMuteButtons();

void renderQuantizer();

void renderTrackSelectButtons();

void renderEuclidPatternLength();

void renderEuclidDensity();

void renderEuclidOffset();

void renderTuringMachinePatternLength();

void renderTuringMachineScale();

void renderTuringMachineRandom();

void renderTempoButtons();

void renderOctaveButtons();

void renderChannels();

void renderViewButtons();

void clearAllPads();

void renderResolution();

void renderAccentButton();

void renderMutes();

#endif
56 changes: 56 additions & 0 deletions include/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef UTILS_H
#define UTILS_H

#include "app_defs.h"

static u8 quantizerWhiteKeysLookupTable[] =
{
0, 2, 4, 5, 7, 9, 11, 12
};

static u8 quantizerBlackKeysLookupTable[] =
{
0, 1, 3, 0, 6, 8, 10, 0
};

static u8 quantizerUiKeyToPadLookupTable[] =
{
11, 22, 12, 23, 13, 14, 25, 15, 26, 16, 27, 17, 18
};

u8 isFlagOn32(u32 flags, u8 bit)
{
return ((flags & (1 << bit)) != 0);
}

u8 isFlagOn16(u16 flags, u8 bit)
{
return ((flags & (1 << bit)) != 0);
}

u8 isFlagOn8(u8 flags, u8 bit)
{
return ((flags & (1 << bit)) != 0);
}

u8 Pow(u8 base, u8 exponent)
{
u32 result = 1;
for(;;)
{
if (exponent & 1)
{
result *= base;
}
exponent >>= 1;
if(!exponent)
{
break;
}
base *= base;
}

return result;
}

#endif
Loading