Subversion Repositories svn.mios32

Rev

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