Subversion Repositories svn.mios32

Rev

Rev 718 | Rev 740 | 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 729 2009-09-30 13:32:55Z 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:
729 tk 318
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
319
    return SEQ_UI_Var8_Inc((u8 *)&seq_core_trk[visible_track].name[ui_selected_instrument*5 + (ui_edit_name_cursor % 5)], 32, 127, incrementer);
320
      } else {
321
    return SEQ_UI_Var8_Inc((u8 *)&seq_core_trk[visible_track].name[ui_edit_name_cursor], 32, 127, incrementer);
322
      }
472 tk 323
 
324
    case ITEM_EDIT_CURSOR:
729 tk 325
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
326
    return SEQ_UI_Var8_Inc(&ui_edit_name_cursor, 0, 5-1, incrementer);
327
      } else {
328
    return SEQ_UI_Var8_Inc(&ui_edit_name_cursor, 0, 20-1, incrementer);
329
      }
472 tk 330
 
331
    case ITEM_EDIT_INS: {
332
      int i;
729 tk 333
      int field_start, field_end;
334
 
335
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
336
    field_start = 5*ui_selected_instrument + (ui_edit_name_cursor % 5);
337
    field_end = 5*ui_selected_instrument + 4;
338
      } else {
339
    field_start = ui_edit_name_cursor;
340
    field_end = (ui_edit_name_cursor < 5) ? 4 : 19;
341
      }
342
 
343
      for(i=field_end; i>field_start; --i) {
472 tk 344
    seq_core_trk[visible_track].name[i] = seq_core_trk[visible_track].name[i-1];
345
      }
729 tk 346
      seq_core_trk[visible_track].name[field_start] = ' ';
472 tk 347
      return 1;
348
    } break;
349
 
350
    case ITEM_EDIT_CLR: {
351
      int i;
729 tk 352
      int field_start, field_end;
353
 
354
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
355
    field_start = 5*ui_selected_instrument + (ui_edit_name_cursor % 5);
356
    field_end = 5*ui_selected_instrument + 4;
357
      } else {
358
    field_start = ui_edit_name_cursor;
359
    field_end = (ui_edit_name_cursor < 5) ? 4 : 19;
360
      }
361
 
362
      for(i=field_start; i<field_end; ++i) {
472 tk 363
    seq_core_trk[visible_track].name[i] = seq_core_trk[visible_track].name[i+1];
364
      }
365
      seq_core_trk[visible_track].name[field_end] = ' ';
366
      return 1;
367
    } break;
368
 
369
    case ITEM_EDIT_PRESET_CATEG:
370
      if( ui_edit_name_cursor >= 5 ) // set cursor to category field if required (more intuitive usage)
371
    ui_edit_name_cursor = 0;
372
 
729 tk 373
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
374
    if( SEQ_UI_Var8_Inc(&ui_edit_preset_num_drum, 0, SEQ_LABEL_NumPresetsDrum()-1, incrementer) ) {
375
      SEQ_LABEL_CopyPresetDrum(ui_edit_preset_num_drum, (char *)&seq_core_trk[visible_track].name[5*ui_selected_instrument]);
376
      return 1;
377
    }
378
      } else {
379
    if( SEQ_UI_Var8_Inc(&ui_edit_preset_num_category, 0, SEQ_LABEL_NumPresetsCategory()-1, incrementer) ) {
380
      SEQ_LABEL_CopyPresetCategory(ui_edit_preset_num_category, (char *)&seq_core_trk[visible_track].name[0]);
381
      return 1;
382
    }
472 tk 383
      }
384
      return 0;
385
 
386
    case ITEM_EDIT_PRESET_LABEL:
729 tk 387
      if( event_mode == SEQ_EVENT_MODE_Drum )
388
    return 0; // no function in drum mode
389
 
472 tk 390
      if( ui_edit_name_cursor < 5 ) // set cursor to category field if required (more intuitive usage)
391
    ui_edit_name_cursor = 5;
392
 
393
      if( SEQ_UI_Var8_Inc(&ui_edit_preset_num_label, 0, SEQ_LABEL_NumPresets()-1, incrementer) ) {
394
    SEQ_LABEL_CopyPreset(ui_edit_preset_num_label, (char *)&seq_core_trk[visible_track].name[5]);
395
    return 1;
396
      }
397
      return 0;
398
 
399
    }
400
  } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
