Subversion Repositories svn.mios32

Rev

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

Rev Author Line No. Line
174 tk 1
// $Id: seq_layer.c 2635 2019-01-06 17:14:01Z tk $
2
/*
3
 * Sequencer Parameter Layer 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
/////////////////////////////////////////////////////////////////////////////
15
// Include files
16
/////////////////////////////////////////////////////////////////////////////
17
 
18
#include <mios32.h>
2551 tk 19
#include <string.h>
1771 tk 20
#include "tasks.h"
174 tk 21
 
1391 tk 22
#include "seq_bpm.h"
174 tk 23
#include "seq_layer.h"
24
#include "seq_core.h"
25
#include "seq_cc.h"
26
#include "seq_trg.h"
27
#include "seq_par.h"
288 tk 28
#include "seq_chord.h"
419 tk 29
#include "seq_record.h"
2149 tk 30
#include "seq_live.h"
333 tk 31
#include "seq_ui.h"
607 tk 32
#include "seq_morph.h"
2522 tk 33
#include "seq_random.h"
174 tk 34
 
35
 
36
/////////////////////////////////////////////////////////////////////////////
333 tk 37
// Global variables
38
/////////////////////////////////////////////////////////////////////////////
39
 
40
// to display activity of selected track in trigger/parameter selection page
41
u8 seq_layer_vu_meter[16];
42
 
2552 tk 43
#ifdef MBSEQV4P
44
// Drum CC configuration
45
u8 seq_layer_drum_cc[16][4]; // up to 4 parameter layers per drum
46
#endif
47
 
48
 
333 tk 49
/////////////////////////////////////////////////////////////////////////////
174 tk 50
// Local definitions and arrays
51
/////////////////////////////////////////////////////////////////////////////
52
 
53
// preset table - each entry contains the initial track configuration and the step settings
54
// EVNT0 and CHN won't be overwritten
55
// for four steps (they are copied to all other 4step groups)
56
// structure of track settings matches with the SEQ_TRKRECORD in app_defines.h
57
 
58
// parameters which will be reset to the given values in all event modes
59
static const u8 seq_layer_preset_table_static[][2] = {
60
  // parameter             value
61
  { SEQ_CC_MODE,           SEQ_CORE_TRKMODE_Normal },
337 tk 62
  { SEQ_CC_MODE_FLAGS,     0x03 },
1023 tk 63
  { SEQ_CC_BUSASG,         0x00 },
174 tk 64
  { SEQ_CC_DIRECTION,      0x00 },
65
  { SEQ_CC_STEPS_REPLAY,   0x00 },
66
  { SEQ_CC_STEPS_FORWARD,  0x00 },
67
  { SEQ_CC_STEPS_JMPBCK,   0x00 },
593 tk 68
  { SEQ_CC_STEPS_REPEAT,   0x00 },
69
  { SEQ_CC_STEPS_SKIP,     0x00 },
652 tk 70
  { SEQ_CC_STEPS_RS_INTERVAL,0x03 },
338 tk 71
  { SEQ_CC_CLK_DIVIDER,    0x0f },
178 tk 72
  { SEQ_CC_CLKDIV_FLAGS,   0x00 },
174 tk 73
  { SEQ_CC_LENGTH,         0x0f },
74
  { SEQ_CC_LOOP,           0x00 },
75
  { SEQ_CC_TRANSPOSE_SEMI, 0x00 },
76
  { SEQ_CC_TRANSPOSE_OCT,  0x00 },
77
  { SEQ_CC_GROOVE_VALUE,   0x00 },
78
  { SEQ_CC_GROOVE_STYLE,   0x00 },
79
  { SEQ_CC_MORPH_MODE,     0x00 },
607 tk 80
  { SEQ_CC_MORPH_DST,      0x00 },
174 tk 81
  { SEQ_CC_HUMANIZE_VALUE, 0x00 },
82
  { SEQ_CC_HUMANIZE_MODE,  0x00 },
318 tk 83
  { SEQ_CC_ECHO_REPEATS,   0x00 },
84
  { SEQ_CC_ECHO_DELAY,     0x07 }, // 1/8
85
  { SEQ_CC_ECHO_VELOCITY,  15 }, // 75%
86
  { SEQ_CC_ECHO_FB_VELOCITY, 15 }, // 75%
87
  { SEQ_CC_ECHO_FB_NOTE,   24 }, // +0
88
  { SEQ_CC_ECHO_FB_GATELENGTH, 20 }, // 100%
89
  { SEQ_CC_ECHO_FB_TICKS,  20 }, // 100%
599 tk 90
  { SEQ_CC_LFO_WAVEFORM,   0x00 }, // off
91
  { SEQ_CC_LFO_AMPLITUDE,  128 + 64 },
92
  { SEQ_CC_LFO_PHASE,      0 },
93
  { SEQ_CC_LFO_STEPS,      15 },
94
  { SEQ_CC_LFO_STEPS_RST,  15 },
95
  { SEQ_CC_LFO_ENABLE_FLAGS, 0 },
96
  { SEQ_CC_LFO_CC,         0 },
97
  { SEQ_CC_LFO_CC_OFFSET,  64 },
98
  { SEQ_CC_LFO_CC_PPQN,    6 }, // 96 ppqn
600 tk 99
  { SEQ_CC_LIMIT_LOWER,    0 },
100
  { SEQ_CC_LIMIT_UPPER,    0 },
174 tk 101
  { 0xff,                  0xff } // end marker
102
};
103
 
104
 
2635 tk 105
// initial drum notes (can be customized in /PRESETS/TRKDRUMS.V4P)
106
static u8 seq_layer_preset_table_drum_notes[16] = {
984 tk 107
  0x24, // BD
108
  0x26, // SD
109
  0x2a, // CH
110
  0x2c, // PH
111
  0x2e, // OH
112
  0x46, // MA
113
  0x27, // CP
114
  0x37, // CY
115
  0x29, // LT
116
  0x2b, // MT
117
  0x2f, // HT
118
  0x4b, // RS
119
  0x38, // CB
120
  0x2c, // Smp1
121
  0x3c, // Smp2
122
  0x3d  // Smp3
174 tk 123
};
124
 
125
 
126
/////////////////////////////////////////////////////////////////////////////
1313 tk 127
// local variables
128
/////////////////////////////////////////////////////////////////////////////
129
static u8 pb_last_value[SEQ_CORE_NUM_TRACKS];
1422 tk 130
static u8 pc_last_value[SEQ_CORE_NUM_TRACKS];
2389 tk 131
static u8 at_last_value[SEQ_CORE_NUM_TRACKS];
2551 tk 132
#ifdef MBSEQV4P
133
static u8 cc_last_value[SEQ_CORE_NUM_TRACKS][16][4]; // up to 4 parameter layers per drum
134
#else
135
static u8 cc_last_value[SEQ_CORE_NUM_TRACKS][1][16];
136
#endif
1313 tk 137
 
2092 tk 138
static u8 track_pc_last_value[SEQ_CORE_NUM_TRACKS];
139
static u8 track_bank_h_last_value[SEQ_CORE_NUM_TRACKS];
140
static u8 track_bank_l_last_value[SEQ_CORE_NUM_TRACKS];
1313 tk 141
 
2092 tk 142
 
1313 tk 143
/////////////////////////////////////////////////////////////////////////////
174 tk 144
// Initialisation
145
/////////////////////////////////////////////////////////////////////////////
146
s32 SEQ_LAYER_Init(u32 mode)
147
{
318 tk 148
  // initialize parameter/trigger layers and CCs
149
  SEQ_PAR_Init(0);
150
  SEQ_TRG_Init(0);
151
  SEQ_CC_Init(0);
152
 
1313 tk 153
  SEQ_LAYER_ResetLatchedValues();
2092 tk 154
  SEQ_LAYER_ResetTrackPCBankLatchedValues();
1313 tk 155
 
318 tk 156
  // copy preset into all tracks
157
  u8 track;
158
  for(track=0; track<16; ++track) {
159
    u8 only_layers = 0;
1316 tk 160
#ifndef MBSEQV4L
318 tk 161
    u8 all_triggers_cleared = (track >= 1) ? 1 : 0; // triggers only set for first track
1316 tk 162
#else
163
    u8 all_triggers_cleared = 0; // trigger handling for all tracks
164
#endif
335 tk 165
    u8 init_assignments = 1;
166
    SEQ_LAYER_CopyPreset(track, only_layers, all_triggers_cleared, init_assignments);
318 tk 167
  }
168
 
2552 tk 169
#ifdef MBSEQV4P
170
  // initial Drum CC assignments
171
  u8 drum;
172
  for(drum=0; drum<16; ++drum) {
173
    u8 par_layer;
174
    for(par_layer=0; par_layer<4; ++par_layer) {
175
      seq_layer_drum_cc[drum][par_layer] = 16 + par_layer*16 + drum;
176
    }
177
  }
178
#endif
318 tk 179
 
288 tk 180
  SEQ_CHORD_Init(0);
181
 
174 tk 182
  return 0; // no error
183
}
184
 
185
 
186
/////////////////////////////////////////////////////////////////////////////
1422 tk 187
// This function clears the latched pitchbender, program change and CC values
1313 tk 188
/////////////////////////////////////////////////////////////////////////////
189
s32 SEQ_LAYER_ResetLatchedValues(void)
190
{
191
  u8 track;
192
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
193
    pb_last_value[track] = 0xff; // invalid value - PB value will be send in any case
1422 tk 194
    pc_last_value[track] = 0xff; // invalid value - PC value will be send in any case
2389 tk 195
    at_last_value[track] = 0xff; // invalid value - AT value will be send in any case
1313 tk 196
 
2551 tk 197
    memset(cc_last_value, 0xff, sizeof(cc_last_value)); // invalid value - CC value will be send in any case
1313 tk 198
  }
199
 
200
  return 0; // no error
201
}
202
 
203
 
204
/////////////////////////////////////////////////////////////////////////////
2092 tk 205
// This function clears the latched track based program/bank change values
206
/////////////////////////////////////////////////////////////////////////////
207
s32 SEQ_LAYER_ResetTrackPCBankLatchedValues(void)
208
{
209
  u8 track;
210
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
211
    // invalid value - value will be send in any case
212
    track_pc_last_value[track] = 0xff;
213
    track_bank_h_last_value[track] = 0xff;
214
    track_bank_l_last_value[track] = 0xff;
215
  }
216
 
217
  return 0; // no error
218
}
219
 
220
/////////////////////////////////////////////////////////////////////////////
221
// This function sends the track based program/bank change values
222
/////////////////////////////////////////////////////////////////////////////
223
s32 SEQ_LAYER_SendPCBankValues(u8 track, u8 force, u8 send_now)
224
{
225
  seq_cc_trk_t *tcc = &seq_cc_trk[track];
226
 
227
  mios32_midi_port_t port = tcc->midi_port;
228
  mios32_midi_chn_t chn = tcc->midi_chn;
229
 
230
  {
231
    if( force || (tcc->midi_bank_l && track_bank_l_last_value[track] != (tcc->midi_bank_l-1)) )
232
      track_bank_l_last_value[track] = tcc->midi_bank_l;
233
    if( send_now && tcc->midi_bank_l )
234
      MIOS32_MIDI_SendCC(port, chn, 0x20, tcc->midi_bank_l - 1);
235
  }
236
 
237
  {
238
    if( force || (tcc->midi_bank_h && track_bank_h_last_value[track] != (tcc->midi_bank_h-1)) )
239
      track_bank_h_last_value[track] = tcc->midi_bank_h - 1;
240
    if( send_now && tcc->midi_bank_h )
241
      MIOS32_MIDI_SendCC(port, chn, 0x00, tcc->midi_bank_h - 1);
242
  }
243
 
244
  {
245
    if( force || (tcc->midi_pc && track_pc_last_value[track] != (tcc->midi_pc-1)) )
246
      track_pc_last_value[track] = tcc->midi_pc - 1;
247
    if( send_now && tcc->midi_pc )
248
      MIOS32_MIDI_SendProgramChange(port, chn, tcc->midi_pc - 1);
249
  }
250
 
251
  return 0;
252
}
253
 
254
 
255
/////////////////////////////////////////////////////////////////////////////
2635 tk 256
// This function allows to change the default drum note
257
/////////////////////////////////////////////////////////////////////////////
258
s32 SEQ_LAYER_PresetDrumNoteSet(u8 num, u8 note)
259
{
260
  if( num >= 16 ) {
261
    return -1; // invalid note
262
  }
263
 
264
  seq_layer_preset_table_drum_notes[num] = note;
265
 
266
  return 0; // no error
267
}
268
 
269
 
270
s32 SEQ_LAYER_PresetDrumNoteGet(u8 num)
271
{
272
  if( num >= 16 ) {
273
    return -1; // invalid note
274
  }
275
 
276
  return seq_layer_preset_table_drum_notes[num];
277
}
278
 
279
 
280
/////////////////////////////////////////////////////////////////////////////
747 tk 281
// This function returns a string to the event mode name (5 chars)
282
/////////////////////////////////////////////////////////////////////////////
774 tk 283
// Note: newer gcc versions don't allow to return a "const" parameter, therefore
284
// this array is declared outside the SEQ_LAYER_GetEvntModeName() function
1316 tk 285
static const char event_mode_str[5+1][7] = { "Note ", "Chord", " CC  ", "Drum ", "Comb ", "?????" };
774 tk 286
 
747 tk 287
const char *SEQ_LAYER_GetEvntModeName(seq_event_mode_t event_mode)
288
{
1316 tk 289
  if( event_mode < 5 )
747 tk 290
    return event_mode_str[event_mode];
291
  else
1211 tk 292
    return event_mode_str[5];
747 tk 293
}
294
 
295
 
296
/////////////////////////////////////////////////////////////////////////////
176 tk 297
// This function returns the layer_evnt_t information based on given
323 tk 298
// layer (used for visualisation purposes)
176 tk 299
/////////////////////////////////////////////////////////////////////////////
336 tk 300
s32 SEQ_LAYER_GetEvntOfLayer(u8 track, u16 step, u8 layer, u8 instrument, seq_layer_evnt_t *layer_event)
176 tk 301
{
302
  s32 number_of_events = 0;
174 tk 303
 
176 tk 304
  seq_cc_trk_t *tcc = &seq_cc_trk[track];
2551 tk 305
#ifdef MBSEQV4P
2552 tk 306
  seq_layer_evnt_t layer_events[83];
2551 tk 307
  number_of_events = SEQ_LAYER_GetEventsPlus(track, step, layer_events, 1);
308
#else
309
  seq_layer_evnt_t layer_events[16];
457 tk 310
  number_of_events = SEQ_LAYER_GetEvents(track, step, layer_events, 1);
2551 tk 311
#endif
174 tk 312
 
176 tk 313
  if( number_of_events <= 0 ) {
314
    // fill with dummy data
315
    layer_event->midi_package.ALL = 0;
178 tk 316
    layer_event->len = -1;
176 tk 317
 
318
    return -1; // no valid event
319
  }
320
 
419 tk 321
  // search layer to which the event belongs to
323 tk 322
  u8 event_num;
323
  if( tcc->event_mode == SEQ_EVENT_MODE_Drum ) {
419 tk 324
    for(event_num=0; event_num<number_of_events; ++event_num) {
325
      if( instrument == layer_events[event_num].layer_tag )
326
    break;
327
    }
323 tk 328
  } else {
419 tk 329
    for(event_num=0; event_num<number_of_events; ++event_num) {
330
      if( layer == layer_events[event_num].layer_tag )
331
    break;
332
    }
323 tk 333
  }
334
 
419 tk 335
  if( event_num >= number_of_events )
336
    event_num = 0;
337
 
176 tk 338
  layer_event->midi_package = layer_events[event_num].midi_package;
339
  layer_event->len = layer_events[event_num].len;
419 tk 340
  layer_event->layer_tag = layer;
176 tk 341
 
342
  return 0; // no error
343
}
344
 
323 tk 345
 
174 tk 346
/////////////////////////////////////////////////////////////////////////////
419 tk 347
// Returns all events of a selected step
2551 tk 348
// Note: MBSEQV4P supports CCs on drum tracks, therefore we've to support
349
// +64 events which can be generated at once
350
// In order to ensure that layer_events array is prepared for this, we give
351
// the function a dedicated name for this case
174 tk 352
/////////////////////////////////////////////////////////////////////////////
2551 tk 353
#ifdef MBSEQV4P
2552 tk 354
s32 SEQ_LAYER_GetEventsPlus(u8 track, u16 step, seq_layer_evnt_t layer_events[83], u8 insert_empty_notes)
2551 tk 355
#else
457 tk 356
s32 SEQ_LAYER_GetEvents(u8 track, u16 step, seq_layer_evnt_t layer_events[16], u8 insert_empty_notes)
2551 tk 357
#endif
174 tk 358
{
359
  seq_cc_trk_t *tcc = &seq_cc_trk[track];
1806 tk 360
  u16 layer_muted = seq_core_trk[track].layer_muted | seq_core_trk[track].layer_muted_from_midi;
323 tk 361
  u8 num_events = 0;
174 tk 362
 
2537 tk 363
  u8 handle_vu_meter = (ui_page == SEQ_UI_PAGE_TRGSEL || ui_page == SEQ_UI_PAGE_INSSEL || ui_page == SEQ_UI_PAGE_PARSEL || ui_page == SEQ_UI_PAGE_MUTE) && track == SEQ_UI_VisibleTrackGet();
333 tk 364
 
1316 tk 365
  if( tcc->event_mode == SEQ_EVENT_MODE_Drum ) {
328 tk 366
    u8 num_instruments = SEQ_TRG_NumInstrumentsGet(track); // we assume, that PAR layer has same number of instruments!
367
 
368
    u8 drum;
369
    for(drum=0; drum<num_instruments; ++drum) {
483 tk 370
      u8 note = tcc->lay_const[0*16 + drum];
371
      u8 velocity = 0;
174 tk 372
 
591 tk 373
      if( !insert_empty_notes && (layer_muted & (1 << drum)) )
374
    velocity = 0;
375
      else {
376
    if( SEQ_TRG_Get(track, step, 0, drum) ) {
686 tk 377
      if( tcc->link_par_layer_velocity >= 0 )
1219 tk 378
        velocity = SEQ_PAR_VelocityGet(track, step, drum, 0x0000);
591 tk 379
      else
380
        velocity = tcc->lay_const[1*16 + drum];
381
    }
323 tk 382
      }
174 tk 383
 
2522 tk 384
      if( !insert_empty_notes ) {
385
    u8 rnd_probability;
386
    if( (rnd_probability=SEQ_PAR_ProbabilityGet(track, step, drum, layer_muted)) < 100 &&
387
        SEQ_RANDOM_Gen_Range(0, 99) >= rnd_probability )
388
      velocity = 0;
389
      }
390
 
483 tk 391
      if( handle_vu_meter && velocity ) {
2615 tk 392
    seq_layer_vu_meter[drum] = (velocity > 8) ? velocity : 1;
333 tk 393
      } else {
394
    seq_layer_vu_meter[drum] &= 0x7f; // ensure that no static assignment is displayed
395
      }
174 tk 396
 
483 tk 397
      if( (note && velocity) || insert_empty_notes ) {
398
    seq_layer_evnt_t *e = &layer_events[num_events];
399
    mios32_midi_package_t *p = &e->midi_package;
333 tk 400
 
483 tk 401
    p->type     = NoteOn;
402
    p->cable    = track;
403
    p->event    = NoteOn;
404
    p->chn      = tcc->midi_chn; // TODO: optionally different channel taken from const D
405
    p->note     = note;
406
    p->velocity = velocity;
1219 tk 407
    e->len = SEQ_PAR_LengthGet(track, step, drum, 0x0000);
483 tk 408
    e->layer_tag = drum;
409
 
410
    ++num_events;
411
      }
323 tk 412
    }
2551 tk 413
 
414
#ifdef MBSEQV4P
2552 tk 415
    // CC, PitchBend, etc only supported by V4+
2551 tk 416
    u8 num_p_layers = SEQ_PAR_NumLayersGet(track);
2552 tk 417
    u8 pb_sent = 0;
418
    u8 at_sent = 0;
419
    u8 pc_sent = 0;
420
 
2551 tk 421
    for(drum=0; drum<num_instruments; ++drum) {
422
      u8 *layer_type_ptr = (u8 *)&tcc->par_assignment_drum[0];
423
      int par_layer;
424
      for(par_layer=0; par_layer<num_p_layers; ++par_layer, ++layer_type_ptr) {
425
 
2552 tk 426
    switch( *layer_type_ptr ) {
427
    case SEQ_PAR_Type_CC: {
428
      u8 cc_number = seq_layer_drum_cc[drum][par_layer];
429
      u8 value = SEQ_PAR_Get(track, step, par_layer, drum);
2551 tk 430
 
2552 tk 431
      if( !insert_empty_notes ) {
432
        // new: don't send CC if assigned to invalid CC number
433
        // new: don't send if CC is assigned to LFO extra CC function
434
        if( cc_number >= 0x80 ||
435
        (tcc->lfo_waveform && tcc->lfo_cc == cc_number) )
436
          break;
2551 tk 437
 
2552 tk 438
        // don't send CC if value hasn't changed (== invalid value)
439
        // but only if LFO not assigned to CC layer
440
        if( !tcc->lfo_enable_flags.CC &&
441
        ( value >= 0x80 || value == cc_last_value[track][drum][par_layer]) ) {
442
          break;
443
        }
444
        cc_last_value[track][drum][par_layer] = value;
445
      }
2551 tk 446
 
2552 tk 447
      if( insert_empty_notes || !(layer_muted & (1 << drum)) ) {
448
        seq_layer_evnt_t *e = &layer_events[num_events];
449
        mios32_midi_package_t *p = &e->midi_package;
450
 
451
        p->type     = CC;
452
        p->cable    = track;
453
        p->event    = CC;
454
        p->chn      = tcc->midi_chn;
455
        p->cc_number = cc_number;
456
        p->value    = value;
457
        e->len      = -1;
458
        e->layer_tag = drum;
459
        ++num_events;
460
 
461
        // morph it
462
        if( !insert_empty_notes && tcc->morph_mode )
463
          SEQ_MORPH_EventCC(track, step, e, drum, par_layer);
2551 tk 464
      }
2552 tk 465
    } break;
2551 tk 466
 
2552 tk 467
        case SEQ_PAR_Type_PitchBend: {
468
      if( pb_sent ) // send only once!
469
        break;
470
      pb_sent = 1;
471
 
2551 tk 472
      seq_layer_evnt_t *e = &layer_events[num_events];
473
      mios32_midi_package_t *p = &e->midi_package;
2552 tk 474
      u8 value = SEQ_PAR_Get(track, step, par_layer, drum);
2551 tk 475
 
2552 tk 476
      // don't send pitchbender if value hasn't changed
477
      if( !insert_empty_notes ) {
478
        if( value >= 0x80 || value == pb_last_value[track] )
479
          break;
480
        pb_last_value[track] = value;
481
      }
2551 tk 482
 
2552 tk 483
      if( insert_empty_notes || !(layer_muted & (1 << drum)) ) {
484
        p->type     = PitchBend;
485
        p->cable    = track;
486
        p->event    = PitchBend;
487
        p->chn      = tcc->midi_chn;
488
        p->evnt1    = (value == 0x40) ? 0x00 : value; // LSB
489
        p->evnt2    = value; // MSB
490
        e->len      = -1;
491
        e->layer_tag = par_layer;
492
        ++num_events;
493
 
494
        // morph it
495
        if( !insert_empty_notes && tcc->morph_mode )
496
          SEQ_MORPH_EventPitchBend(track, step, e, drum, par_layer);
497
      }
498
 
499
    } break;
500
 
501
        case SEQ_PAR_Type_ProgramChange: {
502
      if( pc_sent ) // send only once!
503
        break;
504
      pc_sent = 1;
505
 
506
      seq_layer_evnt_t *e = &layer_events[num_events];
507
      mios32_midi_package_t *p = &e->midi_package;
508
      u8 value = SEQ_PAR_Get(track, step, par_layer, drum);
509
 
510
      // don't send program change if value hasn't changed
511
      if( !insert_empty_notes ) {
512
        if( value >= 0x80 || value == pc_last_value[track] )
513
          break;
514
        pc_last_value[track] = value;
515
      }
516
 
517
      if( insert_empty_notes || !(layer_muted & (1 << drum)) ) {
518
        p->type     = ProgramChange;
519
        p->cable    = track;
520
        p->event    = ProgramChange;
521
        p->chn      = tcc->midi_chn;
522
        p->evnt1    = value;
523
        p->evnt2    = 0x00; // don't care
524
        e->len      = -1;
525
        e->layer_tag = par_layer;
526
        ++num_events;
527
 
528
        // morph it
529
        if( !insert_empty_notes && tcc->morph_mode )
530
          SEQ_MORPH_EventProgramChange(track, step, e, drum, par_layer);
531
      }
532
 
533
    } break;
534
 
535
        case SEQ_PAR_Type_Aftertouch: {
536
      if( at_sent ) // send only once!
537
        break;
538
      at_sent = 1;
539
 
540
      seq_layer_evnt_t *e = &layer_events[num_events];
541
      mios32_midi_package_t *p = &e->midi_package;
542
      u8 value = SEQ_PAR_Get(track, step, par_layer, drum);
543
 
544
      // don't send aftertouch if value hasn't changed
545
      if( !insert_empty_notes ) {
546
        if( value >= 0x80 || value == at_last_value[track] )
547
          break;
548
        at_last_value[track] = value;
549
      }
550
 
551
      if( insert_empty_notes || !(layer_muted & (1 << drum)) ) {
552
        p->type     = Aftertouch;
553
        p->cable    = track;
554
        p->event    = Aftertouch;
555
        p->chn      = tcc->midi_chn;
556
        p->evnt1    = value;
557
        p->evnt2    = 0x00; // don't care
558
        e->len      = -1;
559
        e->layer_tag = par_layer;
560
        ++num_events;
561
 
562
        // morph it
563
        if( !insert_empty_notes && tcc->morph_mode )
564
          SEQ_MORPH_EventAftertouch(track, step, e, drum, par_layer);
565
      }
566
 
567
    } break;
568
 
2551 tk 569
    }
2552 tk 570
 
571
    if( num_events >= 83 )
572
      break;
2551 tk 573
      }
2552 tk 574
    }
2551 tk 575
#endif
576
 
323 tk 577
  } else {
328 tk 578
    u8 instrument = 0;
333 tk 579
    int par_layer;
176 tk 580
 
333 tk 581
    // get velocity and length from first parameter layer which holds it
582
    // if not assigned, we will get back a default value
583
 
1024 tk 584
    u8 gate = SEQ_TRG_GateGet(track, step, instrument);
333 tk 585
    u8 velocity = 100; // default velocity
1316 tk 586
    if( tcc->event_mode != SEQ_EVENT_MODE_Combined ) {
1313 tk 587
      if( (par_layer=tcc->link_par_layer_velocity) >= 0 ) {
588
    if( insert_empty_notes || !(layer_muted & (1 << par_layer)) ) {
589
      velocity = SEQ_PAR_Get(track, step, par_layer, instrument);
590
      if( !insert_empty_notes && !gate )
591
        velocity = 0;
592
    } else {
593
      if( !gate )
594
        velocity = 0;
595
    }
596
 
597
    if( handle_vu_meter )
2615 tk 598
      seq_layer_vu_meter[par_layer] = ((velocity > 8) ? velocity : 8) | 0x80;
1313 tk 599
      } else {
1219 tk 600
    if( !insert_empty_notes && !gate )
601
      velocity = 0;
602
      }
333 tk 603
    }
604
 
605
    u8 length = 71; // default length
1316 tk 606
    if( tcc->event_mode != SEQ_EVENT_MODE_Combined ) {
1313 tk 607
      if( (par_layer=tcc->link_par_layer_length) >= 0 ) {
608
    if( (insert_empty_notes || !(layer_muted & (1 << par_layer))) ) {
1318 tk 609
      length = SEQ_PAR_Get(track, step, par_layer, instrument) + 1;
610
      if( length > 96 )
611
        length = 96;
1313 tk 612
    }
613
 
614
    if( handle_vu_meter )
2615 tk 615
      seq_layer_vu_meter[par_layer] = ((length > 8) ? length : 8) | 0x80;
1219 tk 616
      }
333 tk 617
    }
618
 
742 tk 619
    if( handle_vu_meter ) { // only for VU meters
620
      if( (par_layer=tcc->link_par_layer_probability) ) { // Probability
1219 tk 621
    u8 rnd_probability = SEQ_PAR_ProbabilityGet(track, step, instrument, layer_muted);
2615 tk 622
    seq_layer_vu_meter[par_layer] = ((rnd_probability > 8) ? rnd_probability : 8) | 0x80;
742 tk 623
      }
624
 
625
      if( (par_layer=tcc->link_par_layer_delay) ) { // Delay
1219 tk 626
    u8 delay = SEQ_PAR_StepDelayGet(track, step, instrument, layer_muted);
2615 tk 627
    seq_layer_vu_meter[par_layer] = ((delay > 8) ? delay : 8) | 0x80;
742 tk 628
      }
629
 
630
      if( (par_layer=tcc->link_par_layer_roll) ) { // Roll mode
1219 tk 631
    u8 roll_mode = SEQ_PAR_RollModeGet(track, step, instrument, layer_muted);
742 tk 632
    if( roll_mode )
633
      seq_layer_vu_meter[par_layer] = 0x7f;
634
      }
1219 tk 635
 
636
      if( (par_layer=tcc->link_par_layer_roll2) ) { // Roll2 mode
637
    u8 roll2_mode = SEQ_PAR_Roll2ModeGet(track, step, instrument, layer_muted);
638
    if( roll2_mode )
639
      seq_layer_vu_meter[par_layer] = 0x7f;
640
      }
742 tk 641
    }
642
 
333 tk 643
    // go through all layers to generate events
473 tk 644
    u8 *layer_type_ptr = (u8 *)&tcc->lay_const[0*16];
333 tk 645
    u8 num_p_layers = SEQ_PAR_NumLayersGet(track);
473 tk 646
    for(par_layer=0; par_layer<num_p_layers; ++par_layer, ++layer_type_ptr) {
333 tk 647
 
473 tk 648
      // usually no function assigned to layer - skip it immediately to speed up the loop
649
      if( *layer_type_ptr == SEQ_PAR_Type_None )
650
    continue;
651
 
652
      // branch depending on layer type
653
      switch( *layer_type_ptr ) {
654
 
333 tk 655
        case SEQ_PAR_Type_Note: {
656
      seq_layer_evnt_t *e = &layer_events[num_events];
657
      mios32_midi_package_t *p = &e->midi_package;
457 tk 658
      u8 note = SEQ_PAR_Get(track, step, par_layer, instrument);
333 tk 659
 
1316 tk 660
      if( tcc->event_mode == SEQ_EVENT_MODE_Combined ) {
1313 tk 661
        if( (track&7) == 1 || (track&7) == 2)
662
          return 0; // assigned to velocity and length
663
 
664
        if( !insert_empty_notes && !gate )
665
          velocity = 0;
666
        else
667
          velocity = SEQ_PAR_Get(track+1, step, par_layer, instrument);
668
 
1318 tk 669
        length = SEQ_PAR_Get(track+2, step, par_layer, instrument) + 1;
670
        if( length > 96 )
671
          length = 96;
1313 tk 672
      }
673
 
591 tk 674
      if( !insert_empty_notes && (layer_muted & (1 << par_layer)) )
675
        note = 0;
676
 
457 tk 677
      if( note || insert_empty_notes ) {
678
        p->type     = NoteOn;
679
        p->cable    = track;
680
        p->event    = NoteOn;
681
        p->chn      = tcc->midi_chn;
682
        p->note     = note;
683
        p->velocity = velocity;
684
        e->len      = length;
685
        e->layer_tag = par_layer;
686
        ++num_events;
607 tk 687
 
688
        // morph it
689
        if( !insert_empty_notes && velocity && tcc->morph_mode )
690
          SEQ_MORPH_EventNote(track, step, e, instrument, par_layer, tcc->link_par_layer_velocity, tcc->link_par_layer_length);
457 tk 691
      }
333 tk 692
 
457 tk 693
      if( handle_vu_meter && note && velocity )
2615 tk 694
        seq_layer_vu_meter[par_layer] = ((velocity > 8) ? velocity : 8);
333 tk 695
    } break;
696
 
2274 tk 697
        case SEQ_PAR_Type_Chord1:
2505 tk 698
        case SEQ_PAR_Type_Chord2:
699
        case SEQ_PAR_Type_Chord3: {
333 tk 700
      u8 chord_value = SEQ_PAR_Get(track, step, par_layer, instrument);
701
      int i;
607 tk 702
 
1316 tk 703
      if( tcc->event_mode == SEQ_EVENT_MODE_Combined ) {
1313 tk 704
        if( (track&7) == 1 || (track&7) == 2)
705
          return 0; // assigned to velocity and length
706
 
707
        if( !insert_empty_notes && !gate )
708
          velocity = 0;
709
        else
710
          velocity = SEQ_PAR_Get(track+1, step, par_layer, instrument);
711
 
1318 tk 712
        length = SEQ_PAR_Get(track+2, step, par_layer, instrument) + 1;
713
        if( length > 96 )
714
          length = 96;
1313 tk 715
      }
716
 
1143 tk 717
      if( chord_value || insert_empty_notes ) {
718
        seq_layer_evnt_t e_proto;
719
        mios32_midi_package_t *p_proto = &e_proto.midi_package;
720
        p_proto->type     = NoteOn;
721
        p_proto->cable    = track;
722
        p_proto->event    = NoteOn;
723
        p_proto->chn      = tcc->midi_chn;
724
        p_proto->note     = chord_value; // we will determine the note value later
725
        p_proto->velocity = velocity;
726
        e_proto.len      = length;
727
        e_proto.layer_tag = par_layer;
607 tk 728
 
1143 tk 729
        // morph chord value like a note (-> nice effect!)
730
        if( !insert_empty_notes && velocity && tcc->morph_mode ) {
731
          SEQ_MORPH_EventNote(track, step, &e_proto, instrument, par_layer, tcc->link_par_layer_velocity, tcc->link_par_layer_length);
732
          chord_value = e_proto.midi_package.note; // chord value has been morphed!
733
        }
607 tk 734
 
2274 tk 735
        for(i=0; i<6; ++i) {
1143 tk 736
          if( num_events >= 16 )
737
        break;
333 tk 738
 
2505 tk 739
          u8 chord_set = (*layer_type_ptr == SEQ_PAR_Type_Chord2) ? 1 : (((*layer_type_ptr == SEQ_PAR_Type_Chord3) ? 2 : 0));
2274 tk 740
          s32 note = SEQ_CHORD_NoteGet(i, chord_set, chord_value);
591 tk 741
 
1143 tk 742
          if( !insert_empty_notes && (layer_muted & (1 << par_layer)) )
743
        note = 0;
591 tk 744
 
1143 tk 745
          if( note < 0 )
746
        break;
333 tk 747
 
1143 tk 748
          seq_layer_evnt_t *e = &layer_events[num_events];
749
          *e = e_proto;
750
          e->midi_package.note = note;
751
          ++num_events;
752
        }
333 tk 753
      }
754
 
755
      if( handle_vu_meter && velocity )
2615 tk 756
        seq_layer_vu_meter[par_layer] = ((velocity > 8) ? velocity : 8);
333 tk 757
 
758
    } break;
759
 
760
        case SEQ_PAR_Type_CC: {
761
      seq_layer_evnt_t *e = &layer_events[num_events];
762
      mios32_midi_package_t *p = &e->midi_package;
1811 tk 763
      u8 cc_number = tcc->lay_const[1*16 + par_layer];
1313 tk 764
      u8 value = SEQ_PAR_Get(track, step, par_layer, instrument);
333 tk 765
 
1811 tk 766
      if( !insert_empty_notes ) {
2448 tk 767
        // new: don't send CC if assigned to invalid CC number
1811 tk 768
        // new: don't send if CC is assigned to LFO extra CC function
769
        if( cc_number >= 0x80 ||
770
        (tcc->lfo_waveform && tcc->lfo_cc == cc_number) )
771
          break;
1316 tk 772
 
1811 tk 773
        // don't send CC if value hasn't changed (== invalid value)
774
        // but only if LFO not assigned to CC layer
1794 tk 775
        if( !tcc->lfo_enable_flags.CC &&
2551 tk 776
        ( value >= 0x80 || value == cc_last_value[track][0][par_layer]) ) {
1811 tk 777
          break;
1794 tk 778
        }
2551 tk 779
        cc_last_value[track][0][par_layer] = value;
1345 tk 780
      }
1313 tk 781
 
1341 tk 782
      if(
783
#ifndef MBSEQV4L
784
         (tcc->event_mode != SEQ_EVENT_MODE_CC || gate) &&
785
#endif
786
         (insert_empty_notes || !(layer_muted & (1 << par_layer))) ) {
591 tk 787
        p->type     = CC;
788
        p->cable    = track;
789
        p->event    = CC;
790
        p->chn      = tcc->midi_chn;
2551 tk 791
        p->cc_number = cc_number;
1313 tk 792
        p->value    = value;
591 tk 793
        e->len      = -1;
794
        e->layer_tag = par_layer;
795
        ++num_events;
333 tk 796
 
607 tk 797
        // morph it
798
        if( !insert_empty_notes && tcc->morph_mode )
799
          SEQ_MORPH_EventCC(track, step, e, instrument, par_layer);
800
 
591 tk 801
        if( handle_vu_meter )
2615 tk 802
          seq_layer_vu_meter[par_layer] = ((p->value > 8) ? p->value : 8) | 0x80;
591 tk 803
      }
333 tk 804
 
805
    } break;
806
 
807
        case SEQ_PAR_Type_PitchBend: {
808
      seq_layer_evnt_t *e = &layer_events[num_events];
809
      mios32_midi_package_t *p = &e->midi_package;
810
      u8 value = SEQ_PAR_Get(track, step, par_layer, instrument);
811
 
1313 tk 812
      // don't send pitchbender if value hasn't changed
1385 tk 813
      if( !insert_empty_notes ) {
814
        if( value >= 0x80 || value == pb_last_value[track] )
815
          break;
816
        pb_last_value[track] = value;
817
      }
1313 tk 818
 
1976 tk 819
      if(
820
#ifndef MBSEQV4L
821
         (tcc->event_mode != SEQ_EVENT_MODE_CC || gate) &&
822
#endif
823
         (insert_empty_notes || !(layer_muted & (1 << par_layer))) ) {
591 tk 824
        p->type     = PitchBend;
825
        p->cable    = track;
826
        p->event    = PitchBend;
827
        p->chn      = tcc->midi_chn;
1313 tk 828
        p->evnt1    = (value == 0x40) ? 0x00 : value; // LSB
591 tk 829
        p->evnt2    = value; // MSB
830
        e->len      = -1;
831
        e->layer_tag = par_layer;
832
        ++num_events;
333 tk 833
 
607 tk 834
        // morph it
835
        if( !insert_empty_notes && tcc->morph_mode )
836
          SEQ_MORPH_EventPitchBend(track, step, e, instrument, par_layer);
837
 
591 tk 838
        if( handle_vu_meter )
2615 tk 839
          seq_layer_vu_meter[par_layer] = ((p->evnt2 > 8) ? p->evnt2 : 8) | 0x80;
591 tk 840
      }
333 tk 841
 
842
    } break;
843
 
1422 tk 844
        case SEQ_PAR_Type_ProgramChange: {
845
      seq_layer_evnt_t *e = &layer_events[num_events];
846
      mios32_midi_package_t *p = &e->midi_package;
847
      u8 value = SEQ_PAR_Get(track, step, par_layer, instrument);
848
 
849
      // don't send program change if value hasn't changed
850
      if( !insert_empty_notes ) {
851
        if( value >= 0x80 || value == pc_last_value[track] )
852
          break;
853
        pc_last_value[track] = value;
854
      }
855
 
856
      if( (tcc->event_mode != SEQ_EVENT_MODE_CC || gate) &&
857
          (insert_empty_notes || !(layer_muted & (1 << par_layer))) ) {
858
        p->type     = ProgramChange;
859
        p->cable    = track;
860
        p->event    = ProgramChange;
861
        p->chn      = tcc->midi_chn;
862
        p->evnt1    = value;
863
        p->evnt2    = 0x00; // don't care
864
        e->len      = -1;
865
        e->layer_tag = par_layer;
866
        ++num_events;
867
 
868
        // morph it
869
        if( !insert_empty_notes && tcc->morph_mode )
870
          SEQ_MORPH_EventProgramChange(track, step, e, instrument, par_layer);
871
 
872
        if( handle_vu_meter )
2615 tk 873
          seq_layer_vu_meter[par_layer] = ((p->evnt1 > 8) ? p->evnt1 : 8) | 0x80;
1422 tk 874
      }
875
 
876
    } break;
877
 
2389 tk 878
        case SEQ_PAR_Type_Aftertouch: {
879
      seq_layer_evnt_t *e = &layer_events[num_events];
880
      mios32_midi_package_t *p = &e->midi_package;
881
      u8 value = SEQ_PAR_Get(track, step, par_layer, instrument);
882
 
883
      // don't send aftertouch if value hasn't changed
884
      if( !insert_empty_notes ) {
885
        if( value >= 0x80 || value == at_last_value[track] )
886
          break;
887
        at_last_value[track] = value;
888
      }
889
 
890
      if( (tcc->event_mode != SEQ_EVENT_MODE_CC || gate) &&
891
          (insert_empty_notes || !(layer_muted & (1 << par_layer))) ) {
892
        p->type     = Aftertouch;
893
        p->cable    = track;
894
        p->event    = Aftertouch;
895
        p->chn      = tcc->midi_chn;
896
        p->evnt1    = value;
897
        p->evnt2    = 0x00; // don't care
898
        e->len      = -1;
899
        e->layer_tag = par_layer;
900
        ++num_events;
901
 
902
        // morph it
903
        if( !insert_empty_notes && tcc->morph_mode )
904
          SEQ_MORPH_EventAftertouch(track, step, e, instrument, par_layer);
905
 
906
        if( handle_vu_meter )
2615 tk 907
          seq_layer_vu_meter[par_layer] = ((p->evnt1 > 8) ? p->evnt1 : 8) | 0x80;
2389 tk 908
      }
909
 
910
    } break;
911
 
323 tk 912
      }
333 tk 913
 
914
      if( num_events >= 16 )
915
    break;
323 tk 916
    }
176 tk 917
  }
918
 
323 tk 919
  return num_events;
174 tk 920
}
921
 
176 tk 922
 
174 tk 923
/////////////////////////////////////////////////////////////////////////////
419 tk 924
// Used for recording: insert an event into a selected step
925
// The return value matches with the layer where the new event has been inserted.
926
// if < 0, no event has been inserted.
927
/////////////////////////////////////////////////////////////////////////////
928
s32 SEQ_LAYER_RecEvent(u8 track, u16 step, seq_layer_evnt_t layer_event)
929
{
930
  seq_core_trk_t *t = &seq_core_trk[track];
931
  seq_cc_trk_t *tcc = &seq_cc_trk[track];
932
 
933
  if( tcc->event_mode == SEQ_EVENT_MODE_Drum ) {
934
    u8 num_instruments = SEQ_TRG_NumInstrumentsGet(track); // we assume, that PAR layer has same number of instruments!
935
 
1422 tk 936
    // all events but Notes are ignored (CC/PitchBend/ProgramChange are working channel based, and not drum instr. based)
419 tk 937
    if( layer_event.midi_package.event == NoteOn ) {
938
      u8 drum;
939
      for(drum=0; drum<num_instruments; ++drum) {
940
    u8 drum_note = tcc->lay_const[0*16 + drum];
941
    if( drum_note == layer_event.midi_package.note ) {
2149 tk 942
 
943
      // BEGIN live pattern insertion
944
      u8 gate = 1;
945
      u8 accent = 0;
2152 tk 946
      if( !seq_record_options.STEP_RECORD ) {
2154 tk 947
        seq_live_pattern_slot_t *slot = (seq_live_pattern_slot_t *)&seq_live_pattern_slot[1+drum];
2149 tk 948
        if( slot->enabled ) {
949
          seq_live_arp_pattern_t *pattern = (seq_live_arp_pattern_t *)&seq_live_arp_pattern[slot->pattern];
950
          u16 mask = 1 << (step % 16);
951
          gate = (pattern->gate & mask) ? 1 : 0;
952
          accent = (pattern->accent & mask) ? 1 : 0;
953
          layer_event.midi_package.velocity = slot->velocity;
954
        }
955
      }
956
      // END live pattern insertion
957
 
958
      SEQ_TRG_GateSet(track, step, drum, gate);
959
      SEQ_TRG_AccentSet(track, step, drum, accent);
419 tk 960
 
961
      int par_layer;
962
      if( (par_layer=tcc->link_par_layer_velocity) >= 0 )
963
        SEQ_PAR_Set(track, step, par_layer, drum, layer_event.midi_package.velocity);
964
 
965
      return drum; // drum note has been inserted - return instrument layer
966
    }
967
      }
968
    }
969
  } else {
970
    u8 instrument = 0;
971
    int par_layer;
972
    u8 num_p_layers = SEQ_PAR_NumLayersGet(track);
973
 
2149 tk 974
    // BEGIN live pattern insertion
975
    u8 gate = 1;
976
    u8 accent = 0;
2152 tk 977
    if( !seq_record_options.STEP_RECORD ) {
2154 tk 978
      seq_live_pattern_slot_t *slot = (seq_live_pattern_slot_t *)&seq_live_pattern_slot[0];
2149 tk 979
      if( slot->enabled ) {
980
    seq_live_arp_pattern_t *pattern = (seq_live_arp_pattern_t *)&seq_live_arp_pattern[slot->pattern];
981
    u16 mask = 1 << (step % 16);
982
    gate = (pattern->gate & mask) ? 1 : 0;
983
    accent = (pattern->accent & mask) ? 1 : 0;
984
    layer_event.midi_package.velocity = slot->velocity;
985
    layer_event.len = slot->len;
986
      }
987
    }
988
    // END live pattern insertion
989
 
419 tk 990
    // in poly mode: check if note already recorded
991
    if( seq_record_options.POLY_RECORD && layer_event.midi_package.event == NoteOn ) {
992
      for(par_layer=0; par_layer<num_p_layers; ++par_layer) {
993
    seq_par_layer_type_t par_type = tcc->lay_const[0*16 + par_layer];
2505 tk 994
    if( (par_type == SEQ_PAR_Type_Note || par_type == SEQ_PAR_Type_Chord1 || par_type == SEQ_PAR_Type_Chord2 || par_type == SEQ_PAR_Type_Chord3) &&
419 tk 995
        SEQ_PAR_Get(track, step, par_layer, instrument) == layer_event.midi_package.note ) {
996
 
997
      // set gate and take over new velocity/length (poly mode: last vel/length will be taken for all)
2149 tk 998
      SEQ_TRG_GateSet(track, step, instrument, gate);
999
      SEQ_TRG_AccentSet(track, step, instrument, accent);
419 tk 1000
 
1316 tk 1001
      if( tcc->event_mode == SEQ_EVENT_MODE_Combined ) {
1002
        // insert velocity into track 2/9
1003
        SEQ_PAR_Set(track+1, step, par_layer, instrument, layer_event.midi_package.velocity);
1004
        // insert length into track 3/10
1005
        SEQ_PAR_Set(track+2, step, par_layer, instrument, (layer_event.len >= 95) ? 95 : layer_event.len);
1006
      } else {
1007
        if( tcc->link_par_layer_velocity >= 0 )
1008
          SEQ_PAR_Set(track, step, tcc->link_par_layer_velocity, instrument, layer_event.midi_package.velocity);
419 tk 1009
 
1316 tk 1010
        if( tcc->link_par_layer_length >= 0 )
1011
          SEQ_PAR_Set(track, step, tcc->link_par_layer_length, instrument, (layer_event.len >= 95) ? 95 : layer_event.len);
1012
      }
419 tk 1013
 
1014
      // return the parameter layer
1015
      return par_layer;
1016
    }
1017
      }
1018
    }
1019
 
1313 tk 1020
    // if gate isn't set or MONO mode: start poly counter at 0 (remaining notes will be cleared)
1021
    if( !seq_record_options.POLY_RECORD || !SEQ_TRG_GateGet(track, step, instrument) )
1022
      t->rec_poly_ctr = 0;
1023
 
419 tk 1024
    // go through all layers to search for matching event
1025
    u8 note_ctr = 0;
1026
    for(par_layer=0; par_layer<num_p_layers; ++par_layer) {
1027
      switch( tcc->lay_const[0*16 + par_layer] ) {
1028
 
1029
        case SEQ_PAR_Type_Note:
2274 tk 1030
        case SEQ_PAR_Type_Chord1:
2505 tk 1031
        case SEQ_PAR_Type_Chord2:
1032
        case SEQ_PAR_Type_Chord3: {
419 tk 1033
      if( layer_event.midi_package.event == NoteOn ) {
1034
 
1035
        // in poly mode: skip if note number doesn't match with poly counter
1036
        if( seq_record_options.POLY_RECORD && note_ctr != t->rec_poly_ctr ) {
1037
          ++note_ctr;
1038
          break;
1039
        }
1040
 
1041
        // if first note (reached again): clear remaining notes
1042
        // always active in mono mode (TODO: good? Or should we record on the selected par layer?)
1043
        if( !seq_record_options.POLY_RECORD || t->rec_poly_ctr == 0 ) {
1044
          u8 remaining_par_layer;
1045
          for(remaining_par_layer=par_layer+1; remaining_par_layer<num_p_layers; ++remaining_par_layer) {
1046
        seq_par_layer_type_t par_type = tcc->lay_const[0*16 + remaining_par_layer];
2505 tk 1047
        if( par_type == SEQ_PAR_Type_Note || par_type == SEQ_PAR_Type_Chord1 || par_type == SEQ_PAR_Type_Chord2 || par_type == SEQ_PAR_Type_Chord3 )
419 tk 1048
          SEQ_PAR_Set(track, step, remaining_par_layer, instrument, 0x00);
1049
          }
1050
        }
1051
        SEQ_PAR_Set(track, step, par_layer, instrument, layer_event.midi_package.note);
1052
 
1053
        // set gate and take over new velocity/length (poly mode: last vel/length will be taken for all)
2149 tk 1054
        SEQ_TRG_GateSet(track, step, instrument, gate);
1055
        SEQ_TRG_AccentSet(track, step, instrument, accent);
419 tk 1056
 
1316 tk 1057
        if( tcc->event_mode == SEQ_EVENT_MODE_Combined ) {
1058
          // insert velocity into track 2/9
1059
          SEQ_PAR_Set(track+1, step, par_layer, instrument, layer_event.midi_package.velocity);
1060
          // insert length into track 3/10
1061
          SEQ_PAR_Set(track+2, step, par_layer, instrument, (layer_event.len >= 95) ? 95 : layer_event.len);
1062
        } else {
1063
          if( tcc->link_par_layer_velocity >= 0 )
1064
        SEQ_PAR_Set(track, step, tcc->link_par_layer_velocity, instrument, layer_event.midi_package.velocity);
419 tk 1065
 
1316 tk 1066
          if( tcc->link_par_layer_length >= 0 )
1067
        SEQ_PAR_Set(track, step, tcc->link_par_layer_length, instrument, (layer_event.len >= 95) ? 95 : layer_event.len);
1068
        }
419 tk 1069
 
1070
        // in poly mode: continue search for next free note, wrap if end of layer is reached
1071
        if( seq_record_options.POLY_RECORD ) {
1072
          u8 remaining_par_layer;
1073
          for(remaining_par_layer=par_layer+1; remaining_par_layer<num_p_layers; ++remaining_par_layer) {
1074
        seq_par_layer_type_t par_type = tcc->lay_const[0*16 + remaining_par_layer];
2505 tk 1075
        if( par_type == SEQ_PAR_Type_Note || par_type == SEQ_PAR_Type_Chord1 || par_type == SEQ_PAR_Type_Chord2 || par_type == SEQ_PAR_Type_Chord3 ) {
419 tk 1076
          ++t->rec_poly_ctr; // switch to next note
1077
          break;
1078
        }
1079
          }
1080
 
1081
          // out of notes - restart at 0
1082
          if( remaining_par_layer >= num_p_layers )
1083
        t->rec_poly_ctr = 0;
1084
        }
1085
 
1086
        return par_layer;
1087
      }
1088
    } break;
1089
 
1090
        case SEQ_PAR_Type_CC: {
1091
      if( layer_event.midi_package.event == CC && layer_event.midi_package.cc_number == tcc->lay_const[1*16 + par_layer] ) {
1316 tk 1092
        // extra MBSEQ V4L: write into whole 16th step in step record mode
1093
        if(
1094
#ifndef MBSEQV4L
1095
 
1096
#else
1341 tk 1097
           (seq_record_options.STEP_RECORD || !SEQ_BPM_IsRunning()) && tcc->clkdiv.value == 0x03
1316 tk 1098
#endif
1099
           ) {
1100
          int i;
1101
          for(i=0; i<4; ++i)
1102
        SEQ_PAR_Set(track, step*4+i, par_layer, instrument, layer_event.midi_package.value);
1103
        } else {
1341 tk 1104
          // Live Record mode: write into the next 4*resolution steps (till end of track)
1105
          int i;
1106
          u16 num_p_steps = SEQ_PAR_NumStepsGet(track);
2048 tk 1107
#ifndef MBSEQV4L
1108
          int num_steps = 1;
1109
#else
1341 tk 1110
          int num_steps = 4;
2048 tk 1111
#endif
1112
 
1113
          if( !seq_record_options.STEP_RECORD ) {
1114
        num_steps = 4;
1115
        if( tcc->clkdiv.value <= 0x03 )
1116
          num_steps = 16;
1117
        else if( tcc->clkdiv.value <= 0x07 )
1118
          num_steps = 8;
1119
          }
1120
 
1341 tk 1121
          for(i=0; i<num_steps && (step+i) < num_p_steps; ++i) {
1122
        SEQ_PAR_Set(track, step+i, par_layer, instrument, layer_event.midi_package.value);
1123
          }
1316 tk 1124
        }
419 tk 1125
        return par_layer;
1126
      }
1127
    } break;
1128
 
1129
        case SEQ_PAR_Type_PitchBend: {
1130
      if( layer_event.midi_package.event == PitchBend ) {
1316 tk 1131
        // extra MBSEQ V4L: write into whole 16th step in step record mode
1132
        if(
1133
#ifndef MBSEQV4L
1134
 
1135
#else
1341 tk 1136
           (seq_record_options.STEP_RECORD || !SEQ_BPM_IsRunning()) && tcc->clkdiv.value == 0x03
1316 tk 1137
#endif
1138
           ) {
1139
          int i;
1140
          for(i=0; i<4; ++i)
1141
        SEQ_PAR_Set(track, step*4+i, par_layer, instrument, layer_event.midi_package.evnt2); // MSB
1142
        } else {
1976 tk 1143
          // Live Record mode: write into the next 4*resolution steps (till end of track)
1144
          int i;
1145
          u16 num_p_steps = SEQ_PAR_NumStepsGet(track);
1146
          int num_steps = 4;
1147
          if( tcc->clkdiv.value <= 0x03 )
1148
        num_steps = 16;
1149
          else if( tcc->clkdiv.value <= 0x07 )
1150
        num_steps = 8;
1151
          for(i=0; i<num_steps && (step+i) < num_p_steps; ++i) {
1152
        SEQ_PAR_Set(track, step+i, par_layer, instrument, layer_event.midi_package.evnt2); // MSB
1153
          }
1316 tk 1154
          return par_layer;
1155
        }
419 tk 1156
      }
1157
    } break;
1422 tk 1158
 
1159
        case SEQ_PAR_Type_ProgramChange: {
1160
      if( layer_event.midi_package.event == ProgramChange ) {
1161
        // extra MBSEQ V4L: write into whole 16th step in step record mode
1162
        if(
1163
#ifndef MBSEQV4L
1164
 
1165
#else
1166
           (seq_record_options.STEP_RECORD || !SEQ_BPM_IsRunning()) && tcc->clkdiv.value == 0x03
1167
#endif
1168
           ) {
1169
          int i;
1170
          for(i=0; i<4; ++i)
1171
        SEQ_PAR_Set(track, step*4+i, par_layer, instrument, layer_event.midi_package.evnt1);
1172
        } else {
1173
          SEQ_PAR_Set(track, step, par_layer, instrument, layer_event.midi_package.evnt1);
1174
          return par_layer;
1175
        }
1176
      }
1177
    } break;
2389 tk 1178
 
1179
        case SEQ_PAR_Type_Aftertouch: {
1180
      if( layer_event.midi_package.event == Aftertouch ) {
1181
        // extra MBSEQ V4L: write into whole 16th step in step record mode
1182
        if(
1183
#ifndef MBSEQV4L
1184
 
1185
#else
1186
           (seq_record_options.STEP_RECORD || !SEQ_BPM_IsRunning()) && tcc->clkdiv.value == 0x03
1187
#endif
1188
           ) {
1189
          int i;
1190
          for(i=0; i<4; ++i)
1191
        SEQ_PAR_Set(track, step*4+i, par_layer, instrument, layer_event.midi_package.evnt1);
1192
        } else {
1193
          SEQ_PAR_Set(track, step, par_layer, instrument, layer_event.midi_package.evnt1);
1194
          return par_layer;
1195
        }
1196
      } else if( layer_event.midi_package.event == PolyPressure ) {
1197
        // extra MBSEQ V4L: write into whole 16th step in step record mode
1198
        if(
1199
#ifndef MBSEQV4L
1200
 
1201
#else
1202
           (seq_record_options.STEP_RECORD || !SEQ_BPM_IsRunning()) && tcc->clkdiv.value == 0x03
1203
#endif
1204
           ) {
1205
          int i;
1206
          for(i=0; i<4; ++i)
1207
        SEQ_PAR_Set(track, step*4+i, par_layer, instrument, layer_event.midi_package.evnt2);
1208
        } else {
1209
          SEQ_PAR_Set(track, step, par_layer, instrument, layer_event.midi_package.evnt2);
1210
          return par_layer;
1211
        }
1212
      }
1213
    } break;
419 tk 1214
      }
1215
    }
1216
  }
1217
 
1218
  return -1; // no matching event found!
1219
}
1220
 
1221
 
1222
/////////////////////////////////////////////////////////////////////////////
1771 tk 1223
// Sends the last CC/PB/PC value of the given track and layer
1224
/////////////////////////////////////////////////////////////////////////////
1225
s32 SEQ_LAYER_DirectSendEvent(u8 track, u8 par_layer)
1226
{
1227
  seq_cc_trk_t *tcc = &seq_cc_trk[track];
1228
  seq_par_layer_type_t layer_type = tcc->lay_const[par_layer];
1229
  mios32_midi_package_t p;
1230
 
1231
  p.cable    = track;
1232
  p.chn      = tcc->midi_chn;
1233
 
1234
  switch( layer_type ) {
1235
  case SEQ_PAR_Type_CC: {
1811 tk 1236
    u8 cc_number = tcc->lay_const[1*16 + par_layer];
2551 tk 1237
    u8 value = (cc_last_value[track][0][par_layer] < 0x80) ? cc_last_value[track][0][par_layer] : 0x40;
1771 tk 1238
 
1811 tk 1239
    if( cc_number >= 0x80 )
1812 tk 1240
      return -1; // CC disabled
1811 tk 1241
 
1771 tk 1242
    p.type      = CC;
1243
    p.event     = CC;
1244
    p.cc_number = tcc->lay_const[1*16 + par_layer];
1245
    p.value     = value;
1246
  } break;
1247
 
1248
  case SEQ_PAR_Type_PitchBend: {
1249
    u8 value = (pb_last_value[track] < 0x80) ? pb_last_value[track] : 0x40;
1250
 
1251
    p.type      = PitchBend;
1252
    p.event     = PitchBend;
1253
    p.evnt1     = (value == 0x40) ? 0x00 : value; // LSB
1254
    p.evnt2     = value;
1255
  } break;
1256
 
1257
  case SEQ_PAR_Type_ProgramChange: {
2389 tk 1258
    u8 value = (pc_last_value[track] < 0x80) ? pc_last_value[track] : 0;
1771 tk 1259
 
1260
    p.type      = ProgramChange;
1261
    p.event     = ProgramChange;
1262
    p.evnt1     = value;
1263
    p.evnt2     = 0x00; // don't care
1264
  } break;
1265
 
2389 tk 1266
  case SEQ_PAR_Type_Aftertouch: {
1267
    u8 value = (at_last_value[track] < 0x80) ? at_last_value[track] : 0;
1268
 
1269
    p.type      = Aftertouch;
1270
    p.event     = Aftertouch;
1271
    p.evnt1     = value;
1272
    p.evnt2     = 0x00; // don't care
1273
  } break;
1274
 
1771 tk 1275
  default:
1276
    return -1; // other parameter types are not supported
1277
  }
1278
 
1279
  // send MIDI event
1280
  MUTEX_MIDIOUT_TAKE;
1281
  MIOS32_MIDI_SendPackage(tcc->midi_port, p);
1282
  MUTEX_MIDIOUT_GIVE;
1283
 
1284
  return 0; // no error
1285
}
1286
 
1287
/////////////////////////////////////////////////////////////////////////////
178 tk 1288
// Initializes a track depending on selected event mode
1289
// "only_layers" flag is used by CLR function
318 tk 1290
// "all_triggers_cleared": if 0, triggers will be initialized according to preset
1291
//                         if 1: triggers will be cleared
335 tk 1292
// "init_assignments": if 1, parameter/trigger assignments will be changed
178 tk 1293
/////////////////////////////////////////////////////////////////////////////
335 tk 1294
s32 SEQ_LAYER_CopyPreset(u8 track, u8 only_layers, u8 all_triggers_cleared, u8 init_assignments)
178 tk 1295
{
1296
  int i;
1297
  int cc;
1298
 
323 tk 1299
  u8 event_mode = SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
178 tk 1300
 
591 tk 1301
  // layer specific mutes always cleared to avoid confusion!
1302
  seq_core_trk[track].layer_muted = 0;
1303
 
178 tk 1304
  if( !only_layers ) {
1305
    // copy static presets
1306
    i = 0;
1307
    while( (cc=seq_layer_preset_table_static[i][0]) != 0xff ) {
1308
      SEQ_CC_Set(track, cc, seq_layer_preset_table_static[i][1]);
1309
      i++;
1310
    }
1311
 
335 tk 1312
    // initialize assignments
1313
    if( init_assignments ) {
1314
      switch( event_mode ) {
1315
        case SEQ_EVENT_MODE_Note:
1313 tk 1316
        case SEQ_EVENT_MODE_Chord:
1316 tk 1317
        case SEQ_EVENT_MODE_Combined: {
335 tk 1318
      // Trigger Layer Assignments
1319
      for(i=0; i<8; ++i)
1320
        SEQ_CC_Set(track, SEQ_CC_ASG_GATE+i, i+1);
323 tk 1321
 
335 tk 1322
      // Parameter Layer Assignments
1316 tk 1323
      if( event_mode == SEQ_EVENT_MODE_Combined ) {
1313 tk 1324
        if( (track&7) == 0 ) {
1325
          for(i=0; i<16; ++i)
1326
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_A1+i, SEQ_PAR_Type_Note);
1327
        } else if( (track&7) == 1 ) {
1328
          for(i=0; i<16; ++i)
1329
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_A1+i, SEQ_PAR_Type_Velocity);
1330
        } else if( (track&7) == 2 ) {
1331
          for(i=0; i<16; ++i)
1332
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_A1+i, SEQ_PAR_Type_Length);
1333
        }
1334
      } else {
1335
        // Parameter Layer Assignments
2274 tk 1336
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_A1, (event_mode == SEQ_EVENT_MODE_Chord) ? SEQ_PAR_Type_Chord1 : SEQ_PAR_Type_Note);
1313 tk 1337
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_A2, SEQ_PAR_Type_Velocity);
1338
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_A3, SEQ_PAR_Type_Length);
1339
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_A4, SEQ_PAR_Type_Roll);
1340
        for(i=4; i<16; ++i)
1341
          SEQ_CC_Set(track, SEQ_CC_LAY_CONST_A1+i, SEQ_PAR_Type_Note);
1342
      }
333 tk 1343
 
1811 tk 1344
      // new: assign disabled CCs by default
335 tk 1345
      for(i=0; i<16; ++i)
1811 tk 1346
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_B1+i, 0x80);
1316 tk 1347
 
335 tk 1348
        } break;
323 tk 1349
 
335 tk 1350
        case SEQ_EVENT_MODE_CC: {
1351
      // Trigger Layer Assignments
1352
      for(i=0; i<8; ++i)
1353
        SEQ_CC_Set(track, SEQ_CC_ASG_GATE+i, i+1);
333 tk 1354
 
335 tk 1355
      // Parameter Layer Assignments
1024 tk 1356
      for(i=0; i<16; ++i)
1357
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_A1+i, SEQ_PAR_Type_CC);
333 tk 1358
 
1316 tk 1359
#ifndef MBSEQV4L
1811 tk 1360
      for(i=0; i<16; ++i) // disable all CCs by default
1361
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_B1+i, 0x80);
1316 tk 1362
#else
1363
      // extra for MBSEQ V4L:
1364
      // CCs disabled and will be assigned during recording
1365
      for(i=0; i<16; ++i)
1366
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_B1+i, 0x80);
1367
 
1368
      // G1T4 and G3T4: first layer assigned to pitchbender
1369
      if( track == 3 || track == 11 )
1370
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_A1+0, SEQ_PAR_Type_PitchBend);
1371
 
1372
      // running with 4x resolution
1373
      SEQ_CC_Set(track, SEQ_CC_CLK_DIVIDER, 0x03);
1374
      SEQ_CC_Set(track, SEQ_CC_LENGTH, 0x3f);
1375
#endif
335 tk 1376
        } break;
1377
 
1378
        case SEQ_EVENT_MODE_Drum: {
1379
      // Trigger Layer Assignments
1380
      SEQ_CC_Set(track, SEQ_CC_ASG_GATE, 1);
1381
      SEQ_CC_Set(track, SEQ_CC_ASG_ACCENT, (SEQ_TRG_NumLayersGet(track) > 1) ? 2 : 0);
1382
      for(i=2; i<8; ++i)
1383
        SEQ_CC_Set(track, SEQ_CC_ASG_GATE+i, 0); // not relevant in drum mode
1384
 
1385
      // parameter layer assignments
596 tk 1386
      if( SEQ_PAR_NumLayersGet(track) > 1 ) {
335 tk 1387
        SEQ_CC_Set(track, SEQ_CC_PAR_ASG_DRUM_LAYER_A, SEQ_PAR_Type_Velocity);
1388
        SEQ_CC_Set(track, SEQ_CC_PAR_ASG_DRUM_LAYER_B, SEQ_PAR_Type_Roll);
2444 tk 1389
        SEQ_CC_Set(track, SEQ_CC_PAR_ASG_DRUM_LAYER_C, SEQ_PAR_Type_Probability);
1390
        SEQ_CC_Set(track, SEQ_CC_PAR_ASG_DRUM_LAYER_D, SEQ_PAR_Type_Nth1);
984 tk 1391
      } else if( SEQ_TRG_NumLayersGet(track) > 1 ) {
335 tk 1392
        SEQ_CC_Set(track, SEQ_CC_PAR_ASG_DRUM_LAYER_A, SEQ_PAR_Type_Roll);
1393
        SEQ_CC_Set(track, SEQ_CC_PAR_ASG_DRUM_LAYER_B, SEQ_PAR_Type_None);
2444 tk 1394
        SEQ_CC_Set(track, SEQ_CC_PAR_ASG_DRUM_LAYER_C, SEQ_PAR_Type_None);
1395
        SEQ_CC_Set(track, SEQ_CC_PAR_ASG_DRUM_LAYER_D, SEQ_PAR_Type_None);
984 tk 1396
      } else {
1397
        SEQ_CC_Set(track, SEQ_CC_PAR_ASG_DRUM_LAYER_A, SEQ_PAR_Type_Velocity);
1398
        SEQ_CC_Set(track, SEQ_CC_PAR_ASG_DRUM_LAYER_B, SEQ_PAR_Type_None);
2444 tk 1399
        SEQ_CC_Set(track, SEQ_CC_PAR_ASG_DRUM_LAYER_C, SEQ_PAR_Type_None);
1400
        SEQ_CC_Set(track, SEQ_CC_PAR_ASG_DRUM_LAYER_D, SEQ_PAR_Type_None);
335 tk 1401
      }
1402
 
1403
      // Constant Layer Values
1404
      int drum;
1405
      for(drum=0; drum<16; ++drum) {
1406
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_A1+drum, seq_layer_preset_table_drum_notes[drum]);
1407
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_B1+drum, 100);
1408
        SEQ_CC_Set(track, SEQ_CC_LAY_CONST_C1+drum, 127);
1409
      }
1410
    } break;
1411
      }
1412
    }
1413
 
1414
    // copy event mode depending settings
1415
    switch( event_mode ) {
1416
      case SEQ_EVENT_MODE_Note:
1417
      case SEQ_EVENT_MODE_Chord:
1313 tk 1418
      case SEQ_EVENT_MODE_CC:
1316 tk 1419
      case SEQ_EVENT_MODE_Combined: {
1811 tk 1420
    // CCs disabled and will be assigned in INIT page or during recording
1341 tk 1421
    for(i=0; i<16; ++i)
1422
      SEQ_CC_Set(track, SEQ_CC_LAY_CONST_B1+i, 0x80);
335 tk 1423
        } break;
323 tk 1424
 
1425
      case SEQ_EVENT_MODE_Drum: {
1426
    int drum;
1427
    for(drum=0; drum<16; ++drum) {
1428
      SEQ_CC_Set(track, SEQ_CC_LAY_CONST_A1+drum, seq_layer_preset_table_drum_notes[drum]);
1429
      SEQ_CC_Set(track, SEQ_CC_LAY_CONST_B1+drum, 100);
1430
      SEQ_CC_Set(track, SEQ_CC_LAY_CONST_C1+drum, 127);
1431
    }
1432
      } break;
178 tk 1433
    }
1434
  }
1435
 
327 tk 1436
 
323 tk 1437
  // get constraints of trigger layers
1438
  int num_t_steps  = SEQ_TRG_NumStepsGet(track);;
318 tk 1439
 
178 tk 1440
  // copy trigger layer values
318 tk 1441
  if( !all_triggers_cleared ) {
1442
    int step8;
328 tk 1443
    u8 instrument = 0;
1444
    u8 layer = 0;
318 tk 1445
 
323 tk 1446
    if( event_mode == SEQ_EVENT_MODE_CC ) {
1447
      // CC: enable gate for all steps
318 tk 1448
      for(step8=0; step8<(num_t_steps/8); ++step8)
328 tk 1449
    SEQ_TRG_Set8(track, step8, layer, instrument, 0xff);
1316 tk 1450
    } else if( event_mode == SEQ_EVENT_MODE_Combined ) {
1313 tk 1451
      // Combined: clear all gates
1452
      for(step8=0; step8<(num_t_steps/8); ++step8)
1453
    SEQ_TRG_Set8(track, step8, layer, instrument, 0x00);
323 tk 1454
    } else {
1455
      // Note/Chord/Drum: enable trigger for each beat of (first) gate layer
2294 tk 1456
      // New: can be disabled with INIT_WITH_TRIGGERS = 0 (configureable in OPTIONS menu)
323 tk 1457
      for(step8=0; step8<(num_t_steps/8); ++step8)
2294 tk 1458
    SEQ_TRG_Set8(track, step8, layer, instrument, seq_core_options.INIT_WITH_TRIGGERS ? 0x11 : 0x00);
318 tk 1459
    }
178 tk 1460
  }
1461
 
327 tk 1462
 
178 tk 1463
  // copy parameter layer values
303 tk 1464
  int par_layer;
333 tk 1465
  int num_p_layers = SEQ_PAR_NumLayersGet(track);
1466
  for(par_layer=0; par_layer<num_p_layers; ++par_layer)
1467
    SEQ_LAYER_CopyParLayerPreset(track, par_layer);
323 tk 1468
 
333 tk 1469
  return 0; // no error
1470
}
323 tk 1471
 
1472
 
333 tk 1473
/////////////////////////////////////////////////////////////////////////////
1474
// Copies parameter layer preset depending on selected parameter type
1475
/////////////////////////////////////////////////////////////////////////////
1476
s32 SEQ_LAYER_CopyParLayerPreset(u8 track, u8 par_layer)
1477
{
1478
  int num_p_instruments = SEQ_PAR_NumInstrumentsGet(track);
1479
  int num_p_steps  = SEQ_PAR_NumStepsGet(track);;
1316 tk 1480
  u8 init_value = SEQ_PAR_InitValueGet(SEQ_PAR_AssignmentGet(track, par_layer), par_layer);
178 tk 1481
 
1316 tk 1482
  int step;
1483
  int instrument;
1484
  for(instrument=0; instrument<num_p_instruments; ++instrument)
1485
    for(step=0; step<num_p_steps; ++step)
1486
      SEQ_PAR_Set(track, step, par_layer, instrument, init_value);
323 tk 1487
 
178 tk 1488
  return 0; // no error
1489
}