Subversion Repositories svn.mios32

Rev

Rev 326 | Rev 328 | 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 327 2009-01-30 00:18:01Z 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"
23
#include "seq_layer.h"
24
 
25
 
26
/////////////////////////////////////////////////////////////////////////////
27
// Local definitions
28
/////////////////////////////////////////////////////////////////////////////
29
 
319 tk 30
// Note/Chord/CC
31
#define NUM_OF_ITEMS_NORMAL 6
32
#define ITEM_GXTY           0
33
#define ITEM_EVENT_MODE     1
34
#define ITEM_MIDI_PORT      2
35
#define ITEM_MIDI_CHANNEL   3
36
#define ITEM_LAYER_SELECT   4
37
#define ITEM_LAYER_CONTROL  5
323 tk 38
#define ITEM_LAYER_PAR      6
174 tk 39
 
319 tk 40
// Drum
41
#define NUM_OF_ITEMS_DRUM   11
42
#define ITEM_GXTY           0
43
#define ITEM_EVENT_MODE     1
44
#define ITEM_MIDI_PORT      2
45
#define ITEM_MIDI_CHANNEL   3
46
#define ITEM_MIDI_CHANNEL_LOCAL 4
47
#define ITEM_LAYER_A_SELECT 5
48
#define ITEM_LAYER_B_SELECT 6
49
#define ITEM_DRUM_SELECT    7
50
#define ITEM_DRUM_NOTE      8
51
#define ITEM_DRUM_VEL_N     9
52
#define ITEM_DRUM_VEL_A     10
174 tk 53
 
319 tk 54
 
55
 
174 tk 56
/////////////////////////////////////////////////////////////////////////////
323 tk 57
// Local types
58
/////////////////////////////////////////////////////////////////////////////
59
 
60
typedef struct {
61
  seq_event_mode_t event_mode;  // event mode as forwarded to SEQ_CC_MIDI_EVENT_MODE
62
  u8               par_layers;  // number of parameter layers
63
  u16              par_steps;   // number of steps per parameter layer
64
  u8               trg_layers;  // number of trigger layers
65
  u16              trg_steps;   // number of steps per trigger layer
324 tk 66
  u8               drum_with_accent; // drum track with accent triggers
323 tk 67
} layer_config_t;
68
 
69
 
70
/////////////////////////////////////////////////////////////////////////////
176 tk 71
// Local prototypes
72
/////////////////////////////////////////////////////////////////////////////
73
 
323 tk 74
static s32 GetLayerConfig(u8 track);
75
static s32 CopyPreset(u8 track, u8 config);
176 tk 76
 
77
 
78
/////////////////////////////////////////////////////////////////////////////
178 tk 79
// Local variables
80
/////////////////////////////////////////////////////////////////////////////
81
 
323 tk 82
static u8 selected_layer_config;
319 tk 83
 
323 tk 84
static layer_config_t layer_config[] = {
324 tk 85
  //      mode           par_layers  par_steps  trg_layers  trg_steps  drum w/ accent
325 tk 86
  { SEQ_EVENT_MODE_Note,    16,          64,        8,          64,      0 },
87
  { SEQ_EVENT_MODE_Note,     8,         128,        8,         128,      0 },
324 tk 88
  { SEQ_EVENT_MODE_Note,     4,         256,        8,         256,      0 },
325 tk 89
  { SEQ_EVENT_MODE_Chord,   16,          64,        8,          64,      0 },
90
  { SEQ_EVENT_MODE_Chord,    8,         128,        8,         128,      0 },
324 tk 91
  { SEQ_EVENT_MODE_Chord,    4,         256,        8,         256,      0 },
325 tk 92
  { SEQ_EVENT_MODE_CC,      16,          64,        8,          64,      0 },
93
  { SEQ_EVENT_MODE_CC,       8,         128,        8,         128,      0 },
324 tk 94
  { SEQ_EVENT_MODE_CC,       4,         256,        8,         256,      0 },
327 tk 95
  { SEQ_EVENT_MODE_Drum,    16,          64,     2*16,          64,      1 },
96
  { SEQ_EVENT_MODE_Drum,  2*16,          32,       16,         128,      0 },
97
  { SEQ_EVENT_MODE_Drum,     8,         128,      2*8,         128,      1 },
98
  { SEQ_EVENT_MODE_Drum,   2*8,          64,        8,         256,      0 }
323 tk 99
};
100
 