401
    switch( ui_selected_item ) {
325 tk 402
      case ITEM_DRUM_SELECT: {
328 tk 403
        u8 num_drums = layer_config[selected_layer_config].instruments;
336 tk 404
        return SEQ_UI_Var8_Inc(&ui_selected_instrument, 0, num_drums-1, incrementer);
325 tk 405
      } break;
335 tk 406
      case ITEM_LAYER_A_SELECT: {
407
        if( SEQ_UI_CC_Inc(SEQ_CC_PAR_ASG_DRUM_LAYER_A, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
336 tk 408
      SEQ_LAYER_CopyParLayerPreset(visible_track, 0);
335 tk 409
      return 1;
410
    }
411
    return 0;
412
      } break;
413
      case ITEM_LAYER_B_SELECT: {
414
        if( SEQ_UI_CC_Inc(SEQ_CC_PAR_ASG_DRUM_LAYER_B, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
336 tk 415
      SEQ_LAYER_CopyParLayerPreset(visible_track, 1);
335 tk 416
      return 1;
417
    }
418
    return 0;
419
      } break;
336 tk 420
      case ITEM_DRUM_NOTE:     return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_A1 + ui_selected_instrument, 0, 127, incrementer);
421
      case ITEM_DRUM_VEL_N:    return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_B1 + ui_selected_instrument, 0, 127, incrementer);
422
      case ITEM_DRUM_VEL_A:    return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_C1 + ui_selected_instrument, 0, 127, incrementer);
319 tk 423
    }
424
  } else {
425
    switch( ui_selected_item ) {
336 tk 426
      case ITEM_LAYER_SELECT:  return SEQ_UI_Var8_Inc(&ui_selected_par_layer, 0, 15, incrementer);
427
      case ITEM_LAYER_PAR:     return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer, 0, 127, incrementer);
333 tk 428
      case ITEM_LAYER_CONTROL: {
429
    // TODO: has to be done for all selected tracks
336 tk 430
    if( SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_A1 + ui_selected_par_layer, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
431
      SEQ_LAYER_CopyParLayerPreset(visible_track, ui_selected_par_layer);
333 tk 432
      return 1;
433
    }
434
    return 0;
435
      } break;
319 tk 436
    }
437
  }
438
 
174 tk 439
  return -1; // invalid or unsupported encoder
440
}
441
 
442
 
