Subversion Repositories svn.mios32

Rev

Rev 2572 | Rev 2594 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2593 hawkeye 1
// LoopA Core Logic
2
// (c) Hawkeye 2015-2018
2184 hawkeye 3
 
4
#define DEBUG_MSG MIOS32_MIDI_SendDebugMessage
5
 
2571 hawkeye 6
#define TRACKS 6
7
#define SCENES 6
8
 
2184 hawkeye 9
// Current "menu" position in app
10
 
2571 hawkeye 11
// --- Consts ---
12
#define MAXNOTES 256 // per clip, * TRACKS * SCENES for total note storage
13
 
14
#define PAGES 6
15
enum LoopaPage
16
{
2593 hawkeye 17
   PAGE_MUTE,
18
   PAGE_CLIP,
19
   PAGE_NOTES,
2571 hawkeye 20
   PAGE_TRACK,
21
   PAGE_DISK,
2593 hawkeye 22
   PAGE_TEMPO,
23
   PAGE_FX,
24
   PAGE_METRONOME,
25
   PAGE_ROUTER,
26
   PAGE_SETUP
2571 hawkeye 27
};
28
 
29
enum Command
30
{
31
   COMMAND_NONE,
2593 hawkeye 32
   COMMAND_CLIPLEN, COMMAND_QUANTIZE, COMMAND_TRANSPOSE, COMMAND_SCROLL, COMMAND_STRETCH, COMMAND_CLEAR,  // PAGE_CLIP
2571 hawkeye 33
   COMMAND_POSITION, COMMAND_NOTE, COMMAND_VELOCITY, COMMAND_LENGTH, COMMAND_DELETENOTE, // PAGE_NOTES
34
   COMMAND_PORT, COMMAND_CHANNEL,                                         // PAGE_MIDI
35
   COMMAND_SAVE, COMMAND_LOAD, COMMAND_NEW,                               // PAGE_DISK
2593 hawkeye 36
   COMMAND_BPM, COMMAND_BPMFLASH                                          // PAGE_TEMPO
2571 hawkeye 37
};
38
 
2593 hawkeye 39
enum KeyIcon
40
{
41
   KEYICON_MENU_INVERTED,
42
   KEYICON_MENU,
43
   KEYICON_MUTE_INVERTED,
44
   KEYICON_MUTE,
45
   KEYICON_CLIP_INVERTED,
46
   KEYICON_CLIP,
47
   KEYICON_FX_INVERTED,
48
   KEYICON_FX,
49
   KEYICON_TRACK_INVERTED,
50
   KEYICON_TRACK,
51
   KEYICON_NOTES_INVERTED,
52
   KEYICON_NOTES,
53
   KEYICON_DISK_INVERTED,
54
   KEYICON_DISK,
55
   KEYICON_METRONOME_INVERTED,
56
   KEYICON_METRONOME,
57
   KEYICON_TEMPO_INVERTED,
58
   KEYICON_TEMPO,
59
   KEYICON_ROUTER_INVERTED,
60
   KEYICON_ROUTER,
61
   KEYICON_SETUP_INVERTED,
62
   KEYICON_SETUP,
63
   KEYICON_SHIFT_INVERTED,
64
   KEYICON_SHIFT,
65
   KEYICON_HELP_INVERTED,
66
   KEYICON_HELP,
67
   KEYICON_ABOUT_INVERTED,
68
   KEYICON_ABOUT,
69
   KEYICON_DISPLAY_INVERTED,
70
   KEYICON_DISPLAY,
71
   KEYICON_MIDIMONITOR_INVERTED,
72
   KEYICON_MIDIMONITOR
73
};
74
 
2571 hawkeye 75
// --- Data structures ---
76
 
77
typedef struct
78
{
79
   u16 tick;
80
   u16 length;
81
   u8 note;
82
   u8 velocity;
83
} NoteData;
84
 
85
 
2185 hawkeye 86
// --- Export global variables ---
2184 hawkeye 87
 
2571 hawkeye 88
extern u32 tick_;                // global seq tick
89
extern u16 bpm_;                 // bpm
2185 hawkeye 90
extern u16 sessionNumber_;       // currently active session number (directories will be auto-created)
2571 hawkeye 91
extern u8 sessionExistsOnDisk_;  // is the currently selected session number already saved on disk/sd card
92
extern enum LoopaPage page_;     // currently active page/view
93
extern enum Command command_;    // currently active command
2184 hawkeye 94
 
