Subversion Repositories svn.mios32

Rev

Rev 2548 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
134 tk 1
// $Id: seq_core.h 2633 2019-01-04 11:10:04Z tk $
2
/*
3
 * Header file for core routines
4
 *
5
 * ==========================================================================
6
 *
7
 *  Copyright (C) 2008 Thorsten Klose (tk@midibox.org)
8
 *  Licensed for personal non-commercial use only.
9
 *  All other rights reserved.
10
 *
11
 * ==========================================================================
12
 */
13
 
14
#ifndef _SEQ_CORE_H
15
#define _SEQ_CORE_H
16
 
17
/////////////////////////////////////////////////////////////////////////////
18
// Global definitions
19
/////////////////////////////////////////////////////////////////////////////
20
 
248 tk 21
#define SEQ_CORE_NUM_GROUPS            4
22
#define SEQ_CORE_NUM_TRACKS_PER_GROUP  4
23
#define SEQ_CORE_NUM_TRACKS            (SEQ_CORE_NUM_TRACKS_PER_GROUP*SEQ_CORE_NUM_GROUPS)
134 tk 24
 
491 tk 25
#define SEQ_CORE_NUM_BPM_PRESETS       16
134 tk 26
 
491 tk 27
 
134 tk 28
/////////////////////////////////////////////////////////////////////////////
29
// Global Types
30
/////////////////////////////////////////////////////////////////////////////
31
 
166 tk 32
typedef union {
1810 tk 33
  u32 ALL;
166 tk 34
  struct {
2448 tk 35
    u32 INIT_CC:8;
1810 tk 36
    u32 SYNCHED_PATTERN_CHANGE:1;
2523 tk 37
    u32 PATTERN_CHANGE_DONT_RESET_LATCHED_PC:1;
1810 tk 38
    u32 PASTE_CLR_ALL:1;
39
    u32 RATOPC:1;
40
    u32 SYNCHED_MUTE:1;
41
    u32 SYNCHED_UNMUTE:1;
2633 tk 42
    u32 UNMUTE_ON_PATTERN_CHANGE:1;
1810 tk 43
    u32 PATTERN_MIXER_MAP_COUPLING:1;
2101 tk 44
    u32 MIXER_LIVE_SEND:1;
2294 tk 45
    u32 INIT_WITH_TRIGGERS:1;
1810 tk 46
    u32 LIVE_LAYER_MUTE_STEPS:3; // 0=off, 1=permanent, 2..4 steps
166 tk 47
  };
240 tk 48
} seq_core_options_t;
49
 
50
typedef union {
848 tk 51
  u32 ALL;
240 tk 52
  struct {
848 tk 53
    u16 ref_step; // u16 instead of u8 to cover overrun on 256 steps per measure
2548 tk 54
    u16 ref_step_pattern; // independent reference step for pattern changes
1513 tk 55
    u16 ref_step_song; // reference step can be different in song mode if a guide track is used
1518 tk 56
    u16 reset_trkpos_req; // resets the track with the next step
134 tk 57
 
1515 tk 58
    u16 FIRST_CLK:1;
59
    u16 FORCE_REF_STEP_RESET:1;
60
    u16 METRONOME:1;
61
    u16 MANUAL_TRIGGER_STOP_REQ:1;
62
    u16 MANUAL_TRIGGER_STEP_REQ:1;
63
    u16 EXT_RESTART_REQ:1;
64
    u16 LOOP:1;
65
    u16 FOLLOW:1;
166 tk 66
  };
67
} seq_core_state_t;
68
 
240 tk 69
 
166 tk 70
typedef union {
1205 tk 71
  u16 ALL;
166 tk 72
  struct {
1205 tk 73
    u16 DISABLED:1;    // set if no pattern is selected to avoid editing of trigger/layer values
74
    u16 POS_RESET:1;   // set by MIDI handler if position of ARP/Transpose track should be reset
75
    u16 BACKWARD:1;    // if set, the track will be played in backward direction
76
    u16 FIRST_CLK:1;   // don't increment on the first clock event
77
    u16 REC_DONT_OVERWRITE_NEXT_STEP:1; // if a recorded step has been shifted forward
78
    u16 SYNC_MEASURE:1; // temporary request for synch to measure (used during pattern switching)
79
    u16 SUSTAINED:1;    // sustained note
2449 tk 80
    u16 ROBOSUSTAINED:1;  // events are temporarily sustained by the robotizer
1205 tk 81
    u16 STRETCHED_GL:1; // stretched gatelength
82
    u16 MANUAL_STEP_REQ:1; // manual_step should be copied to step
2230 tk 83
    u16 CANCEL_SUSTAIN_REQ:1; // cancel ongoing sustain
2465 tk 84
    u16 TRIGGER_NEXT_STEP_REQ:1; // to continue with next step in STEP_TRG mode; flag is set by transposer
166 tk 85
  };
86
} seq_core_trk_state_t;
87
 