443
/////////////////////////////////////////////////////////////////////////////
444
// Local button callback function
445
// Should return:
446
//   1 if value has been changed
447
//   0 if value hasn't been changed
448
//  -1 if invalid or unsupported button
449
/////////////////////////////////////////////////////////////////////////////
450
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
451
{
452
  if( depressed ) return 0; // ignore when button depressed
453
 
472 tk 454
  u8 visible_track = SEQ_UI_VisibleTrackGet();
323 tk 455
  u8 event_mode = layer_config[selected_layer_config].event_mode;
456
 
472 tk 457
  if( button >= SEQ_UI_BUTTON_GP9 && button <= SEQ_UI_BUTTON_GP16 ) {
481 tk 458
    if( edit_label_mode ) {
472 tk 459
      switch( button ) {
460
        case SEQ_UI_BUTTON_GP9:
461
      ui_selected_item = ITEM_EDIT_CHAR;
462
      break;
463
 
464
        case SEQ_UI_BUTTON_GP10:
465
      ui_selected_item = ITEM_EDIT_CURSOR;
466
      break;
467
 
468
        case SEQ_UI_BUTTON_GP11:
469
      return Encoder_Handler(SEQ_UI_ENCODER_GP11, 1);
470
 
471
        case SEQ_UI_BUTTON_GP12:
472
      return Encoder_Handler(SEQ_UI_ENCODER_GP12, 1);
473
 
474
        case SEQ_UI_BUTTON_GP13:
481 tk 475
        case SEQ_UI_BUTTON_GP14:
476
      return -1; // not mapped
472 tk 477
 
481 tk 478
        case SEQ_UI_BUTTON_GP15:
472 tk 479
      ui_selected_item = ITEM_EDIT_PRESET_CATEG;
480
      break;
481
 
481 tk 482
        case SEQ_UI_BUTTON_GP16:
472 tk 483
      ui_selected_item = ITEM_EDIT_PRESET_LABEL;
484
      break;
485
      }
486
    } else {
487
      if( selected_layer_config != GetLayerConfig(visible_track) ) {
488
    // uninitialized track: only GP16 available
489
    if( button != SEQ_UI_BUTTON_GP16 )
490
      return -1;
491
      }
492
 
493
      switch( button ) {
494
        case SEQ_UI_BUTTON_GP9:
495
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_LAYER_A_SELECT : ITEM_LAYER_SELECT;
496
      return 1;
497
 
498
        case SEQ_UI_BUTTON_GP10:
499
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_LAYER_B_SELECT : ITEM_LAYER_CONTROL;
500
      return 1;
501
 
502
        case SEQ_UI_BUTTON_GP11:
503
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_SELECT : ITEM_LAYER_CONTROL;
504
      return 1;
505
 
506
        case SEQ_UI_BUTTON_GP12:
507
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_NOTE : ITEM_LAYER_CONTROL;
508
      return 1;
509
 
510
        case SEQ_UI_BUTTON_GP13:
511
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_VEL_N : ITEM_LAYER_CONTROL;
512
      return 1;
513
 
514
        case SEQ_UI_BUTTON_GP14:
515
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_VEL_A : ITEM_LAYER_CONTROL;
516
      return 1;
517
 
518
        case SEQ_UI_BUTTON_GP15:
519
      return -1; // not mapped
520
 
521
        case SEQ_UI_BUTTON_GP16:
522
      // ui_selected_item = ITEM_PRESET;
523
      // TODO: copy preset for all selected tracks!
524
      CopyPreset(visible_track, selected_layer_config);
525
      return 1; // value has been changed
526
      }
527
    }
528
  }
529
 
174 tk 530
  switch( button ) {
323 tk 531
    case SEQ_UI_BUTTON_GP1:
174 tk 532
      ui_selected_item = ITEM_GXTY;
319 tk 533
      return 1;
174 tk 534
 
323 tk 535
    case SEQ_UI_BUTTON_GP2:
536
    case SEQ_UI_BUTTON_GP3:
537
    case SEQ_UI_BUTTON_GP4:
538
    case SEQ_UI_BUTTON_GP5:
319 tk 539
      ui_selected_item = ITEM_EVENT_MODE;
540
      return 1;
174 tk 541
 
323 tk 542
    case SEQ_UI_BUTTON_GP6:
319 tk 543
      ui_selected_item = ITEM_MIDI_PORT;
544
      return 1;
174 tk 545
 
323 tk 546
    case SEQ_UI_BUTTON_GP7:
319 tk 547
      ui_selected_item = ITEM_MIDI_CHANNEL;
548
      return 1;
174 tk 549
 
323 tk 550
    case SEQ_UI_BUTTON_GP8:
472 tk 551
      // toggle "edit name" mode
481 tk 552
      return Encoder_Handler((seq_ui_encoder_t)button, edit_label_mode ? -1 : 1);
174 tk 553
 
554
    case SEQ_UI_BUTTON_Select:
555
    case SEQ_UI_BUTTON_Right:
481 tk 556
      if( edit_label_mode ) {
472 tk 557
    if( ++ui_selected_item >= NUM_OF_ITEMS_EDIT_MODE )
558
      ui_selected_item = 0;
559
      } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
319 tk 560
    if( ++ui_selected_item >= NUM_OF_ITEMS_DRUM )
561
      ui_selected_item = 0;
562
      } else {
563
    if( ++ui_selected_item >= NUM_OF_ITEMS_NORMAL )
564
      ui_selected_item = 0;
565
      }
566
 
174 tk 567
      return 1; // value always changed
568
 
569
    case SEQ_UI_BUTTON_Left:
481 tk 570
      if( edit_label_mode ) {
319 tk 571
    if( ui_selected_item == 0 )
472 tk 572
      ui_selected_item = NUM_OF_ITEMS_EDIT_MODE-1;
573
      } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
574
    if( ui_selected_item == 0 )
319 tk 575
      ui_selected_item = NUM_OF_ITEMS_DRUM-1;
576
      } else {
577
    if( ui_selected_item == 0 )
578
      ui_selected_item = NUM_OF_ITEMS_NORMAL-1;
579
      }
174 tk 580
      return 1; // value always changed
581
 
582
    case SEQ_UI_BUTTON_Up:
583
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
584
 
585
    case SEQ_UI_BUTTON_Down:
586
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
587
  }
588
 
589
  return -1; // invalid or unsupported button
590
}
591
 
592
 