319 tk 101
static u8 selected_layer;
102
static u8 selected_drum;
103
 
178 tk 104
 
105
/////////////////////////////////////////////////////////////////////////////
174 tk 106
// Local LED handler function
107
/////////////////////////////////////////////////////////////////////////////
108
static s32 LED_Handler(u16 *gp_leds)
109
{
178 tk 110
  if( ui_cursor_flash ) { // if flashing flag active: no LED flag set
323 tk 111
    // flash INIT LED if current preset doesn't match with old preset
112
    // this notifies the user, that he should press the "INIT" button
178 tk 113
    u8 visible_track = SEQ_UI_VisibleTrackGet();
323 tk 114
    if( selected_layer_config != GetLayerConfig(visible_track) )
319 tk 115
      *gp_leds = 0x8000;
178 tk 116
 
174 tk 117
    return 0;
178 tk 118
  }
174 tk 119
 
323 tk 120
  if( layer_config[selected_layer_config].event_mode == SEQ_EVENT_MODE_Drum ) {
319 tk 121
    switch( ui_selected_item ) {
122
      case ITEM_GXTY: *gp_leds = 0x0001; break;
123
      case ITEM_EVENT_MODE: *gp_leds = 0x001e; break;
124
      case ITEM_MIDI_PORT: *gp_leds = 0x0020; break;
125
      case ITEM_MIDI_CHANNEL: *gp_leds = 0x0040; break;
126
      case ITEM_MIDI_CHANNEL_LOCAL: *gp_leds = 0x0080; break;
127
      case ITEM_LAYER_A_SELECT: *gp_leds = 0x0100; break;
128
      case ITEM_LAYER_B_SELECT: *gp_leds = 0x0200; break;
129
      case ITEM_DRUM_SELECT: *gp_leds = 0x0400; break;
130
      case ITEM_DRUM_NOTE: *gp_leds = 0x0800; break;
131
      case ITEM_DRUM_VEL_N: *gp_leds = 0x1000; break;
132
      case ITEM_DRUM_VEL_A: *gp_leds = 0x2000; break;
133
    }
134
  } else {
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;
140
      case ITEM_LAYER_SELECT: *gp_leds = 0x0100; break;
323 tk 141
      case ITEM_LAYER_CONTROL: *gp_leds = 0x0200; break;
142
      case ITEM_LAYER_PAR: *gp_leds = 0x3c00; break;
319 tk 143
    }
174 tk 144
  }
145
 
146
  return 0; // no error
147
}
148
 
149
 