88
 
89
typedef struct seq_core_trk_t {
90
  seq_core_trk_state_t state;            // various status flags (see structure definition above)
316 tk 91
  char                 name[81];         // the track name (80 chars + zero terminator)
338 tk 92
  u8                   step;             // current track position
2159 tk 93
  u8                   bar;              // bar counter
344 tk 94
  u16                  step_length;      // length of the current step
95
  u32                  timestamp_next_step; // timestamp at which the next step will be played
96
  u32                  timestamp_next_step_ref; // timestamp of next step w/o groove delay
717 tk 97
  u32                  glide_notes[4];   // 128 bit to store notes in glide state
338 tk 98
  u16                  bpm_tick_delay;   // delay of current step
166 tk 99
  u8                   step_replay_ctr;  // step replay counter
100
  u8                   step_saved;       // for replay mechanism
1205 tk 101
  u8                   manual_step;      // requested step in manual trigger mode
166 tk 102
  u8                   step_fwd_ctr;     // step forward counter
593 tk 103
  u8                   step_interval_ctr; // step interval counter
104
  u8                   step_repeat_ctr;  // step repeat counter
105
  u8                   step_skip_ctr;    // step skip counter
591 tk 106
  u16                  layer_muted;      // separate layer mutes
1806 tk 107
  u16                  layer_muted_from_midi; // temporary layer mutes on incoming (and matching) events
108
  u16                  layer_muted_from_midi_next; // will be taken over with the next step
1809 tk 109
  u8                   lfo_cc_muted_from_midi:1; // the same for the LFO CC
110
  u8                   lfo_cc_muted_from_midi_next:1;
166 tk 111
  u8                   arp_pos;          // arpeggiator position
184 tk 112
  u8                   vu_meter;         // for visualisation in mute menu
419 tk 113
  u32                  rec_timestamp;    // for recording function
114
  u8                   rec_poly_ctr;     // for recording function
828 tk 115
  u8                   play_section;     // selects the section which should be played. If -1, no section selection
1859 tk 116
  u8                   fx_midi_ctr;      // Fx MIDI channel counter
166 tk 117
} seq_core_trk_t;
118
 
119
 
168 tk 120
typedef enum {
121
  SEQ_CORE_TRKMODE_Off,
122
  SEQ_CORE_TRKMODE_Normal,
123
  SEQ_CORE_TRKMODE_Transpose,
124
  SEQ_CORE_TRKMODE_Arpeggiator
125
} seq_core_trk_playmode_t;
126
 
1023 tk 127
typedef union {
128
  u8 ALL;
129
  struct {
130
    u8 bus:2;
131
  };
132
} seq_core_busasg_t;
168 tk 133
 
134
typedef enum {
135
  SEQ_CORE_TRKDIR_Forward,
136
  SEQ_CORE_TRKDIR_Backward,
137
  SEQ_CORE_TRKDIR_PingPong,
138
  SEQ_CORE_TRKDIR_Pendulum,
139
  SEQ_CORE_TRKDIR_Random_Dir,
140
  SEQ_CORE_TRKDIR_Random_Step,
141
  SEQ_CORE_TRKDIR_Random_D_S
142
} seq_core_trk_dir_t;
143
 
1206 tk 144
typedef enum {
145
  SEQ_CORE_SLAVECLK_MUTE_Off,
146
  SEQ_CORE_SLAVECLK_MUTE_Enabled,
147
  SEQ_CORE_SLAVECLK_MUTE_OffOnNextMeasure,
148
} seq_core_slaveclk_mute_t;
168 tk 149
 
150
// shared mode parameters (each track holds another value)
151
typedef union {
152
  struct {
153
    u8 chain; // stored in track #1
154
  };
155
  struct {
156
    u8 morph_pattern; // stored in track #2
157
  };
158
  struct {
159
    u8 scale; // stored in track #3
160
  };
161
  struct {
162
    u8 scale_root; // stored in track #4
163
  };
164
} seq_core_shared_t;
165
 
166
 