593
/////////////////////////////////////////////////////////////////////////////
594
// Local Display Handler function
595
// IN: <high_prio>: if set, a high-priority LCD update is requested
596
/////////////////////////////////////////////////////////////////////////////
597
static s32 LCD_Handler(u8 high_prio)
598
{
599
  if( high_prio )
600
    return 0; // there are no high-priority updates
601
 
602
  // layout:
603
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
604
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
605
  // <--------------------------------------><-------------------------------------->
472 tk 606
  // Trk. Type Steps/ParL/TrgL Port Chn. EditLayer  controls                         
607
  // G1T1 Note  256   4     8  IIC2  12  Name  D    Prob                         INIT
174 tk 608
 
472 tk 609
  // Trk. Type Steps/ParL/TrgL Port Chn. EditLayer  controls                         
718 tk 610
  // G1T1 Note  256   4     8  IIC2  12  Name  D    CC #001 (ModWheel)           INIT
319 tk 611
 
612
  // Track Type "Note", Chord" and "CC":
613
  // Note: Parameter Layer A/B/C statically assigned to Note Number/Velocity/Length
614
  //       Parameter Layer D..P can be mapped to
615
  //       - additional Notes (e.g. for poly recording)
616
  //       - Base note (directly forwarded to Transposer, e.g. for Force-to-Scale or Chords)
617
  //       - CC (Number 000..127 assignable, GM controller name will be displayed)
618
  //       - Pitch Bender
619
  //       - Loopback (Number 000..127 assignable, name will be displayed)
338 tk 620
  //       - Delay (0..95 ticks @384 ppqn)
319 tk 621
  //       - Probability (100%..0%)
327 tk 622
  //       - "Roll/Flam Effect" (a selection of up to 128 different effects selectable for each step separately)
319 tk 623
  // Chord: same like Note, but predefined Chords will be played
624
  // CC: Layer A/B/C play CCs (or other parameters) as well - no note number, no velocity, no length
625
 
626
  // Available Layer Constraints (Partitioning for 1024 bytes Par. memory, 2048 bits Trg. memory)
627
  //    - 256 Steps with  4 Parameter Layers A-D and 8 Trigger Layers A-H
628
  //    - 128 Steps with  8 Parameter Layers A-H and 8 Trigger Layers A-H
629
  //    -  64 Steps with 16 Parameter Layers A-P and 8 Trigger Layers A-H
630
 
631
 
632
  // layout:
633
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
634
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
635
  // <--------------------------------------><-------------------------------------->
472 tk 636
  // Trk. Type StepsP/T  Drums Port Chn. EditLayA LayB  Drum Note VelN VelA          
637
  // G1T1 Drum  (64/2*64) 16   USB1  10  NamePrb. ----   BD   C-1  100  127      INIT
319 tk 638
 
472 tk 639
  // Trk. Type StepsP/T  Drums Port Chn. EditLayA LayB  Drum Note VelN VelA          
640
  // G1T1 Drum  (2*64/256) 8   USB1  12  NameVel. Len.   SD   D-1  ---  ---      INIT
319 tk 641
 
642
 
643
  // Track Type "Drums":
327 tk 644
  //    1 or 2 parameter layers for each trigger layer (drum instrument).
645
  //    If parameters layers consist of more than 1024 steps in total, steps > 1024 will be mirrored
646
  //    assignable to Velocity/Gatelength/Delay/Probability/Roll/Flam only
319 tk 647
  //    (no CC, no Pitch Bender, no Loopback, as they don't work note-wise, but 
648
  //     only channel wise
649
  //     just send them from a different track)
650
 
651
  // Each drum instrument provides 4 constant parameters for:
652
  //   - Note Number
472 tk 653
  //   - MIDI Channel (1-16) for all drum instruments (TODO: optionally allow to use a "local" channel, edit parameter right of VelA)
319 tk 654
  //   - Velocity Normal (if not taken from Parameter Layer)
655
  //   - Velocity Accented (if not taken from Parameter Layer)
656
 
657
 
658
  // Available Layer Constraints (Partitioning for 1024 bytes Par. memory, 2048 bits Trg. memory)
327 tk 659
  //    - 16 Parameter Layers with 64 steps and 2*16 Trigger Layers A-P with 64 steps taken for Gate and Accent
660
  //    - 2*16 Parameter Layer with 32 steps and 16 Trigger Layers A-P with 128 steps taken for Gate
661
  //    - 8 Parameter Layer with 128 steps and 2*8 Trigger Layers A-P with 128 steps taken for Gate and Accent
662
  //    - 2*8 Parameter Layer with 64 steps and 8 Trigger Layers A-P with 256 steps taken for Gate
319 tk 663
 
472 tk 664
 
665
 
666
  // "Edit Name" layout:
667
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
668
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
669
  // <--------------------------------------><-------------------------------------->
670
  // Trk. Type Steps/ParL/TrgL Port Chn. EditCategory: xxxxx   Label: xxxxxxxxxxxxxxx
481 tk 671
  // G1T1 Note  256   4     8  IIC2  12  NameChar  Cur  Ins  Clr    Preset Cat./Label
472 tk 672
 
729 tk 673
  // "Edit Drum Name" layout:
674
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
675
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
676
  // <--------------------------------------><-------------------------------------->
677
  // Trk. Type Steps/ParL/TrgL Port Chn. EditDrum Label: xxxxx                        
678
  // G1T1 Note  256   4     8  IIC2  12  NameChar  Cur  Ins  Clr    Preset Label     
679
 
174 tk 680
  u8 visible_track = SEQ_UI_VisibleTrackGet();
472 tk 681
 
682
  // if track has changed, switch layer config:
683
  if( visible_track != selected_layer_config_track ) {
684
    selected_layer_config_track = visible_track;
685
    selected_layer_config = GetLayerConfig(selected_layer_config_track);
686
  }
687
 
323 tk 688
  u8 event_mode = layer_config[selected_layer_config].event_mode;
174 tk 689
 
472 tk 690
 
174 tk 691
  ///////////////////////////////////////////////////////////////////////////
278 tk 692
  SEQ_LCD_CursorSet(0, 0);
319 tk 693
 
472 tk 694
  SEQ_LCD_PrintString("Trk. Type ");
695
  SEQ_LCD_PrintString((event_mode == SEQ_EVENT_MODE_Drum) ? "StepsP/T  Drums " : "Steps/ParL/TrgL ");
696
  SEQ_LCD_PrintString("Port Chn. ");
697
 
698
  if( ui_selected_item == ITEM_EDIT_NAME && ui_cursor_flash ) {
699
    SEQ_LCD_PrintSpaces(4);
700
  } else {
701
    SEQ_LCD_PrintFormattedString("Edit");
702
  }
703
 
481 tk 704
  if( edit_label_mode ) {
729 tk 705
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
706
      SEQ_LCD_PrintString("Drum Label: ");
707
      SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, seq_core_trk[visible_track].name);
708
      SEQ_LCD_PrintSpaces(23);
472 tk 709
 
729 tk 710
      // insert flashing cursor
711
      if( ui_cursor_flash ) {
712
    if( ui_edit_name_cursor >= 5 ) // correct cursor position if it is outside the 5 char label space
713
      ui_edit_name_cursor = 0;
714
    SEQ_LCD_CursorSet(52 + ui_edit_name_cursor, 0);
715
    SEQ_LCD_PrintChar('*');
716
      }
717
    } else {
718
      SEQ_LCD_PrintString("Category: ");
719
      SEQ_LCD_PrintTrackCategory(visible_track, seq_core_trk[visible_track].name);
720
      SEQ_LCD_PrintString("   Label: ");
721
      SEQ_LCD_PrintTrackLabel(visible_track, seq_core_trk[visible_track].name);
722
 
723
      // insert flashing cursor
724
      if( ui_cursor_flash ) {
725
    SEQ_LCD_CursorSet(40 + ((ui_edit_name_cursor < 5) ? 10 : 20) + ui_edit_name_cursor, 0);
726
    SEQ_LCD_PrintChar('*');
727
      }
472 tk 728
    }