2571 hawkeye 95
extern u8 activeTrack_;          // currently active track number (0-5)
96
extern u8 activeScene_;          // currently active scene number (0-15)
97
extern u16 activeNote_;          // currently active edited note number, when in noteroll editor
98
extern u16 beatLoopSteps_;       // number of steps for one beatloop (adjustable)
99
extern u8 isRecording_;          // set, if currently recording to the selected clip
100
extern u8 oledBeatFlashState_;   // 0: don't flash, 1: flash slightly (normal 1/4th note), 2: flash intensively (after four 1/4th notes or 16 steps)
2185 hawkeye 101
extern u16 seqPlayEnabledPorts_;
102
extern u16 seqRecEnabledPorts_;
103
 
2571 hawkeye 104
extern u8 trackMute_[TRACKS];    // mute state of each track
105
extern u8 trackMidiPort_[TRACKS];
106
extern u8 trackMidiChannel_[TRACKS];
2185 hawkeye 107
 
2571 hawkeye 108
extern u16 clipSteps_[TRACKS][SCENES];     // number of steps for each clip
109
extern u32 clipQuantize_[TRACKS][SCENES];  // brings all clip notes close to the specified timing, e.g. qunatize = 4 - close to 4th notes, 16th = quantize to step, ...
110
extern s8 clipTranspose_[TRACKS][SCENES];
111
extern s16 clipScroll_[TRACKS][SCENES];
112
extern u8 clipStretch_[TRACKS][SCENES];    // 1: compress to 1/16th, 2: compress to 1/8th ... 16: no stretch, 32: expand 2x, 64: expand 4x, 128: expand 8x
113
 
114
NoteData clipNotes_[TRACKS][SCENES][MAXNOTES]; // clip note data storage of active scene (chained list, note start time and length/velocity)
115
extern u16 clipNotesSize_[TRACKS][SCENES];     // Active number of notes in use for that clip
116
 
117
// --- Secondary clip data (not on disk) ---
118
extern u8 trackMuteToggleRequested_[TRACKS]; // 1: perform a mute/unmute toggle of the clip at the next beatstep (synced mute/unmute)
119
extern u8 sceneChangeRequested_;             // If != activeScene_, this will be the scene we are changing to
120
extern u16 clipActiveNote_[TRACKS][SCENES];  // currently active edited note number, when in noteroll editor
121
 
122
// Help function: convert tick number to step number
123
u16 tickToStep(u32 tick);
124
 
125
// Help function: convert step number to tick number
126
u32 stepToTick(u16 step);
127
 
128
// Bound tick to clip steps
129
u32 boundTickToClipSteps(u32 tick, u8 clip);
130
 
131
// Quantize a tick time event
132
u32 quantize(u32 tick, u32 quantizeMeasure, u32 clipLengthInTicks);
133
 
134
// Transform (stretch and scroll) and then quantize a note in a clip
135
s32 quantizeTransform(u8 clip, u16 noteNumber);
136
 
137
// Get the clip length in ticks
138
u32 getClipLengthInTicks(u8 clip);
139
 
140
// Update the six general purpose LED states
141
void updateGPLeds();
142
 
2184 hawkeye 143
// First callback from app - render Loopa Startup logo on screen
144
void loopaStartup();
145
 
2185 hawkeye 146
// Initialize Loopa SEQ
147
s32 seqInit();
148
 
149
// This main sequencer handler is called periodically to poll the clock/current tick from BPM generator
150
s32 seqHandler(void);
151
 
2184 hawkeye 152
// SD Card Available, initialize
153
void loopaSDCardAvailable();
154
 
155
// A buttonpress has occured
156
void loopaButtonPressed(s32 pin);
157
 
2593 hawkeye 158
// A button release has occured
159
void loopaButtonReleased(s32 pin);
160
 
2184 hawkeye 161
// An encoder has been turned
162
void loopaEncoderTurned(s32 encoder, s32 incrementer);
163
 
2571 hawkeye 164
// Record midi event
165
void loopaRecord(mios32_midi_port_t port, mios32_midi_package_t midi_package);
2184 hawkeye 166
 
167
 
168
 
169
 
170