150
/////////////////////////////////////////////////////////////////////////////
151
// Local encoder callback function
152
// Should return:
153
//   1 if value has been changed
154
//   0 if value hasn't been changed
155
//  -1 if invalid or unsupported encoder
156
/////////////////////////////////////////////////////////////////////////////
157
static s32 Encoder_Handler(seq_ui_encoder_t encoder, s32 incrementer)
158
{
323 tk 159
  u8 event_mode = layer_config[selected_layer_config].event_mode;
178 tk 160
 
174 tk 161
  switch( encoder ) {
162
    case SEQ_UI_ENCODER_GP1:
163
      ui_selected_item = ITEM_GXTY;
164
      break;
165
 
166
    case SEQ_UI_ENCODER_GP2:
167
    case SEQ_UI_ENCODER_GP3:
168
    case SEQ_UI_ENCODER_GP4:
169
    case SEQ_UI_ENCODER_GP5:
319 tk 170
      ui_selected_item = ITEM_EVENT_MODE;
174 tk 171
      break;
172
 
173
    case SEQ_UI_ENCODER_GP6:
319 tk 174
      ui_selected_item = ITEM_MIDI_PORT;
174 tk 175
      break;
176
 
177
    case SEQ_UI_ENCODER_GP7:
319 tk 178
      ui_selected_item = ITEM_MIDI_CHANNEL;
174 tk 179
      break;
180
 
181
    case SEQ_UI_ENCODER_GP8:
319 tk 182
      if( event_mode == SEQ_EVENT_MODE_Drum )
183
    ui_selected_item = ITEM_MIDI_CHANNEL_LOCAL;
184
      else
185
    return -1;
174 tk 186
      break;
187
 
188
    case SEQ_UI_ENCODER_GP9:
319 tk 189
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_LAYER_A_SELECT : ITEM_LAYER_SELECT;
174 tk 190
      break;
191
 
192
    case SEQ_UI_ENCODER_GP10:
319 tk 193
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_LAYER_B_SELECT : ITEM_LAYER_CONTROL;
174 tk 194
      break;
195
 
196
    case SEQ_UI_ENCODER_GP11:
323 tk 197
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_SELECT : ITEM_LAYER_PAR;
319 tk 198
      break;
199
 
174 tk 200
    case SEQ_UI_ENCODER_GP12:
323 tk 201
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_NOTE : ITEM_LAYER_PAR;
319 tk 202
      break;
203
 
174 tk 204
    case SEQ_UI_ENCODER_GP13:
323 tk 205
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_VEL_N : ITEM_LAYER_PAR;
319 tk 206
      break;
207
 
174 tk 208
    case SEQ_UI_ENCODER_GP14:
323 tk 209
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_VEL_A : ITEM_LAYER_PAR;
319 tk 210
      break;
174 tk 211
 
212
    case SEQ_UI_ENCODER_GP15:
319 tk 213
      return -1; // not mapped to encoder
214
 
174 tk 215
    case SEQ_UI_ENCODER_GP16:
319 tk 216
      return -1; // not mapped to encoder
174 tk 217
  }
218
 
219
  // for GP encoders and Datawheel
220
  switch( ui_selected_item ) {
221
    case ITEM_GXTY:          return SEQ_UI_GxTyInc(incrementer);
323 tk 222
    case ITEM_EVENT_MODE: {
223
      u8 max_layer_config = (sizeof(layer_config)/sizeof(layer_config_t)) - 1;
224
      return SEQ_UI_Var8_Inc(&selected_layer_config, 0, max_layer_config, incrementer);
225
    } break;
285 tk 226
    case ITEM_MIDI_PORT: {
227
      u8 visible_track = SEQ_UI_VisibleTrackGet();
228
      mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
229
      u8 port_ix = SEQ_MIDI_PORT_OutIxGet(port);
230
      if( SEQ_UI_Var8_Inc(&port_ix, 0, SEQ_MIDI_PORT_OutNumGet()-1, incrementer) ) {
231
    mios32_midi_port_t new_port = SEQ_MIDI_PORT_OutPortGet(port_ix);
232
    SEQ_UI_CC_Set(SEQ_CC_MIDI_PORT, new_port);
233
    return 1; // value changed
234
      }
235
      return 0; // value not changed
236
    } break;
319 tk 237
    case ITEM_MIDI_CHANNEL:  return SEQ_UI_CC_Inc(SEQ_CC_MIDI_CHANNEL, 0, 15, incrementer);
174 tk 238
  }
239
 
319 tk 240
  if( event_mode == SEQ_EVENT_MODE_Drum ) {
241
    switch( ui_selected_item ) {
325 tk 242
      case ITEM_DRUM_SELECT: {
243
        u8 num_drums = layer_config[selected_layer_config].trg_layers / (layer_config[selected_layer_config].drum_with_accent ? 2 : 1);
244
        return SEQ_UI_Var8_Inc(&selected_drum, 0, num_drums-1, incrementer);
245
      } break;
323 tk 246
      case ITEM_DRUM_NOTE:     return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_A1 + selected_drum, 0, 127, incrementer);
247
      case ITEM_DRUM_VEL_N:    return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_B1 + selected_drum, 0, 127, incrementer);
248
      case ITEM_DRUM_VEL_A:    return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_C1 + selected_drum, 0, 127, incrementer);
319 tk 249
    }
250
  } else {
251
    switch( ui_selected_item ) {
252
      case ITEM_LAYER_SELECT:  return SEQ_UI_Var8_Inc(&selected_layer, 0, 15, incrementer);
323 tk 253
      case ITEM_LAYER_CONTROL: return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_A1 + selected_layer, 0, 127, incrementer);
254
      case ITEM_LAYER_PAR:     return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_B1 + selected_layer, 0, 127, incrementer);
319 tk 255
    }
256
  }
257
 
174 tk 258
  return -1; // invalid or unsupported encoder
259
}
260
 
261
 