729 tk 729
 
472 tk 730
  } else if( selected_layer_config != GetLayerConfig(visible_track) ) {
731
    SEQ_LCD_PrintString("    Please initialize the track         ");
732
  } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
319 tk 733
    SEQ_LCD_PrintString("LayA ");
472 tk 734
    SEQ_LCD_PrintString((layer_config[selected_layer_config].par_layers >= 2) ? "LayB " : "     ");
735
    SEQ_LCD_PrintString(" Drum Note VelN VelA          ");
174 tk 736
  } else {
472 tk 737
    SEQ_LCD_PrintString("Layer  controls                         ");
174 tk 738
  }
739
 
740
  ///////////////////////////////////////////////////////////////////////////
278 tk 741
  SEQ_LCD_CursorSet(0, 1);
174 tk 742
 
743
  if( ui_selected_item == ITEM_GXTY && ui_cursor_flash ) {
744
    SEQ_LCD_PrintSpaces(5);
745
  } else {
746
    SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
747
    SEQ_LCD_PrintSpaces(1);
748
  }
749
 
750
  ///////////////////////////////////////////////////////////////////////////
751
 
319 tk 752
  if( ui_selected_item == ITEM_EVENT_MODE && ui_cursor_flash ) {
753
    SEQ_LCD_PrintSpaces(21);
754
  } else {
755
    const char event_mode_str[4][6] = { "Note ", "Chord", " CC  ", "Drum " };
690 tk 756
    SEQ_LCD_PrintString((char *)event_mode_str[event_mode]);
174 tk 757
 
328 tk 758
    layer_config_t *lc = (layer_config_t *)&layer_config[selected_layer_config];
321 tk 759
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
327 tk 760
      SEQ_LCD_PrintChar(' ');
761
      SEQ_LCD_PrintChar('(');
762
      SEQ_LCD_PrintSpaces(14); // for easier handling
763
      SEQ_LCD_CursorSet(12, 1);
764
 
328 tk 765
      if( lc->par_layers > 1 )
766
    SEQ_LCD_PrintFormattedString("%d*", lc->par_layers);
767
      SEQ_LCD_PrintFormattedString("%d/", lc->par_steps);
768
      if( lc->trg_layers > 1 )
769
    SEQ_LCD_PrintFormattedString("%d*", lc->trg_layers);
770
      SEQ_LCD_PrintFormattedString("%d", lc->trg_steps);
327 tk 771
 
328 tk 772
      SEQ_LCD_PrintFormattedString(") %d", lc->instruments);
327 tk 773
      SEQ_LCD_CursorSet(26, 1);
774
 
321 tk 775
    } else {
328 tk 776
      SEQ_LCD_PrintFormattedString("  %3d %3d  %3d  ", lc->par_steps, lc->par_layers, lc->trg_layers);
321 tk 777
    }
