Subversion Repositories svn.mios32

Rev

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

Rev Author Line No. Line
174 tk 1
// $Id: seq_ui_trkevnt.c 690 2009-08-04 22:49:33Z tk $
2
/*
319 tk 3
 * Track event page
174 tk 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>
326 tk 19
#include <string.h>
174 tk 20
#include "seq_lcd.h"
21
#include "seq_ui.h"
22
#include "seq_cc.h"
333 tk 23
#include "seq_par.h"
174 tk 24
#include "seq_layer.h"
690 tk 25
#include "seq_midi_port.h"
26
#include "seq_label.h"
174 tk 27
 
28
 
29
/////////////////////////////////////////////////////////////////////////////
30
// Local definitions
31
/////////////////////////////////////////////////////////////////////////////
32
 
319 tk 33
// Note/Chord/CC
472 tk 34
#define NUM_OF_ITEMS_NORMAL 8
319 tk 35
#define ITEM_GXTY           0
36
#define ITEM_EVENT_MODE     1
37
#define ITEM_MIDI_PORT      2
38
#define ITEM_MIDI_CHANNEL   3
472 tk 39
#define ITEM_EDIT_NAME      4
40
#define ITEM_LAYER_SELECT   5
41
#define ITEM_LAYER_CONTROL  6
42
#define ITEM_LAYER_PAR      7
174 tk 43
 
319 tk 44
// Drum
45
#define NUM_OF_ITEMS_DRUM   11
472 tk 46
//#define ITEM_GXTY           0
47
//#define ITEM_EVENT_MODE     1
48
//#define ITEM_MIDI_PORT      2
49
//#define ITEM_MIDI_CHANNEL   3
50
//#define ITEM_EDIT_NAME      4
319 tk 51
#define ITEM_LAYER_A_SELECT 5
52
#define ITEM_LAYER_B_SELECT 6
53
#define ITEM_DRUM_SELECT    7
54
#define ITEM_DRUM_NOTE      8
55
#define ITEM_DRUM_VEL_N     9
56
#define ITEM_DRUM_VEL_A     10
174 tk 57
 
319 tk 58
 
472 tk 59
#define NUM_OF_ITEMS_EDIT_MODE 11
60
#define ITEM_EDIT_CHAR     5
61
#define ITEM_EDIT_CURSOR   6
62
#define ITEM_EDIT_INS      7
63
#define ITEM_EDIT_CLR      8
64
#define ITEM_EDIT_PRESET_CATEG  9
65
#define ITEM_EDIT_PRESET_LABEL  10
319 tk 66
 
472 tk 67
 
68
 
174 tk 69
/////////////////////////////////////////////////////////////////////////////
323 tk 70
// Local types
71
/////////////////////////////////////////////////////////////////////////////
72
 
73
typedef struct {
74
  seq_event_mode_t event_mode;  // event mode as forwarded to SEQ_CC_MIDI_EVENT_MODE
75
  u8               par_layers;  // number of parameter layers
76
  u16              par_steps;   // number of steps per parameter layer
77
  u8               trg_layers;  // number of trigger layers
78
  u16              trg_steps;   // number of steps per trigger layer
328 tk 79
  u8               instruments; // number of instruments per track
323 tk 80
} layer_config_t;
81
 
82
 
83
/////////////////////////////////////////////////////////////////////////////
176 tk 84
// Local prototypes
85
/////////////////////////////////////////////////////////////////////////////
86
 
323 tk 87
static s32 GetLayerConfig(u8 track);
88
static s32 CopyPreset(u8 track, u8 config);
176 tk 89
 
90
 
91
/////////////////////////////////////////////////////////////////////////////
178 tk 92
// Local variables
93
/////////////////////////////////////////////////////////////////////////////
94
 
481 tk 95
static u8 edit_label_mode;
472 tk 96
 
323 tk 97
static u8 selected_layer_config;
472 tk 98
static u8 selected_layer_config_track;
319 tk 99
 
472 tk 100
static const layer_config_t layer_config[] = {
328 tk 101
  //      mode           par_layers  par_steps  trg_layers  trg_steps  instruments
102
  { SEQ_EVENT_MODE_Note,    16,          64,        8,          64,      1 },
103
  { SEQ_EVENT_MODE_Note,     8,         128,        8,         128,      1 },
104
  { SEQ_EVENT_MODE_Note,     4,         256,        8,         256,      1 },
105
  { SEQ_EVENT_MODE_Chord,   16,          64,        8,          64,      1 },
106
  { SEQ_EVENT_MODE_Chord,    8,         128,        8,         128,      1 },
107
  { SEQ_EVENT_MODE_Chord,    4,         256,        8,         256,      1 },
108
  { SEQ_EVENT_MODE_CC,      16,          64,        8,          64,      1 },
109
  { SEQ_EVENT_MODE_CC,       8,         128,        8,         128,      1 },
110
  { SEQ_EVENT_MODE_CC,       4,         256,        8,         256,      1 },
111
  { SEQ_EVENT_MODE_Drum,     1,          64,        2,          64,     16 },
112
  { SEQ_EVENT_MODE_Drum,     2,          32,        1,         128,     16 },
113
  { SEQ_EVENT_MODE_Drum,     1,         128,        2,         128,      8 },
114
  { SEQ_EVENT_MODE_Drum,     2,          64,        1,         256,      8 }
323 tk 115
};
116
 
319 tk 117
 
178 tk 118
/////////////////////////////////////////////////////////////////////////////
174 tk 119
// Local LED handler function
120
/////////////////////////////////////////////////////////////////////////////
121
static s32 LED_Handler(u16 *gp_leds)
122
{
178 tk 123
  if( ui_cursor_flash ) { // if flashing flag active: no LED flag set
323 tk 124
    // flash INIT LED if current preset doesn't match with old preset
125
    // this notifies the user, that he should press the "INIT" button
178 tk 126
    u8 visible_track = SEQ_UI_VisibleTrackGet();
481 tk 127
    if( !edit_label_mode && selected_layer_config != GetLayerConfig(visible_track) )
319 tk 128
      *gp_leds = 0x8000;
178 tk 129
 
174 tk 130
    return 0;
178 tk 131
  }
174 tk 132
 
481 tk 133
  if( edit_label_mode ) {
319 tk 134
    switch( ui_selected_item ) {
135
      case ITEM_GXTY: *gp_leds = 0x0001; break;
136
      case ITEM_EVENT_MODE: *gp_leds = 0x001e; break;
137
      case ITEM_MIDI_PORT: *gp_leds = 0x0020; break;
138
      case ITEM_MIDI_CHANNEL: *gp_leds = 0x0040; break;
472 tk 139
      case ITEM_EDIT_NAME: *gp_leds = 0x0080; break;
140
      case ITEM_EDIT_CHAR:     *gp_leds = 0x0100; break;
141
      case ITEM_EDIT_CURSOR:   *gp_leds = 0x0200; break;
142
      case ITEM_EDIT_INS:      *gp_leds = 0x0400; break;
143
      case ITEM_EDIT_CLR:      *gp_leds = 0x0800; break;
481 tk 144
      case ITEM_EDIT_PRESET_CATEG:  *gp_leds = 0x4000; break;
145
      case ITEM_EDIT_PRESET_LABEL:  *gp_leds = 0x8000; break;
472 tk 146
    }
147
  } else if( layer_config[selected_layer_config].event_mode == SEQ_EVENT_MODE_Drum ) {
148
    switch( ui_selected_item ) {
149
      case ITEM_GXTY: *gp_leds = 0x0001; break;
150
      case ITEM_EVENT_MODE: *gp_leds = 0x001e; break;
151
      case ITEM_MIDI_PORT: *gp_leds = 0x0020; break;
152
      case ITEM_MIDI_CHANNEL: *gp_leds = 0x0040; break;
153
      case ITEM_EDIT_NAME: *gp_leds = 0x0080; break;
319 tk 154
      case ITEM_LAYER_A_SELECT: *gp_leds = 0x0100; break;
155
      case ITEM_LAYER_B_SELECT: *gp_leds = 0x0200; break;
156
      case ITEM_DRUM_SELECT: *gp_leds = 0x0400; break;
157
      case ITEM_DRUM_NOTE: *gp_leds = 0x0800; break;
158
      case ITEM_DRUM_VEL_N: *gp_leds = 0x1000; break;
159
      case ITEM_DRUM_VEL_A: *gp_leds = 0x2000; break;
160
    }
161
  } else {
162
    switch( ui_selected_item ) {
163
      case ITEM_GXTY: *gp_leds = 0x0001; break;
164
      case ITEM_EVENT_MODE: *gp_leds = 0x001e; break;
165
      case ITEM_MIDI_PORT: *gp_leds = 0x0020; break;
166
      case ITEM_MIDI_CHANNEL: *gp_leds = 0x0040; break;
472 tk 167
      case ITEM_EDIT_NAME: *gp_leds = 0x0080; break;
319 tk 168
      case ITEM_LAYER_SELECT: *gp_leds = 0x0100; break;
323 tk 169
      case ITEM_LAYER_CONTROL: *gp_leds = 0x0200; break;
170
      case ITEM_LAYER_PAR: *gp_leds = 0x3c00; break;
319 tk 171
    }
174 tk 172
  }
173
 
472 tk 174
  // always flash "edit track" LED if name is edited
481 tk 175
  if( edit_label_mode )
472 tk 176
    *gp_leds |= 0x0080;
177
 
174 tk 178
  return 0; // no error
179
}
180
 
181
 
182
/////////////////////////////////////////////////////////////////////////////
183
// Local encoder callback function
184
// Should return:
185
//   1 if value has been changed
186
//   0 if value hasn't been changed
187
//  -1 if invalid or unsupported encoder
188
/////////////////////////////////////////////////////////////////////////////
189
static s32 Encoder_Handler(seq_ui_encoder_t encoder, s32 incrementer)
190
{
323 tk 191
  u8 event_mode = layer_config[selected_layer_config].event_mode;
335 tk 192
  u8 visible_track = SEQ_UI_VisibleTrackGet();
178 tk 193
 
472 tk 194
  if( encoder >= SEQ_UI_ENCODER_GP9 && encoder <= SEQ_UI_ENCODER_GP16 ) {
481 tk 195
    if( edit_label_mode ) {
472 tk 196
      switch( encoder ) {
197
        case SEQ_UI_ENCODER_GP9:
198
      ui_selected_item = ITEM_EDIT_CHAR;
199
      break;
174 tk 200
 
472 tk 201
        case SEQ_UI_ENCODER_GP10:
202
      ui_selected_item = ITEM_EDIT_CURSOR;
203
      break;
174 tk 204
 
472 tk 205
        case SEQ_UI_ENCODER_GP11:
206
      ui_selected_item = ITEM_EDIT_INS;
207
      break;
174 tk 208
 
472 tk 209
        case SEQ_UI_ENCODER_GP12:
210
      ui_selected_item = ITEM_EDIT_CLR;
211
      break;
174 tk 212
 
472 tk 213
        case SEQ_UI_ENCODER_GP13:
481 tk 214
        case SEQ_UI_ENCODER_GP14:
472 tk 215
      return -1; // not mapped
216
 
481 tk 217
        case SEQ_UI_ENCODER_GP15:
472 tk 218
      ui_selected_item = ITEM_EDIT_PRESET_CATEG;
219
      break;
220
 
481 tk 221
        case SEQ_UI_ENCODER_GP16:
472 tk 222
      ui_selected_item = ITEM_EDIT_PRESET_LABEL;
223
      break;
224
      }
225
    } else {
226
      if( selected_layer_config != GetLayerConfig(visible_track) ) {
227
    // no ENC function available
319 tk 228
    return -1;
472 tk 229
      }
174 tk 230
 
472 tk 231
      switch( encoder ) {
232
        case SEQ_UI_ENCODER_GP9:
233
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_LAYER_A_SELECT : ITEM_LAYER_SELECT;
234
      break;
174 tk 235
 
472 tk 236
        case SEQ_UI_ENCODER_GP10:
237
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_LAYER_B_SELECT : ITEM_LAYER_CONTROL;
238
      break;
174 tk 239
 
472 tk 240
        case SEQ_UI_ENCODER_GP11:
241
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_SELECT : ITEM_LAYER_PAR;
242
      break;
319 tk 243
 
472 tk 244
        case SEQ_UI_ENCODER_GP12:
245
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_NOTE : ITEM_LAYER_PAR;
246
      break;
319 tk 247
 
472 tk 248
        case SEQ_UI_ENCODER_GP13:
249
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_VEL_N : ITEM_LAYER_PAR;
250
      break;
319 tk 251
 
472 tk 252
        case SEQ_UI_ENCODER_GP14:
253
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_VEL_A : ITEM_LAYER_PAR;
254
      break;
174 tk 255
 
472 tk 256
        case SEQ_UI_ENCODER_GP15:
257
      return -1; // not mapped to encoder
319 tk 258
 
472 tk 259
        case SEQ_UI_ENCODER_GP16:
260
      return -1; // not mapped to encoder
261
      }
262
    }
263
  } else {
264
    switch( encoder ) {
265
      case SEQ_UI_ENCODER_GP1:
266
    ui_selected_item = ITEM_GXTY;
267
    break;
268
 
269
      case SEQ_UI_ENCODER_GP2:
270
      case SEQ_UI_ENCODER_GP3:
271
      case SEQ_UI_ENCODER_GP4:
272
      case SEQ_UI_ENCODER_GP5:
273
    ui_selected_item = ITEM_EVENT_MODE;
274
    break;
275
 
276
      case SEQ_UI_ENCODER_GP6:
277
    ui_selected_item = ITEM_MIDI_PORT;
278
    break;
279
 
280
      case SEQ_UI_ENCODER_GP7:
281
    ui_selected_item = ITEM_MIDI_CHANNEL;
282
    break;
283
 
284
      case SEQ_UI_ENCODER_GP8:
285
    ui_selected_item = ITEM_EDIT_NAME;
286
    break;
287
    }
174 tk 288
  }
289
 
290
  // for GP encoders and Datawheel
291
  switch( ui_selected_item ) {
292
    case ITEM_GXTY:          return SEQ_UI_GxTyInc(incrementer);
323 tk 293
    case ITEM_EVENT_MODE: {
294
      u8 max_layer_config = (sizeof(layer_config)/sizeof(layer_config_t)) - 1;
295
      return SEQ_UI_Var8_Inc(&selected_layer_config, 0, max_layer_config, incrementer);
296
    } break;
472 tk 297
 
285 tk 298
    case ITEM_MIDI_PORT: {
299
      mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
300
      u8 port_ix = SEQ_MIDI_PORT_OutIxGet(port);
301
      if( SEQ_UI_Var8_Inc(&port_ix, 0, SEQ_MIDI_PORT_OutNumGet()-1, incrementer) ) {
302
    mios32_midi_port_t new_port = SEQ_MIDI_PORT_OutPortGet(port_ix);
303
    SEQ_UI_CC_Set(SEQ_CC_MIDI_PORT, new_port);
304
    return 1; // value changed
305
      }
306
      return 0; // value not changed
307
    } break;
472 tk 308
 
319 tk 309
    case ITEM_MIDI_CHANNEL:  return SEQ_UI_CC_Inc(SEQ_CC_MIDI_CHANNEL, 0, 15, incrementer);
472 tk 310
 
481 tk 311
    case ITEM_EDIT_NAME: return SEQ_UI_Var8_Inc(&edit_label_mode, 0, 1, incrementer);
174 tk 312
  }
313
 
481 tk 314
  if( edit_label_mode ) {
319 tk 315
    switch( ui_selected_item ) {
472 tk 316
    case ITEM_EDIT_CHAR:
317
      return SEQ_UI_Var8_Inc((u8 *)&seq_core_trk[visible_track].name[ui_edit_name_cursor], 32, 127, incrementer);
318
 
319
    case ITEM_EDIT_CURSOR:
320
      return SEQ_UI_Var8_Inc(&ui_edit_name_cursor, 0, 20-1, incrementer);
321
 
322
    case ITEM_EDIT_INS: {
323
      u8 field_end = (ui_edit_name_cursor < 5) ? 4 : 19;
324
      int i;
325
      for(i=field_end; i>ui_edit_name_cursor; --i) {
326
    seq_core_trk[visible_track].name[i] = seq_core_trk[visible_track].name[i-1];
327
      }
328
      seq_core_trk[visible_track].name[ui_edit_name_cursor] = ' ';
329
      return 1;
330
    } break;
331
 
332
    case ITEM_EDIT_CLR: {
333
      u8 field_end = (ui_edit_name_cursor < 5) ? 4 : 19;
334
      int i;
335
      for(i=ui_edit_name_cursor; i<field_end; ++i) {
336
    seq_core_trk[visible_track].name[i] = seq_core_trk[visible_track].name[i+1];
337
      }
338
      seq_core_trk[visible_track].name[field_end] = ' ';
339
      return 1;
340
    } break;
341
 
342
    case ITEM_EDIT_PRESET_CATEG:
343
      if( ui_edit_name_cursor >= 5 ) // set cursor to category field if required (more intuitive usage)
344
    ui_edit_name_cursor = 0;
345
 
346
      if( SEQ_UI_Var8_Inc(&ui_edit_preset_num_category, 0, SEQ_LABEL_NumPresetsCategory()-1, incrementer) ) {
347
    SEQ_LABEL_CopyPresetCategory(ui_edit_preset_num_category, (char *)&seq_core_trk[visible_track].name[0]);
348
    return 1;
349
      }
350
      return 0;
351
 
352
    case ITEM_EDIT_PRESET_LABEL:
353
      if( ui_edit_name_cursor < 5 ) // set cursor to category field if required (more intuitive usage)
354
    ui_edit_name_cursor = 5;
355
 
356
      if( SEQ_UI_Var8_Inc(&ui_edit_preset_num_label, 0, SEQ_LABEL_NumPresets()-1, incrementer) ) {
357
    SEQ_LABEL_CopyPreset(ui_edit_preset_num_label, (char *)&seq_core_trk[visible_track].name[5]);
358
    return 1;
359
      }
360
      return 0;
361
 
362
    }
363
  } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
364
    switch( ui_selected_item ) {
325 tk 365
      case ITEM_DRUM_SELECT: {
328 tk 366
        u8 num_drums = layer_config[selected_layer_config].instruments;
336 tk 367
        return SEQ_UI_Var8_Inc(&ui_selected_instrument, 0, num_drums-1, incrementer);
325 tk 368
      } break;
335 tk 369
      case ITEM_LAYER_A_SELECT: {
370
        if( SEQ_UI_CC_Inc(SEQ_CC_PAR_ASG_DRUM_LAYER_A, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
336 tk 371
      SEQ_LAYER_CopyParLayerPreset(visible_track, 0);
335 tk 372
      return 1;
373
    }
374
    return 0;
375
      } break;
376
      case ITEM_LAYER_B_SELECT: {
377
        if( SEQ_UI_CC_Inc(SEQ_CC_PAR_ASG_DRUM_LAYER_B, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
336 tk 378
      SEQ_LAYER_CopyParLayerPreset(visible_track, 1);
335 tk 379
      return 1;
380
    }
381
    return 0;
382
      } break;
336 tk 383
      case ITEM_DRUM_NOTE:     return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_A1 + ui_selected_instrument, 0, 127, incrementer);
384
      case ITEM_DRUM_VEL_N:    return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_B1 + ui_selected_instrument, 0, 127, incrementer);
385
      case ITEM_DRUM_VEL_A:    return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_C1 + ui_selected_instrument, 0, 127, incrementer);
319 tk 386
    }
387
  } else {
388
    switch( ui_selected_item ) {
336 tk 389
      case ITEM_LAYER_SELECT:  return SEQ_UI_Var8_Inc(&ui_selected_par_layer, 0, 15, incrementer);
390
      case ITEM_LAYER_PAR:     return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer, 0, 127, incrementer);
333 tk 391
      case ITEM_LAYER_CONTROL: {
392
    // TODO: has to be done for all selected tracks
336 tk 393
    if( SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_A1 + ui_selected_par_layer, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
394
      SEQ_LAYER_CopyParLayerPreset(visible_track, ui_selected_par_layer);
333 tk 395
      return 1;
396
    }
397
    return 0;
398
      } break;
319 tk 399
    }
400
  }
401
 
174 tk 402
  return -1; // invalid or unsupported encoder
403
}
404
 
405
 
406
/////////////////////////////////////////////////////////////////////////////
407
// Local button callback function
408
// Should return:
409
//   1 if value has been changed
410
//   0 if value hasn't been changed
411
//  -1 if invalid or unsupported button
412
/////////////////////////////////////////////////////////////////////////////
413
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
414
{
415
  if( depressed ) return 0; // ignore when button depressed
416
 
472 tk 417
  u8 visible_track = SEQ_UI_VisibleTrackGet();
323 tk 418
  u8 event_mode = layer_config[selected_layer_config].event_mode;
419
 
472 tk 420
  if( button >= SEQ_UI_BUTTON_GP9 && button <= SEQ_UI_BUTTON_GP16 ) {
481 tk 421
    if( edit_label_mode ) {
472 tk 422
      switch( button ) {
423
        case SEQ_UI_BUTTON_GP9:
424
      ui_selected_item = ITEM_EDIT_CHAR;
425
      break;
426
 
427
        case SEQ_UI_BUTTON_GP10:
428
      ui_selected_item = ITEM_EDIT_CURSOR;
429
      break;
430
 
431
        case SEQ_UI_BUTTON_GP11:
432
      return Encoder_Handler(SEQ_UI_ENCODER_GP11, 1);
433
 
434
        case SEQ_UI_BUTTON_GP12:
435
      return Encoder_Handler(SEQ_UI_ENCODER_GP12, 1);
436
 
437
        case SEQ_UI_BUTTON_GP13:
481 tk 438
        case SEQ_UI_BUTTON_GP14:
439
      return -1; // not mapped
472 tk 440
 
481 tk 441
        case SEQ_UI_BUTTON_GP15:
472 tk 442
      ui_selected_item = ITEM_EDIT_PRESET_CATEG;
443
      break;
444
 
481 tk 445
        case SEQ_UI_BUTTON_GP16:
472 tk 446
      ui_selected_item = ITEM_EDIT_PRESET_LABEL;
447
      break;
448
      }
449
    } else {
450
      if( selected_layer_config != GetLayerConfig(visible_track) ) {
451
    // uninitialized track: only GP16 available
452
    if( button != SEQ_UI_BUTTON_GP16 )
453
      return -1;
454
      }
455
 
456
      switch( button ) {
457
        case SEQ_UI_BUTTON_GP9:
458
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_LAYER_A_SELECT : ITEM_LAYER_SELECT;
459
      return 1;
460
 
461
        case SEQ_UI_BUTTON_GP10:
462
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_LAYER_B_SELECT : ITEM_LAYER_CONTROL;
463
      return 1;
464
 
465
        case SEQ_UI_BUTTON_GP11:
466
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_SELECT : ITEM_LAYER_CONTROL;
467
      return 1;
468
 
469
        case SEQ_UI_BUTTON_GP12:
470
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_NOTE : ITEM_LAYER_CONTROL;
471
      return 1;
472
 
473
        case SEQ_UI_BUTTON_GP13:
474
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_VEL_N : ITEM_LAYER_CONTROL;
475
      return 1;
476
 
477
        case SEQ_UI_BUTTON_GP14:
478
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_VEL_A : ITEM_LAYER_CONTROL;
479
      return 1;
480
 
481
        case SEQ_UI_BUTTON_GP15:
482
      return -1; // not mapped
483
 
484
        case SEQ_UI_BUTTON_GP16:
485
      // ui_selected_item = ITEM_PRESET;
486
      // TODO: copy preset for all selected tracks!
487
      CopyPreset(visible_track, selected_layer_config);
488
      return 1; // value has been changed
489
      }
490
    }
491
  }
492
 
174 tk 493
  switch( button ) {
323 tk 494
    case SEQ_UI_BUTTON_GP1:
174 tk 495
      ui_selected_item = ITEM_GXTY;
319 tk 496
      return 1;
174 tk 497
 
323 tk 498
    case SEQ_UI_BUTTON_GP2:
499
    case SEQ_UI_BUTTON_GP3:
500
    case SEQ_UI_BUTTON_GP4:
501
    case SEQ_UI_BUTTON_GP5:
319 tk 502
      ui_selected_item = ITEM_EVENT_MODE;
503
      return 1;
174 tk 504
 
323 tk 505
    case SEQ_UI_BUTTON_GP6:
319 tk 506
      ui_selected_item = ITEM_MIDI_PORT;
507
      return 1;
174 tk 508
 
323 tk 509
    case SEQ_UI_BUTTON_GP7:
319 tk 510
      ui_selected_item = ITEM_MIDI_CHANNEL;
511
      return 1;
174 tk 512
 
323 tk 513
    case SEQ_UI_BUTTON_GP8:
472 tk 514
      // toggle "edit name" mode
481 tk 515
      return Encoder_Handler((seq_ui_encoder_t)button, edit_label_mode ? -1 : 1);
174 tk 516
 
517
    case SEQ_UI_BUTTON_Select:
518
    case SEQ_UI_BUTTON_Right:
481 tk 519
      if( edit_label_mode ) {
472 tk 520
    if( ++ui_selected_item >= NUM_OF_ITEMS_EDIT_MODE )
521
      ui_selected_item = 0;
522
      } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
319 tk 523
    if( ++ui_selected_item >= NUM_OF_ITEMS_DRUM )
524
      ui_selected_item = 0;
525
      } else {
526
    if( ++ui_selected_item >= NUM_OF_ITEMS_NORMAL )
527
      ui_selected_item = 0;
528
      }
529
 
174 tk 530
      return 1; // value always changed
531
 
532
    case SEQ_UI_BUTTON_Left:
481 tk 533
      if( edit_label_mode ) {
319 tk 534
    if( ui_selected_item == 0 )
472 tk 535
      ui_selected_item = NUM_OF_ITEMS_EDIT_MODE-1;
536
      } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
537
    if( ui_selected_item == 0 )
319 tk 538
      ui_selected_item = NUM_OF_ITEMS_DRUM-1;
539
      } else {
540
    if( ui_selected_item == 0 )
541
      ui_selected_item = NUM_OF_ITEMS_NORMAL-1;
542
      }
174 tk 543
      return 1; // value always changed
544
 
545
    case SEQ_UI_BUTTON_Up:
546
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
547
 
548
    case SEQ_UI_BUTTON_Down:
549
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
550
  }
551
 
552
  return -1; // invalid or unsupported button
553
}
554
 
555
 
556
/////////////////////////////////////////////////////////////////////////////
557
// Local Display Handler function
558
// IN: <high_prio>: if set, a high-priority LCD update is requested
559
/////////////////////////////////////////////////////////////////////////////
560
static s32 LCD_Handler(u8 high_prio)
561
{
562
  if( high_prio )
563
    return 0; // there are no high-priority updates
564
 
565
  // layout:
566
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
567
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
568
  // <--------------------------------------><-------------------------------------->
472 tk 569
  // Trk. Type Steps/ParL/TrgL Port Chn. EditLayer  controls                         
570
  // G1T1 Note  256   4     8  IIC2  12  Name  D    Prob                         INIT
174 tk 571
 
472 tk 572
  // Trk. Type Steps/ParL/TrgL Port Chn. EditLayer  controls                         
573
  // G1T1 Note  256   4     8  IIC2  12  Name  D    CC #001 ModWheel             INIT
319 tk 574
 
575
  // Track Type "Note", Chord" and "CC":
576
  // Note: Parameter Layer A/B/C statically assigned to Note Number/Velocity/Length
577
  //       Parameter Layer D..P can be mapped to
578
  //       - additional Notes (e.g. for poly recording)
579
  //       - Base note (directly forwarded to Transposer, e.g. for Force-to-Scale or Chords)
580
  //       - CC (Number 000..127 assignable, GM controller name will be displayed)
581
  //       - Pitch Bender
582
  //       - Loopback (Number 000..127 assignable, name will be displayed)
338 tk 583
  //       - Delay (0..95 ticks @384 ppqn)
319 tk 584
  //       - Probability (100%..0%)
327 tk 585
  //       - "Roll/Flam Effect" (a selection of up to 128 different effects selectable for each step separately)
319 tk 586
  // Chord: same like Note, but predefined Chords will be played
587
  // CC: Layer A/B/C play CCs (or other parameters) as well - no note number, no velocity, no length
588
 
589
  // Available Layer Constraints (Partitioning for 1024 bytes Par. memory, 2048 bits Trg. memory)
590
  //    - 256 Steps with  4 Parameter Layers A-D and 8 Trigger Layers A-H
591
  //    - 128 Steps with  8 Parameter Layers A-H and 8 Trigger Layers A-H
592
  //    -  64 Steps with 16 Parameter Layers A-P and 8 Trigger Layers A-H
593
 
594
 
595
  // layout:
596
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
597
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
598
  // <--------------------------------------><-------------------------------------->
472 tk 599
  // Trk. Type StepsP/T  Drums Port Chn. EditLayA LayB  Drum Note VelN VelA          
600
  // G1T1 Drum  (64/2*64) 16   USB1  10  NamePrb. ----   BD   C-1  100  127      INIT
319 tk 601
 
472 tk 602
  // Trk. Type StepsP/T  Drums Port Chn. EditLayA LayB  Drum Note VelN VelA          
603
  // G1T1 Drum  (2*64/256) 8   USB1  12  NameVel. Len.   SD   D-1  ---  ---      INIT
319 tk 604
 
605
 
606
  // Track Type "Drums":
327 tk 607
  //    1 or 2 parameter layers for each trigger layer (drum instrument).
608
  //    If parameters layers consist of more than 1024 steps in total, steps > 1024 will be mirrored
609
  //    assignable to Velocity/Gatelength/Delay/Probability/Roll/Flam only
319 tk 610
  //    (no CC, no Pitch Bender, no Loopback, as they don't work note-wise, but 
611
  //     only channel wise
612
  //     just send them from a different track)
613
 
614
  // Each drum instrument provides 4 constant parameters for:
615
  //   - Note Number
472 tk 616
  //   - MIDI Channel (1-16) for all drum instruments (TODO: optionally allow to use a "local" channel, edit parameter right of VelA)
319 tk 617
  //   - Velocity Normal (if not taken from Parameter Layer)
618
  //   - Velocity Accented (if not taken from Parameter Layer)
619
 
620
 
621
  // Available Layer Constraints (Partitioning for 1024 bytes Par. memory, 2048 bits Trg. memory)
327 tk 622
  //    - 16 Parameter Layers with 64 steps and 2*16 Trigger Layers A-P with 64 steps taken for Gate and Accent
623
  //    - 2*16 Parameter Layer with 32 steps and 16 Trigger Layers A-P with 128 steps taken for Gate
624
  //    - 8 Parameter Layer with 128 steps and 2*8 Trigger Layers A-P with 128 steps taken for Gate and Accent
625
  //    - 2*8 Parameter Layer with 64 steps and 8 Trigger Layers A-P with 256 steps taken for Gate
319 tk 626
 
472 tk 627
 
628
 
629
  // "Edit Name" layout:
630
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
631
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
632
  // <--------------------------------------><-------------------------------------->
633
  // Trk. Type Steps/ParL/TrgL Port Chn. EditCategory: xxxxx   Label: xxxxxxxxxxxxxxx
481 tk 634
  // G1T1 Note  256   4     8  IIC2  12  NameChar  Cur  Ins  Clr    Preset Cat./Label
472 tk 635
 
174 tk 636
  u8 visible_track = SEQ_UI_VisibleTrackGet();
472 tk 637
 
638
  // if track has changed, switch layer config:
639
  if( visible_track != selected_layer_config_track ) {
640
    selected_layer_config_track = visible_track;
641
    selected_layer_config = GetLayerConfig(selected_layer_config_track);
642
  }
643
 
323 tk 644
  u8 event_mode = layer_config[selected_layer_config].event_mode;
174 tk 645
 
472 tk 646
 
174 tk 647
  ///////////////////////////////////////////////////////////////////////////
278 tk 648
  SEQ_LCD_CursorSet(0, 0);
319 tk 649
 
472 tk 650
  SEQ_LCD_PrintString("Trk. Type ");
651
  SEQ_LCD_PrintString((event_mode == SEQ_EVENT_MODE_Drum) ? "StepsP/T  Drums " : "Steps/ParL/TrgL ");
652
  SEQ_LCD_PrintString("Port Chn. ");
653
 
654
  if( ui_selected_item == ITEM_EDIT_NAME && ui_cursor_flash ) {
655
    SEQ_LCD_PrintSpaces(4);
656
  } else {
657
    SEQ_LCD_PrintFormattedString("Edit");
658
  }
659
 
481 tk 660
  if( edit_label_mode ) {
472 tk 661
    SEQ_LCD_PrintString("Category: ");
662
    SEQ_LCD_PrintTrackCategory(visible_track, seq_core_trk[visible_track].name);
663
    SEQ_LCD_PrintString("   Label: ");
664
    SEQ_LCD_PrintTrackLabel(visible_track, seq_core_trk[visible_track].name);
665
 
666
    // insert flashing cursor
667
    if( ui_cursor_flash ) {
668
      SEQ_LCD_CursorSet(40 + ((ui_edit_name_cursor < 5) ? 10 : 20) + ui_edit_name_cursor, 0);
669
      SEQ_LCD_PrintChar('*');
670
    }
671
  } else if( selected_layer_config != GetLayerConfig(visible_track) ) {
672
    SEQ_LCD_PrintString("    Please initialize the track         ");
673
  } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
319 tk 674
    SEQ_LCD_PrintString("LayA ");
472 tk 675
    SEQ_LCD_PrintString((layer_config[selected_layer_config].par_layers >= 2) ? "LayB " : "     ");
676
    SEQ_LCD_PrintString(" Drum Note VelN VelA          ");
174 tk 677
  } else {
472 tk 678
    SEQ_LCD_PrintString("Layer  controls                         ");
174 tk 679
  }
680
 
681
  ///////////////////////////////////////////////////////////////////////////
278 tk 682
  SEQ_LCD_CursorSet(0, 1);
174 tk 683
 
684
  if( ui_selected_item == ITEM_GXTY && ui_cursor_flash ) {
685
    SEQ_LCD_PrintSpaces(5);
686
  } else {
687
    SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
688
    SEQ_LCD_PrintSpaces(1);
689
  }
690
 
691
  ///////////////////////////////////////////////////////////////////////////
692
 
319 tk 693
  if( ui_selected_item == ITEM_EVENT_MODE && ui_cursor_flash ) {
694
    SEQ_LCD_PrintSpaces(21);
695
  } else {
696
    const char event_mode_str[4][6] = { "Note ", "Chord", " CC  ", "Drum " };
690 tk 697
    SEQ_LCD_PrintString((char *)event_mode_str[event_mode]);
174 tk 698
 
328 tk 699
    layer_config_t *lc = (layer_config_t *)&layer_config[selected_layer_config];
321 tk 700
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
327 tk 701
      SEQ_LCD_PrintChar(' ');
702
      SEQ_LCD_PrintChar('(');
703
      SEQ_LCD_PrintSpaces(14); // for easier handling
704
      SEQ_LCD_CursorSet(12, 1);
705
 
328 tk 706
      if( lc->par_layers > 1 )
707
    SEQ_LCD_PrintFormattedString("%d*", lc->par_layers);
708
      SEQ_LCD_PrintFormattedString("%d/", lc->par_steps);
709
      if( lc->trg_layers > 1 )
710
    SEQ_LCD_PrintFormattedString("%d*", lc->trg_layers);
711
      SEQ_LCD_PrintFormattedString("%d", lc->trg_steps);
327 tk 712
 
328 tk 713
      SEQ_LCD_PrintFormattedString(") %d", lc->instruments);
327 tk 714
      SEQ_LCD_CursorSet(26, 1);
715
 
321 tk 716
    } else {
328 tk 717
      SEQ_LCD_PrintFormattedString("  %3d %3d  %3d  ", lc->par_steps, lc->par_layers, lc->trg_layers);
321 tk 718
    }
319 tk 719
  }
174 tk 720
 
721
  ///////////////////////////////////////////////////////////////////////////
319 tk 722
  mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
723
  if( ui_selected_item == ITEM_MIDI_PORT && ui_cursor_flash ) {
724
    SEQ_LCD_PrintSpaces(5);
725
  } else {
726
    SEQ_LCD_PrintMIDIOutPort(port);
727
    SEQ_LCD_PrintChar(SEQ_MIDI_PORT_OutCheckAvailable(port) ? ' ' : '*');
174 tk 728
  }
729
 
730
  ///////////////////////////////////////////////////////////////////////////
731
  if( ui_selected_item == ITEM_MIDI_CHANNEL && ui_cursor_flash ) {
732
    SEQ_LCD_PrintSpaces(5);
733
  } else {
278 tk 734
    SEQ_LCD_PrintFormattedString("%3d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
174 tk 735
  }
736
 
737
  ///////////////////////////////////////////////////////////////////////////
472 tk 738
  if( ui_selected_item == ITEM_EDIT_NAME && ui_cursor_flash ) {
739
    SEQ_LCD_PrintSpaces(4);
740
  } else {
741
    SEQ_LCD_PrintFormattedString("Name");
742
  }
743
 
744
 
745
  ///////////////////////////////////////////////////////////////////////////
481 tk 746
  if( edit_label_mode ) {
747
    SEQ_LCD_PrintString("Char  Cur  Ins  Clr    Preset Cat./Label");
472 tk 748
 
749
  ///////////////////////////////////////////////////////////////////////////
750
  } else if( selected_layer_config != GetLayerConfig(visible_track) ) {
751
    SEQ_LCD_PrintString(" ---------------------------------> ");
752
    if( ui_cursor_flash ) {
319 tk 753
      SEQ_LCD_PrintSpaces(4);
754
    } else {
472 tk 755
      SEQ_LCD_PrintString("INIT");
319 tk 756
    }
174 tk 757
 
472 tk 758
  ///////////////////////////////////////////////////////////////////////////
759
  } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
319 tk 760
    /////////////////////////////////////////////////////////////////////////
761
    if( ui_selected_item == ITEM_LAYER_A_SELECT && ui_cursor_flash ) {
762
      SEQ_LCD_PrintSpaces(5);
763
    } else {
333 tk 764
      SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, 0));
319 tk 765
    }
174 tk 766
 
319 tk 767
    /////////////////////////////////////////////////////////////////////////
768
    if( ui_selected_item == ITEM_LAYER_B_SELECT && ui_cursor_flash ) {
472 tk 769
      SEQ_LCD_PrintSpaces(5);
319 tk 770
    } else {
472 tk 771
      if( layer_config[selected_layer_config].par_layers >= 2 ) {
772
    SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, 1));
773
      } else {
774
    if( ui_selected_item == ITEM_LAYER_B_SELECT )
775
      SEQ_LCD_PrintString("---- "); // not a bug, but a feature - highlight, that layer not configurable
776
    else
777
      SEQ_LCD_PrintSpaces(5);
778
      }
319 tk 779
    }
472 tk 780
    SEQ_LCD_PrintSpaces(1);
319 tk 781
 
782
    /////////////////////////////////////////////////////////////////////////
783
    if( ui_selected_item == ITEM_DRUM_SELECT && ui_cursor_flash ) {
784
      SEQ_LCD_PrintSpaces(5);
785
    } else {
336 tk 786
      SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
319 tk 787
    }
788
 
789
    /////////////////////////////////////////////////////////////////////////
790
    SEQ_LCD_PrintSpaces(1);
791
    if( ui_selected_item == ITEM_DRUM_NOTE && ui_cursor_flash ) {
792
      SEQ_LCD_PrintSpaces(3);
793
    } else {
336 tk 794
      SEQ_LCD_PrintNote(SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_instrument));
319 tk 795
    }
796
    SEQ_LCD_PrintSpaces(1);
797
 
798
    /////////////////////////////////////////////////////////////////////////
799
    if( ui_selected_item == ITEM_DRUM_VEL_N && ui_cursor_flash ) {
800
      SEQ_LCD_PrintSpaces(5);
801
    } else {
336 tk 802
      SEQ_LCD_PrintFormattedString(" %3d ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_instrument));
319 tk 803
    }
804
 
805
    /////////////////////////////////////////////////////////////////////////
806
    if( ui_selected_item == ITEM_DRUM_VEL_A && ui_cursor_flash ) {
807
      SEQ_LCD_PrintSpaces(5);
808
    } else {
336 tk 809
      SEQ_LCD_PrintFormattedString(" %3d ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_C1 + ui_selected_instrument));
319 tk 810
    }
178 tk 811
  } else {
319 tk 812
    /////////////////////////////////////////////////////////////////////////
813
    SEQ_LCD_PrintSpaces(2);
814
    if( ui_selected_item == ITEM_LAYER_SELECT && ui_cursor_flash ) {
815
      SEQ_LCD_PrintChar(' ');
300 tk 816
    } else {
336 tk 817
      SEQ_LCD_PrintChar('A' + ui_selected_par_layer);
300 tk 818
    }
319 tk 819
    SEQ_LCD_PrintSpaces(4);
820
 
821
    /////////////////////////////////////////////////////////////////////////
822
    if( ui_selected_item == ITEM_LAYER_CONTROL && ui_cursor_flash ) {
323 tk 823
      SEQ_LCD_PrintSpaces(5);
319 tk 824
    } else {
336 tk 825
      SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, ui_selected_par_layer));
319 tk 826
    }
323 tk 827
 
828
    /////////////////////////////////////////////////////////////////////////
829
    if( ui_selected_item == ITEM_LAYER_PAR && ui_cursor_flash ) {
830
      SEQ_LCD_PrintSpaces(19);
831
    } else {
336 tk 832
      switch( SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer) ) {
333 tk 833
        case SEQ_PAR_Type_CC:
336 tk 834
      SEQ_LCD_PrintFormattedString("%03d ModWheel       ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer));
333 tk 835
      break;
836
        default:
837
      SEQ_LCD_PrintSpaces(19);
838
      }
323 tk 839
    }
178 tk 840
  }
174 tk 841
 
472 tk 842
  SEQ_LCD_PrintString("     INIT");
178 tk 843
 
323 tk 844
 
174 tk 845
  return 0; // no error
846
}
847
 
848
 
849
/////////////////////////////////////////////////////////////////////////////
850
// Initialisation
851
/////////////////////////////////////////////////////////////////////////////
852
s32 SEQ_UI_TRKEVNT_Init(u32 mode)
853
{
854
  // install callback routines
855
  SEQ_UI_InstallButtonCallback(Button_Handler);
856
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
857
  SEQ_UI_InstallLEDCallback(LED_Handler);
858
  SEQ_UI_InstallLCDCallback(LCD_Handler);
859
 
178 tk 860
 
481 tk 861
  edit_label_mode = 0;
472 tk 862
  selected_layer_config_track = SEQ_UI_VisibleTrackGet();
863
  selected_layer_config = GetLayerConfig(selected_layer_config_track);
864
 
865
  // initialize edit label vars (name is modified directly, not via ui_edit_name!)
866
  ui_edit_name_cursor = 0;
867
  ui_edit_preset_num_category = 0;
868
  ui_edit_preset_num_label = 0;
869
 
174 tk 870
  return 0; // no error
871
}
176 tk 872
 
873
 
874
/////////////////////////////////////////////////////////////////////////////
323 tk 875
// Copies preset
176 tk 876
/////////////////////////////////////////////////////////////////////////////
323 tk 877
static s32 CopyPreset(u8 track, u8 config)
176 tk 878
{
323 tk 879
  // exit if invalid config
880
  if( config >= (sizeof(layer_config)/sizeof(layer_config_t)) )
881
    return -1; // invalid config
176 tk 882
 
328 tk 883
  layer_config_t *lc = (layer_config_t *)&layer_config[selected_layer_config];
884
 
323 tk 885
  // partitionate layers and clear all steps
328 tk 886
  SEQ_PAR_TrackInit(track, lc->par_steps, lc->par_layers, lc->instruments);
887
  SEQ_TRG_TrackInit(track, lc->trg_steps, lc->trg_layers, lc->instruments);
176 tk 888
 
472 tk 889
#if 0
890
  // confusing if assignments are not changed under such a condition
336 tk 891
  u8 init_assignments = lc->event_mode != SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
472 tk 892
#else
893
  u8 init_assignments = 1;
894
#endif
336 tk 895
 
328 tk 896
  SEQ_CC_Set(track, SEQ_CC_MIDI_EVENT_MODE, lc->event_mode);
176 tk 897
 
326 tk 898
  // BEGIN TMP
328 tk 899
  if( lc->event_mode == SEQ_EVENT_MODE_Drum ) {
326 tk 900
    memcpy((char *)seq_core_trk[track].name, " BD   SD   LT   MT   HT   CP   MA   RS   CB   CY   OH   CH  Smp1 Smp2 Smp3 Smp4 ", 80);
901
  } else {
902
    memset((char *)seq_core_trk[track].name, ' ', 80);
903
  }
904
  // END TMP
905
 
324 tk 906
  u8 only_layers = 0;
907
  u8 all_triggers_cleared = 0;
335 tk 908
  return SEQ_LAYER_CopyPreset(track, only_layers, all_triggers_cleared, init_assignments);
323 tk 909
}
176 tk 910
 
911
 
323 tk 912
/////////////////////////////////////////////////////////////////////////////
913
// Determines current layer config
914
/////////////////////////////////////////////////////////////////////////////
915
static s32 GetLayerConfig(u8 track)
916
{
917
  int i;
918
 
919
  u8 event_mode = SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
920
  u8 par_layers = SEQ_PAR_NumLayersGet(track);
921
  u16 par_steps = SEQ_PAR_NumStepsGet(track);
922
  u8 trg_layers = SEQ_TRG_NumLayersGet(track);
923
  u16 trg_steps = SEQ_TRG_NumStepsGet(track);
328 tk 924
  u8 num_instruments = SEQ_PAR_NumInstrumentsGet(track);
323 tk 925
 
926
  for(i=0; i<(sizeof(layer_config)/sizeof(layer_config_t)); ++i) {
927
    layer_config_t *lc = (layer_config_t *)&layer_config[i];
928
    if( lc->event_mode == event_mode &&
929
    lc->par_layers == par_layers && lc->par_steps == par_steps &&
325 tk 930
    lc->trg_layers == trg_layers && lc->trg_steps == trg_steps &&
328 tk 931
    lc->instruments == num_instruments ) {
323 tk 932
      return i;
176 tk 933
    }
934
  }
935
 
323 tk 936
  return 0; // not found, return index to first config
176 tk 937
}
178 tk 938