262
/////////////////////////////////////////////////////////////////////////////
263
// Local button callback function
264
// Should return:
265
//   1 if value has been changed
266
//   0 if value hasn't been changed
267
//  -1 if invalid or unsupported button
268
/////////////////////////////////////////////////////////////////////////////
269
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
270
{
271
  if( depressed ) return 0; // ignore when button depressed
272
 
323 tk 273
  u8 event_mode = layer_config[selected_layer_config].event_mode;
274
 
174 tk 275
  switch( button ) {
323 tk 276
    case SEQ_UI_BUTTON_GP1:
174 tk 277
      ui_selected_item = ITEM_GXTY;
319 tk 278
      return 1;
174 tk 279
 
323 tk 280
    case SEQ_UI_BUTTON_GP2:
281
    case SEQ_UI_BUTTON_GP3:
282
    case SEQ_UI_BUTTON_GP4:
283
    case SEQ_UI_BUTTON_GP5:
319 tk 284
      ui_selected_item = ITEM_EVENT_MODE;
285
      return 1;
174 tk 286
 
323 tk 287
    case SEQ_UI_BUTTON_GP6:
319 tk 288
      ui_selected_item = ITEM_MIDI_PORT;
289
      return 1;
174 tk 290
 
323 tk 291
    case SEQ_UI_BUTTON_GP7:
319 tk 292
      ui_selected_item = ITEM_MIDI_CHANNEL;
293
      return 1;
174 tk 294
 
323 tk 295
    case SEQ_UI_BUTTON_GP8:
319 tk 296
      if( event_mode == SEQ_EVENT_MODE_Drum )
297
    ui_selected_item = ITEM_MIDI_CHANNEL_LOCAL;
298
      else
299
    return -1;
300
      return 1;
174 tk 301
 
323 tk 302
    case SEQ_UI_BUTTON_GP9:
319 tk 303
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_LAYER_A_SELECT : ITEM_LAYER_SELECT;
304
      return 1;
174 tk 305
 
323 tk 306
    case SEQ_UI_BUTTON_GP10:
319 tk 307
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_LAYER_B_SELECT : ITEM_LAYER_CONTROL;
308
      return 1;
174 tk 309
 
323 tk 310
    case SEQ_UI_BUTTON_GP11:
319 tk 311
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_SELECT : ITEM_LAYER_CONTROL;
312
      return 1;
174 tk 313
 
323 tk 314
    case SEQ_UI_BUTTON_GP12:
319 tk 315
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_NOTE : ITEM_LAYER_CONTROL;
316
      return 1;
317
 
323 tk 318
    case SEQ_UI_BUTTON_GP13:
319 tk 319
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_VEL_N : ITEM_LAYER_CONTROL;
320
      return 1;
321
 
323 tk 322
    case SEQ_UI_BUTTON_GP14:
319 tk 323
      ui_selected_item = (event_mode == SEQ_EVENT_MODE_Drum) ? ITEM_DRUM_VEL_A : ITEM_LAYER_CONTROL;
324
      return 1;
325
 
323 tk 326
    case SEQ_UI_BUTTON_GP15:
319 tk 327
      // TODO
328
      return 1;
329
 
323 tk 330
    case SEQ_UI_BUTTON_GP16:
178 tk 331
      // ui_selected_item = ITEM_PRESET;
323 tk 332
      // TODO: copy preset for all selected tracks!
333
      CopyPreset(SEQ_UI_VisibleTrackGet(), selected_layer_config);
178 tk 334
      return 1; // value has been changed
174 tk 335
 
319 tk 336
 
174 tk 337
    case SEQ_UI_BUTTON_Select:
338
    case SEQ_UI_BUTTON_Right:
319 tk 339
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
340
    if( ++ui_selected_item >= NUM_OF_ITEMS_DRUM )
341
      ui_selected_item = 0;
342
      } else {
343
    if( ++ui_selected_item >= NUM_OF_ITEMS_NORMAL )
344
      ui_selected_item = 0;
345
      }
346
 
174 tk 347
      return 1; // value always changed
348
 
349
    case SEQ_UI_BUTTON_Left:
319 tk 350
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
351
    if( ui_selected_item == 0 )
352
      ui_selected_item = NUM_OF_ITEMS_DRUM-1;
353
      } else {
354
    if( ui_selected_item == 0 )
355
      ui_selected_item = NUM_OF_ITEMS_NORMAL-1;
356
      }
174 tk 357
      return 1; // value always changed
358
 
359
    case SEQ_UI_BUTTON_Up:
360
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
361
 
362
    case SEQ_UI_BUTTON_Down:
363
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
364
  }
365
 
366
  return -1; // invalid or unsupported button
367
}
368
 
369
 
