Subversion Repositories svn.mios32

Rev

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