319 tk 778
  }
174 tk 779
 
780
  ///////////////////////////////////////////////////////////////////////////
319 tk 781
  mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
782
  if( ui_selected_item == ITEM_MIDI_PORT && ui_cursor_flash ) {
783
    SEQ_LCD_PrintSpaces(5);
784
  } else {
785
    SEQ_LCD_PrintMIDIOutPort(port);
786
    SEQ_LCD_PrintChar(SEQ_MIDI_PORT_OutCheckAvailable(port) ? ' ' : '*');
174 tk 787
  }
788
 
789
  ///////////////////////////////////////////////////////////////////////////
790
  if( ui_selected_item == ITEM_MIDI_CHANNEL && ui_cursor_flash ) {
791
    SEQ_LCD_PrintSpaces(5);
792
  } else {
278 tk 793
    SEQ_LCD_PrintFormattedString("%3d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
174 tk 794
  }
795
 
796
  ///////////////////////////////////////////////////////////////////////////
472 tk 797
  if( ui_selected_item == ITEM_EDIT_NAME && ui_cursor_flash ) {
798
    SEQ_LCD_PrintSpaces(4);
799
  } else {
800
    SEQ_LCD_PrintFormattedString("Name");
801
  }
802
 
803
 
804
  ///////////////////////////////////////////////////////////////////////////
481 tk 805
  if( edit_label_mode ) {
729 tk 806
    if( event_mode == SEQ_EVENT_MODE_Drum )
807
      SEQ_LCD_PrintString("Char  Cur  Ins  Clr    Preset Label     ");
808
    else
809
      SEQ_LCD_PrintString("Char  Cur  Ins  Clr    Preset Cat./Label");
472 tk 810
 
811
  ///////////////////////////////////////////////////////////////////////////
812
  } else if( selected_layer_config != GetLayerConfig(visible_track) ) {
813
    SEQ_LCD_PrintString(" ---------------------------------> ");
814
    if( ui_cursor_flash ) {
319 tk 815
      SEQ_LCD_PrintSpaces(4);
816
    } else {
472 tk 817
      SEQ_LCD_PrintString("INIT");
319 tk 818
    }
174 tk 819
 
472 tk 820
  ///////////////////////////////////////////////////////////////////////////
821
  } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
319 tk 822
    /////////////////////////////////////////////////////////////////////////
823
    if( ui_selected_item == ITEM_LAYER_A_SELECT && ui_cursor_flash ) {
824
      SEQ_LCD_PrintSpaces(5);
825
    } else {
333 tk 826
      SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, 0));