370
/////////////////////////////////////////////////////////////////////////////
371
// Local Display Handler function
372
// IN: <high_prio>: if set, a high-priority LCD update is requested
373
/////////////////////////////////////////////////////////////////////////////
374
static s32 LCD_Handler(u8 high_prio)
375
{
376
  if( high_prio )
377
    return 0; // there are no high-priority updates
378
 
379
  // layout:
380
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
381
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
382
  // <--------------------------------------><-------------------------------------->
319 tk 383
  // Trk. Type Steps/ParL/TrgL Port Chn.     Layer  controls                Edit      
323 tk 384
  // G1T1 Note  256   4     8  IIC2  12        D    Prob                    Name INIT
174 tk 385
 
319 tk 386
  // Trk. Type Steps/ParL/TrgL Port Chn.     Layer  controls                Edit      
323 tk 387
  // G1T1 Note  256   4     8  IIC2  12        D    CC #001 ModWheel        Name INIT
319 tk 388
 
389
  // Track Type "Note", Chord" and "CC":
390
  // Note: Parameter Layer A/B/C statically assigned to Note Number/Velocity/Length
391
  //       Parameter Layer D..P can be mapped to
392
  //       - additional Notes (e.g. for poly recording)
393
  //       - Base note (directly forwarded to Transposer, e.g. for Force-to-Scale or Chords)
394
  //       - CC (Number 000..127 assignable, GM controller name will be displayed)
395
  //       - Pitch Bender
396
  //       - Loopback (Number 000..127 assignable, name will be displayed)
397
  //       - Delay (+/- 96 ticks @384 ppqn)
398
  //       - Probability (100%..0%)
327 tk 399
  //       - "Roll/Flam Effect" (a selection of up to 128 different effects selectable for each step separately)
319 tk 400
  // Chord: same like Note, but predefined Chords will be played
401
  // CC: Layer A/B/C play CCs (or other parameters) as well - no note number, no velocity, no length
402
 
403
  // Available Layer Constraints (Partitioning for 1024 bytes Par. memory, 2048 bits Trg. memory)
404
  //    - 256 Steps with  4 Parameter Layers A-D and 8 Trigger Layers A-H
405
  //    - 128 Steps with  8 Parameter Layers A-H and 8 Trigger Layers A-H
406
  //    -  64 Steps with 16 Parameter Layers A-P and 8 Trigger Layers A-H
407
 
408
 
409
  // layout:
410
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
411
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
412
  // <--------------------------------------><-------------------------------------->
327 tk 413
  // Trk. Type StepsP/T  Drums Port Chn. Glb LayA LayB  Drum Note VelN VelA Edit     
414
  // G1T1 Drum  (64/2*64) 16   USB1  10  yes Prb. ----   BD   C-1  100  127 Name INIT
319 tk 415
 
327 tk 416
  // Trk. Type StepsP/T  Drums Port Chn. Glb LayA LayB  Drum Note VelN VelA Edit     
417
  // G1T1 Drum  (2*64/256) 8   USB1  12   no Vel. Len.   SD   D-1  ---  --- Name INIT
319 tk 418
 
419
 
420
  // Track Type "Drums":
327 tk 421
  //    1 or 2 parameter layers for each trigger layer (drum instrument).
422
  //    If parameters layers consist of more than 1024 steps in total, steps > 1024 will be mirrored
423
  //    assignable to Velocity/Gatelength/Delay/Probability/Roll/Flam only
319 tk 424
  //    (no CC, no Pitch Bender, no Loopback, as they don't work note-wise, but 
425
  //     only channel wise
426
  //     just send them from a different track)
427
 
428
  // Each drum instrument provides 4 constant parameters for:
429
  //   - Note Number
430
  //   - MIDI Channel (1-16) - optionally, we can select a "local" channel definition for the instrument
431
  //   - Velocity Normal (if not taken from Parameter Layer)
432
  //   - Velocity Accented (if not taken from Parameter Layer)
433
 
434
 
435
  // Available Layer Constraints (Partitioning for 1024 bytes Par. memory, 2048 bits Trg. memory)
327 tk 436
  //    - 16 Parameter Layers with 64 steps and 2*16 Trigger Layers A-P with 64 steps taken for Gate and Accent
437
  //    - 2*16 Parameter Layer with 32 steps and 16 Trigger Layers A-P with 128 steps taken for Gate
438
  //    - 8 Parameter Layer with 128 steps and 2*8 Trigger Layers A-P with 128 steps taken for Gate and Accent
439
  //    - 2*8 Parameter Layer with 64 steps and 8 Trigger Layers A-P with 256 steps taken for Gate
319 tk 440
 
174 tk 441
  u8 visible_track = SEQ_UI_VisibleTrackGet();
323 tk 442
  u8 event_mode = layer_config[selected_layer_config].event_mode;
174 tk 443
 
444
  ///////////////////////////////////////////////////////////////////////////
278 tk 445
  SEQ_LCD_CursorSet(0, 0);
319 tk 446
 
447
  if( event_mode == SEQ_EVENT_MODE_Drum ) {
327 tk 448
    SEQ_LCD_PrintString("Trk. Type StepsP/T  Drums Port Chn. Glb Layer  controls                Edit     ");
319 tk 449
    SEQ_LCD_PrintString("LayA ");
450
    SEQ_LCD_PrintString("LayB ");
451
    SEQ_LCD_PrintString(" Drum Note VelN VelA Edit     ");
174 tk 452
  } else {
321 tk 453
    SEQ_LCD_PrintString("Trk. Type Steps/ParL/TrgL Port Chn.     Layer  controls                Edit     ");
174 tk 454
  }
455
 
456
  ///////////////////////////////////////////////////////////////////////////
278 tk 457
  SEQ_LCD_CursorSet(0, 1);
174 tk 458
 
459
  if( ui_selected_item == ITEM_GXTY && ui_cursor_flash ) {
460
    SEQ_LCD_PrintSpaces(5);
461
  } else {
462
    SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
463
    SEQ_LCD_PrintSpaces(1);
464
  }
465
 
466
  ///////////////////////////////////////////////////////////////////////////
467
 
319 tk 468
  if( ui_selected_item == ITEM_EVENT_MODE && ui_cursor_flash ) {
469
    SEQ_LCD_PrintSpaces(21);
470
  } else {
471
    const char event_mode_str[4][6] = { "Note ", "Chord", " CC  ", "Drum " };
472
    SEQ_LCD_PrintString(event_mode_str[event_mode]);
174 tk 473
 
321 tk 474
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
327 tk 475
      SEQ_LCD_PrintChar(' ');
476
      SEQ_LCD_PrintChar('(');
477
      SEQ_LCD_PrintSpaces(14); // for easier handling
478
      SEQ_LCD_CursorSet(12, 1);
479
 
480
      if( !layer_config[selected_layer_config].drum_with_accent )
481
    SEQ_LCD_PrintString("2*");
482
      SEQ_LCD_PrintFormattedString("%d/", layer_config[selected_layer_config].par_steps);
483
      if( layer_config[selected_layer_config].drum_with_accent )
484
    SEQ_LCD_PrintString("2*");
485
      SEQ_LCD_PrintFormattedString("%d", layer_config[selected_layer_config].trg_steps);
486
 
487
      SEQ_LCD_PrintFormattedString(") %d", layer_config[selected_layer_config].trg_layers / (layer_config[selected_layer_config].drum_with_accent ? 2 : 1));
488
      SEQ_LCD_CursorSet(26, 1);
489
 
321 tk 490
    } else {
323 tk 491
      SEQ_LCD_PrintFormattedString("  %3d %3d  %3d  ",
492
                   layer_config[selected_layer_config].par_steps,
493
                   layer_config[selected_layer_config].par_layers,
494
                   layer_config[selected_layer_config].trg_layers);
321 tk 495
    }
319 tk 496
  }