167
typedef union {
848 tk 168
  u8 ALL;
168 tk 169
  struct {
848 tk 170
    u8 UNSORTED:1;     // sort mode for arpeggiator
171
    u8 HOLD:1;         // hold mode for transposer/arpeggiator
172
    u8 RESTART:1;      // track restart on key press
173
    u8 FORCE_SCALE:1;  // note values are forced to scale
2124 borfo 174
    u8 SUSTAIN:1;      // events are sustained because SUSTAIN is set as active on the track
2449 tk 175
    u8 FIRST_NOTE:1;   // transposer takes the first played note instead of the last one
2465 tk 176
    u8 STEP_TRG:1;     // next step has to be triggered from transposer (e.g. via loopback track or external keyboard)
168 tk 177
  };
178
} seq_core_trkmode_flags_t;
179
 
1859 tk 180
typedef enum {
181
  SEQ_CORE_FX_MIDI_MODE_BEH_Forward,   // forward to all channels
182
  SEQ_CORE_FX_MIDI_MODE_BEH_Alternate, // alternate between channels
1868 tk 183
  SEQ_CORE_FX_MIDI_MODE_BEH_AlternateSynchedEcho, // Alternate only on echo taps
1859 tk 184
  SEQ_CORE_FX_MIDI_MODE_BEH_Random,    // forward to random channel
185
} seq_core_fx_midi_mode_beh_t;
168 tk 186
 
187
typedef union {
1859 tk 188
  u8 ALL;
189
  struct {
190
    u8 beh:3;           // Fx behaviour (seq_core_fx_midi_mode_beh_t)
191
    u8 fwd_non_notes:1; // forward CCs, PitchBender, Channel Pressure, Program Change to all Fx channels
192
  };
193
} seq_core_fx_midi_mode_t;
194
 
195
typedef union {
848 tk 196
  u16 ALL;
168 tk 197
  struct {
338 tk 198
    u8 value;                // clock divider value
1883 tk 199
    u8 flags;                // combines all flags (for CC access)
168 tk 200
  };
201
  struct {
868 tk 202
    u8 value_dummy;          // clock divider value
1883 tk 203
    u8 SYNCH_TO_MEASURE:1;   // synch to globally selectable measure
204
    u8 TRIPLETS:1;           // play triplets
205
    u8 MANUAL:1;             // clock to next step only on manual requests (or via Step CC)
168 tk 206
  };
207
} seq_core_clkdiv_t;
208
 
209
 
596 tk 210
#define SEQ_CORE_NUM_LOOP_MODES 4
211
typedef enum {
212
  SEQ_CORE_LOOP_MODE_ALL_TRACKS_VIEW,
213
  SEQ_CORE_LOOP_MODE_ALL_TRACKS_STATIC,
214
  SEQ_CORE_LOOP_MODE_SELECTED_TRACK_VIEW,
215
  SEQ_CORE_LOOP_MODE_SELECTED_TRACK_STATIC,
216
} seq_core_loop_mode_t;
217
 
218
 
134 tk 219
/////////////////////////////////////////////////////////////////////////////
220
// Prototypes
221
/////////////////////////////////////////////////////////////////////////////
222
 
1219 tk 223
#include "seq_cc.h"
224
#include "seq_layer.h"
2125 borfo 225
#include "seq_robotize.h"
1859 tk 226
#include <seq_midi_out.h>
1219 tk 227
 
134 tk 228
extern s32 SEQ_CORE_Init(u32 mode);
229
 
2545 tk 230
extern s32 SEQ_CORE_ScheduleEvent(u8 track, seq_core_trk_t *t, seq_cc_trk_t *tcc, mios32_midi_package_t midi_package, seq_midi_out_event_type_t event_type, u32 timestamp, u32 len, u8 is_echo, seq_robotize_flags_t robotize_flags);
1859 tk 231
 
1145 tk 232
extern s32 SEQ_CORE_Reset(u32 bpm_start);
759 tk 233
extern s32 SEQ_CORE_PlayOffEvents(void);
1145 tk 234
extern s32 SEQ_CORE_Tick(u32 bpm_tick, s8 export_track, u8 mute_nonloopback_tracks);
134 tk 235
 
159 tk 236
extern s32 SEQ_CORE_Handler(void);
237
 
2435 tk 238
extern s32 SEQ_CORE_FTS_GetScaleAndRoot(u8 track, u8 step, u8 instrument, seq_cc_trk_t *tcc, u8 *scale, u8 *root_selection, u8 *root);
254 tk 239
 
747 tk 240
extern const char *SEQ_CORE_Echo_GetDelayModeName(u8 delay_mode);
1121 tk 241
extern u8 SEQ_CORE_Echo_MapUserToInternal(u8 user_value);
242
extern u8 SEQ_CORE_Echo_MapInternalToUser(u8 internal_value);
747 tk 243
 