319 tk 827
    }
174 tk 828
 
319 tk 829
    /////////////////////////////////////////////////////////////////////////
830
    if( ui_selected_item == ITEM_LAYER_B_SELECT && ui_cursor_flash ) {
472 tk 831
      SEQ_LCD_PrintSpaces(5);
319 tk 832
    } else {
472 tk 833
      if( layer_config[selected_layer_config].par_layers >= 2 ) {
834
    SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, 1));
835
      } else {
836
    if( ui_selected_item == ITEM_LAYER_B_SELECT )
837
      SEQ_LCD_PrintString("---- "); // not a bug, but a feature - highlight, that layer not configurable
838
    else
839
      SEQ_LCD_PrintSpaces(5);
840
      }
319 tk 841
    }
472 tk 842
    SEQ_LCD_PrintSpaces(1);
319 tk 843
 
844
    /////////////////////////////////////////////////////////////////////////
845
    if( ui_selected_item == ITEM_DRUM_SELECT && ui_cursor_flash ) {
846
      SEQ_LCD_PrintSpaces(5);
847
    } else {
336 tk 848
      SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
319 tk 849
    }
850
 
851
    /////////////////////////////////////////////////////////////////////////
852
    SEQ_LCD_PrintSpaces(1);
853
    if( ui_selected_item == ITEM_DRUM_NOTE && ui_cursor_flash ) {
854
      SEQ_LCD_PrintSpaces(3);
855
    } else {
336 tk 856
      SEQ_LCD_PrintNote(SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_instrument));
319 tk 857
    }
858
    SEQ_LCD_PrintSpaces(1);
859
 
860
    /////////////////////////////////////////////////////////////////////////
861
    if( ui_selected_item == ITEM_DRUM_VEL_N && ui_cursor_flash ) {
862
      SEQ_LCD_PrintSpaces(5);
863
    } else {
336 tk 864
      SEQ_LCD_PrintFormattedString(" %3d ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_instrument));
319 tk 865
    }
866
 
867
    /////////////////////////////////////////////////////////////////////////
868
    if( ui_selected_item == ITEM_DRUM_VEL_A && ui_cursor_flash ) {
869
      SEQ_LCD_PrintSpaces(5);
870
    } else {
336 tk 871
      SEQ_LCD_PrintFormattedString(" %3d ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_C1 + ui_selected_instrument));
319 tk 872
    }
178 tk 873
  } else {
319 tk 874
    /////////////////////////////////////////////////////////////////////////
875
    SEQ_LCD_PrintSpaces(2);
876
    if( ui_selected_item == ITEM_LAYER_SELECT && ui_cursor_flash ) {
877
      SEQ_LCD_PrintChar(' ');
300 tk 878
    } else {
336 tk 879
      SEQ_LCD_PrintChar('A' + ui_selected_par_layer);
300 tk 880
    }
319 tk 881
    SEQ_LCD_PrintSpaces(4);
882
 
883
    /////////////////////////////////////////////////////////////////////////
884
    if( ui_selected_item == ITEM_LAYER_CONTROL && ui_cursor_flash ) {
323 tk 885
      SEQ_LCD_PrintSpaces(5);
319 tk 886
    } else {
336 tk 887
      SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, ui_selected_par_layer));
319 tk 888
    }
323 tk 889
 
890
    /////////////////////////////////////////////////////////////////////////
891
    if( ui_selected_item == ITEM_LAYER_PAR && ui_cursor_flash ) {
892
      SEQ_LCD_PrintSpaces(19);
893
    } else {
336 tk 894
      switch( SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer) ) {
718 tk 895
        case SEQ_PAR_Type_CC: {
896
      u8 cc = SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer);
897
      SEQ_LCD_PrintFormattedString("%03d (%s)     ", cc, SEQ_CC_LABELS_Get(cc));
898
    } break;
333 tk 899
        default:
900
      SEQ_LCD_PrintSpaces(19);
901
      }
323 tk 902
    }
178 tk 903
  }
174 tk 904
 
472 tk 905
  SEQ_LCD_PrintString("     INIT");
178 tk 906
 
323 tk 907
 
174 tk 908
  return 0; // no error
909
}
910
 
911
 
