Subversion Repositories svn.mios32

Rev

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