2436 tk 244
extern s32 SEQ_CORE_Transpose(u8 track, u8 instrument, seq_core_trk_t *t, seq_cc_trk_t *tcc, mios32_midi_package_t *p);
1219 tk 245
extern s32 SEQ_CORE_Limit(seq_core_trk_t *t, seq_cc_trk_t *tcc, seq_layer_evnt_t *e);
2127 borfo 246
 
2435 tk 247
extern s32 SEQ_CORE_Echo(u8 track, u8 instrument, seq_core_trk_t *t, seq_cc_trk_t *tcc, mios32_midi_package_t p, u32 bpm_tick, u32 gatelength, seq_robotize_flags_t robotize_flags);
1219 tk 248
 
1205 tk 249
extern s32 SEQ_CORE_ResetTrkPosAll(void);
1883 tk 250
extern s32 SEQ_CORE_SetTrkPos(u8 track, u8 value, u8 scale_value);
1205 tk 251
 
600 tk 252
extern s32 SEQ_CORE_ManualTrigger(u8 step);
1315 tk 253
extern s32 SEQ_CORE_ManualSynchToMeasure(u16 tracks);
600 tk 254
 
2465 tk 255
extern s32 SEQ_CORE_StepTriggerReq(u8 bus);
256
 
1806 tk 257
extern s32 SEQ_CORE_NotifyIncomingMIDIEvent(u8 track, mios32_midi_package_t p);
258
 
184 tk 259
extern s32 SEQ_CORE_AddForwardDelay(u16 delay_ms);
159 tk 260
 
491 tk 261
extern s32 SEQ_CORE_BPM_Update(float bpm, float sweep_ramp);
262
extern s32 SEQ_CORE_BPM_SweepHandler(void);
184 tk 263
 
607 tk 264
extern s32 SEQ_CORE_Scrub(s32 incrementer);
491 tk 265
 
2230 tk 266
extern s32 SEQ_CORE_CancelSustainedNotes(u8 track);
267
 
1746 tk 268
extern u8 SEQ_CORE_TrimNote(s32 note, u8 lower, u8 upper);
607 tk 269
 
1746 tk 270
 
134 tk 271
/////////////////////////////////////////////////////////////////////////////
272
// Export global variables
273
/////////////////////////////////////////////////////////////////////////////
274
 
240 tk 275
extern seq_core_options_t seq_core_options;
276
extern u8 seq_core_steps_per_measure;
758 tk 277
extern u8 seq_core_steps_per_pattern;
254 tk 278
 
1015 tk 279
extern u16 seq_core_trk_muted;
1261 tk 280
extern u16 seq_core_trk_synched_mute;
281
extern u16 seq_core_trk_synched_unmute;
1206 tk 282
extern seq_core_slaveclk_mute_t seq_core_slaveclk_mute;
2110 tk 283
extern u16 seq_core_trk_soloed;
1015 tk 284
 
751 tk 285
extern u8 seq_core_step_update_req;
286
 
254 tk 287
extern u8 seq_core_global_scale;
288
extern u8 seq_core_global_scale_root_selection;
289
extern u8 seq_core_keyb_scale_root;
290
 
1320 tk 291
extern u8 seq_core_global_transpose_enabled;
292
 
491 tk 293
extern u8 seq_core_bpm_preset_num;
294
extern float seq_core_bpm_preset_tempo[SEQ_CORE_NUM_BPM_PRESETS];
295
extern float seq_core_bpm_preset_ramp[SEQ_CORE_NUM_BPM_PRESETS];
296
 
524 tk 297
extern mios32_midi_port_t seq_core_metronome_port;
298
extern u8 seq_core_metronome_chn;
299
extern u8 seq_core_metronome_note_m;
300
extern u8 seq_core_metronome_note_b;
491 tk 301
 
2545 tk 302
extern mios32_midi_port_t seq_core_shadow_out_port;
303
extern u8 seq_core_shadow_out_chn;
304
 
166 tk 305
extern seq_core_state_t seq_core_state;
306
extern seq_core_trk_t seq_core_trk[SEQ_CORE_NUM_TRACKS];
134 tk 307
 
596 tk 308
extern seq_core_loop_mode_t seq_core_glb_loop_mode;
309
extern u8 seq_core_glb_loop_offset;
310
extern u8 seq_core_glb_loop_steps;
311
 
134 tk 312
#endif /* _SEQ_CORE_H */