912
/////////////////////////////////////////////////////////////////////////////
913
// Initialisation
914
/////////////////////////////////////////////////////////////////////////////
915
s32 SEQ_UI_TRKEVNT_Init(u32 mode)
916
{
917
  // install callback routines
918
  SEQ_UI_InstallButtonCallback(Button_Handler);
919
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
920
  SEQ_UI_InstallLEDCallback(LED_Handler);
921
  SEQ_UI_InstallLCDCallback(LCD_Handler);
922
 
178 tk 923
 
481 tk 924
  edit_label_mode = 0;
472 tk 925
  selected_layer_config_track = SEQ_UI_VisibleTrackGet();
926
  selected_layer_config = GetLayerConfig(selected_layer_config_track);
927
 
928
  // initialize edit label vars (name is modified directly, not via ui_edit_name!)
929
  ui_edit_name_cursor = 0;
930
  ui_edit_preset_num_category = 0;
931
  ui_edit_preset_num_label = 0;
932
 
174 tk 933
  return 0; // no error
934
}
176 tk 935
 
936
 
937
/////////////////////////////////////////////////////////////////////////////
323 tk 938
// Copies preset
176 tk 939
/////////////////////////////////////////////////////////////////////////////
323 tk 940
static s32 CopyPreset(u8 track, u8 config)
176 tk 941
{
323 tk 942
  // exit if invalid config
943
  if( config >= (sizeof(layer_config)/sizeof(layer_config_t)) )
944
    return -1; // invalid config
176 tk 945
 
328 tk 946
  layer_config_t *lc = (layer_config_t *)&layer_config[selected_layer_config];
947
 
323 tk 948
  // partitionate layers and clear all steps
328 tk 949
  SEQ_PAR_TrackInit(track, lc->par_steps, lc->par_layers, lc->instruments);
950
  SEQ_TRG_TrackInit(track, lc->trg_steps, lc->trg_layers, lc->instruments);
176 tk 951
 
472 tk 952
#if 0
953
  // confusing if assignments are not changed under such a condition
336 tk 954
  u8 init_assignments = lc->event_mode != SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
472 tk 955
#else
956
  u8 init_assignments = 1;
957
#endif
336 tk 958
 
328 tk 959
  SEQ_CC_Set(track, SEQ_CC_MIDI_EVENT_MODE, lc->event_mode);
176 tk 960
 
326 tk 961
  // BEGIN TMP
328 tk 962
  if( lc->event_mode == SEQ_EVENT_MODE_Drum ) {
729 tk 963
    int i;
964
 
965
    for(i=0; i<16; ++i)
966
      SEQ_LABEL_CopyPresetDrum(i, (char *)&seq_core_trk[track].name[5*i]);
326 tk 967
  } else {
968
    memset((char *)seq_core_trk[track].name, ' ', 80);
969
  }
970
  // END TMP
971
 
324 tk 972
  u8 only_layers = 0;
973
  u8 all_triggers_cleared = 0;
335 tk 974
  return SEQ_LAYER_CopyPreset(track, only_layers, all_triggers_cleared, init_assignments);
323 tk 975
}
176 tk 976
 
977
 
323 tk 978
/////////////////////////////////////////////////////////////////////////////
979
// Determines current layer config
980
/////////////////////////////////////////////////////////////////////////////
981
static s32 GetLayerConfig(u8 track)
982
{
983
  int i;
984
 
985
  u8 event_mode = SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
986
  u8 par_layers = SEQ_PAR_NumLayersGet(track);
987
  u16 par_steps = SEQ_PAR_NumStepsGet(track);
988
  u8 trg_layers = SEQ_TRG_NumLayersGet(track);
989
  u16 trg_steps = SEQ_TRG_NumStepsGet(track);
328 tk 990
  u8 num_instruments = SEQ_PAR_NumInstrumentsGet(track);
323 tk 991
 
992
  for(i=0; i<(sizeof(layer_config)/sizeof(layer_config_t)); ++i) {
993
    layer_config_t *lc = (layer_config_t *)&layer_config[i];
994
    if( lc->event_mode == event_mode &&
995
    lc->par_layers == par_layers && lc->par_steps == par_steps &&
325 tk 996
    lc->trg_layers == trg_layers && lc->trg_steps == trg_steps &&
328 tk 997
    lc->instruments == num_instruments ) {
323 tk 998
      return i;
176 tk 999
    }
1000
  }
1001
 
323 tk 1002
  return 0; // not found, return index to first config
176 tk 1003
}
178 tk 1004