174 tk 497
 
498
  ///////////////////////////////////////////////////////////////////////////
319 tk 499
  mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
500
  if( ui_selected_item == ITEM_MIDI_PORT && ui_cursor_flash ) {
501
    SEQ_LCD_PrintSpaces(5);
502
  } else {
503
    SEQ_LCD_PrintMIDIOutPort(port);
504
    SEQ_LCD_PrintChar(SEQ_MIDI_PORT_OutCheckAvailable(port) ? ' ' : '*');
174 tk 505
  }
506
 
507
  ///////////////////////////////////////////////////////////////////////////
508
  if( ui_selected_item == ITEM_MIDI_CHANNEL && ui_cursor_flash ) {
509
    SEQ_LCD_PrintSpaces(5);
510
  } else {
278 tk 511
    SEQ_LCD_PrintFormattedString("%3d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
174 tk 512
  }
513
 
514
  ///////////////////////////////////////////////////////////////////////////
319 tk 515
  if( event_mode == SEQ_EVENT_MODE_Drum ) {
516
    /////////////////////////////////////////////////////////////////////////
517
    if( ui_selected_item == ITEM_MIDI_CHANNEL_LOCAL && ui_cursor_flash ) {
518
      SEQ_LCD_PrintSpaces(4);
519
    } else {
520
      SEQ_LCD_PrintFormattedString(" no ");
521
    }
174 tk 522
 
319 tk 523
    /////////////////////////////////////////////////////////////////////////
524
    if( ui_selected_item == ITEM_LAYER_A_SELECT && ui_cursor_flash ) {
525
      SEQ_LCD_PrintSpaces(5);
526
    } else {
527
      SEQ_LCD_PrintFormattedString("Dly. ");
528
    }
174 tk 529
 
319 tk 530
    /////////////////////////////////////////////////////////////////////////
531
    if( ui_selected_item == ITEM_LAYER_B_SELECT && ui_cursor_flash ) {
532
      SEQ_LCD_PrintSpaces(6);
533
    } else {
534
      SEQ_LCD_PrintFormattedString("Par.  ");
535
    }
536
 
537
    /////////////////////////////////////////////////////////////////////////
538
    if( ui_selected_item == ITEM_DRUM_SELECT && ui_cursor_flash ) {
539
      SEQ_LCD_PrintSpaces(5);
540
    } else {
541
      SEQ_LCD_PrintTrackDrum(visible_track, selected_drum, (char *)seq_core_trk[visible_track].name);
542
    }
543
 
544
    /////////////////////////////////////////////////////////////////////////
545
    SEQ_LCD_PrintSpaces(1);
546
    if( ui_selected_item == ITEM_DRUM_NOTE && ui_cursor_flash ) {
547
      SEQ_LCD_PrintSpaces(3);
548
    } else {
323 tk 549
      SEQ_LCD_PrintNote(SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + selected_drum));
319 tk 550
    }
551
    SEQ_LCD_PrintSpaces(1);
552
 
553
    /////////////////////////////////////////////////////////////////////////
554
    if( ui_selected_item == ITEM_DRUM_VEL_N && ui_cursor_flash ) {
555
      SEQ_LCD_PrintSpaces(5);
556
    } else {
323 tk 557
      SEQ_LCD_PrintFormattedString(" %3d ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + selected_drum));
319 tk 558
    }
559
 
560
    /////////////////////////////////////////////////////////////////////////
561
    if( ui_selected_item == ITEM_DRUM_VEL_A && ui_cursor_flash ) {
562
      SEQ_LCD_PrintSpaces(5);
563
    } else {
323 tk 564
      SEQ_LCD_PrintFormattedString(" %3d ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_C1 + selected_drum));
319 tk 565
    }
178 tk 566
  } else {
319 tk 567
    /////////////////////////////////////////////////////////////////////////
568
    SEQ_LCD_PrintSpaces(4);
300 tk 569
 
319 tk 570
    /////////////////////////////////////////////////////////////////////////
571
    SEQ_LCD_PrintSpaces(2);
572
    if( ui_selected_item == ITEM_LAYER_SELECT && ui_cursor_flash ) {
573
      SEQ_LCD_PrintChar(' ');
300 tk 574
    } else {
319 tk 575
      SEQ_LCD_PrintChar('A' + selected_layer);
300 tk 576
    }
319 tk 577
    SEQ_LCD_PrintSpaces(4);
578
 
579
    /////////////////////////////////////////////////////////////////////////
580
    if( ui_selected_item == ITEM_LAYER_CONTROL && ui_cursor_flash ) {
323 tk 581
      SEQ_LCD_PrintSpaces(5);
319 tk 582
    } else {
323 tk 583
      SEQ_LCD_PrintFormattedString("CC  #"); // TODO
319 tk 584
    }
323 tk 585
 
586
    /////////////////////////////////////////////////////////////////////////
587
    if( ui_selected_item == ITEM_LAYER_PAR && ui_cursor_flash ) {
588
      SEQ_LCD_PrintSpaces(19);
589
    } else {
590
      SEQ_LCD_PrintFormattedString("%03d ModWheel       ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + selected_layer));
591
    }
178 tk 592
  }
174 tk 593
 
323 tk 594
  /////////////////////////////////////////////////////////////////////////
595
  SEQ_LCD_PrintString("Name ");
178 tk 596
 
323 tk 597
  /////////////////////////////////////////////////////////////////////////
598
  if( selected_layer_config != GetLayerConfig(visible_track) && ui_cursor_flash ) {
599
    SEQ_LCD_PrintSpaces(4);
600
  } else {
601
    SEQ_LCD_PrintString("INIT");
602
  }
603
 
174 tk 604
  return 0; // no error
605
}
606
 
607
 
608
/////////////////////////////////////////////////////////////////////////////
609
// Initialisation
610
/////////////////////////////////////////////////////////////////////////////
611
s32 SEQ_UI_TRKEVNT_Init(u32 mode)
612
{
613
  // install callback routines
614
  SEQ_UI_InstallButtonCallback(Button_Handler);
615
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
616
  SEQ_UI_InstallLEDCallback(LED_Handler);
617
  SEQ_UI_InstallLCDCallback(LCD_Handler);
618
 
323 tk 619
  selected_layer_config = GetLayerConfig(SEQ_UI_VisibleTrackGet());
178 tk 620
 
174 tk 621
  return 0; // no error
622
}
176 tk 623
 
624
 
625
/////////////////////////////////////////////////////////////////////////////
323 tk 626
// Copies preset
176 tk 627
/////////////////////////////////////////////////////////////////////////////
323 tk 628
static s32 CopyPreset(u8 track, u8 config)
176 tk 629
{
323 tk 630
  // exit if invalid config
631
  if( config >= (sizeof(layer_config)/sizeof(layer_config_t)) )
632
    return -1; // invalid config
176 tk 633
 
323 tk 634
  // partitionate layers and clear all steps
635
  SEQ_PAR_TrackInit(track, layer_config[config].par_steps, layer_config[config].par_layers);
636
  SEQ_TRG_TrackInit(track, layer_config[config].trg_steps, layer_config[config].trg_layers);
176 tk 637
 
323 tk 638
  SEQ_CC_Set(track, SEQ_CC_MIDI_EVENT_MODE, layer_config[config].event_mode);
176 tk 639
 
326 tk 640
  // BEGIN TMP
641
  if( layer_config[config].event_mode == SEQ_EVENT_MODE_Drum ) {
642
    memcpy((char *)seq_core_trk[track].name, " BD   SD   LT   MT   HT   CP   MA   RS   CB   CY   OH   CH  Smp1 Smp2 Smp3 Smp4 ", 80);
643
  } else {
644
    memset((char *)seq_core_trk[track].name, ' ', 80);
645
  }
646
  // END TMP
647
 
324 tk 648
  u8 only_layers = 0;
649
  u8 all_triggers_cleared = 0;
650
  u8 drum_with_accent = layer_config[config].drum_with_accent;
651
  return SEQ_LAYER_CopyPreset(track, only_layers, all_triggers_cleared, drum_with_accent);
323 tk 652
}
176 tk 653
 
654
 
323 tk 655
/////////////////////////////////////////////////////////////////////////////
656
// Determines current layer config
657
/////////////////////////////////////////////////////////////////////////////
658
static s32 GetLayerConfig(u8 track)
659
{
660
  int i;
661
 
662
  u8 event_mode = SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
663
  u8 par_layers = SEQ_PAR_NumLayersGet(track);
664
  u16 par_steps = SEQ_PAR_NumStepsGet(track);
665
  u8 trg_layers = SEQ_TRG_NumLayersGet(track);
666
  u16 trg_steps = SEQ_TRG_NumStepsGet(track);
325 tk 667
  u8 drum_with_accent = (event_mode == SEQ_EVENT_MODE_Drum) && SEQ_TRG_AssignmentGet(track, 1);
323 tk 668
 
669
  for(i=0; i<(sizeof(layer_config)/sizeof(layer_config_t)); ++i) {
670
    layer_config_t *lc = (layer_config_t *)&layer_config[i];
671
    if( lc->event_mode == event_mode &&
672
    lc->par_layers == par_layers && lc->par_steps == par_steps &&
325 tk 673
    lc->trg_layers == trg_layers && lc->trg_steps == trg_steps &&
674
    lc->drum_with_accent == drum_with_accent ) {
323 tk 675
      return i;
176 tk 676
    }
677
  }
678
 
323 tk 679
  return 0; // not found, return index to first config
176 tk 680
}
178 tk 681