Subversion Repositories svn.mios32

Rev

Rev 416 | Rev 593 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
167 tk 1
// $Id: seq_ui_edit.c 484 2009-05-04 20:16:40Z tk $
2
/*
3
 * Edit page
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>
19
#include "seq_lcd.h"
20
#include "seq_ui.h"
21
 
22
#include "seq_core.h"
168 tk 23
#include "seq_cc.h"
176 tk 24
#include "seq_layer.h"
167 tk 25
#include "seq_par.h"
26
#include "seq_trg.h"
27
 
28
 
29
/////////////////////////////////////////////////////////////////////////////
178 tk 30
// Local prototypes
31
/////////////////////////////////////////////////////////////////////////////
32
 
318 tk 33
static s32 ChangeSingleEncValue(u8 track, u16 step, s32 incrementer, s32 forced_value, u8 change_gate);
178 tk 34
 
35
 
36
/////////////////////////////////////////////////////////////////////////////
240 tk 37
// LED handler function (globally accessible, since it's re-used by UTIL page)
167 tk 38
/////////////////////////////////////////////////////////////////////////////
240 tk 39
s32 SEQ_UI_EDIT_LED_Handler(u16 *gp_leds)
167 tk 40
{
41
  u8 visible_track = SEQ_UI_VisibleTrackGet();
42
 
43
  *gp_leds =
328 tk 44
    (SEQ_TRG_Get8(visible_track, 2*ui_selected_step_view+1, ui_selected_trg_layer, ui_selected_instrument) << 8) |
45
    (SEQ_TRG_Get8(visible_track, 2*ui_selected_step_view+0, ui_selected_trg_layer, ui_selected_instrument) << 0);
167 tk 46
 
47
  return 0; // no error
48
}
49
 
50
 
51
/////////////////////////////////////////////////////////////////////////////
168 tk 52
// Local encoder callback function
53
// Should return:
54
//   1 if value has been changed
55
//   0 if value hasn't been changed
56
//  -1 if invalid or unsupported encoder
167 tk 57
/////////////////////////////////////////////////////////////////////////////
168 tk 58
static s32 Encoder_Handler(seq_ui_encoder_t encoder, s32 incrementer)
167 tk 59
{
168 tk 60
#if 0
61
  // leads to: comparison is always true due to limited range of data type
62
  if( (encoder >= SEQ_UI_ENCODER_GP1 && encoder <= SEQ_UI_ENCODER_GP16) || encoder == SEQ_UI_ENCODER_Datawheel ) {
63
#else
64
  if( encoder <= SEQ_UI_ENCODER_GP16 || encoder == SEQ_UI_ENCODER_Datawheel ) {
65
#endif
178 tk 66
    ui_selected_step = ((encoder == SEQ_UI_ENCODER_Datawheel) ? (ui_selected_step%16) : encoder) + ui_selected_step_view*16;
167 tk 67
 
182 tk 68
    u8 visible_track = SEQ_UI_VisibleTrackGet();
69
 
178 tk 70
    s32 value_changed = 0;
71
    s32 forced_value = -1;
72
    u8  change_gate = 1;
168 tk 73
 
182 tk 74
    // due to historical reasons (from old times where MBSEQ CS was stuffed with pots): 
75
    // in arp mode, we increment in steps of 4
76
    if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator &&
333 tk 77
    SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer) == SEQ_PAR_Type_Note )
182 tk 78
      incrementer *= 4;
79
 
80
 
178 tk 81
    // first change the selected value
82
    if( seq_ui_button_state.CHANGE_ALL_STEPS && seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
182 tk 83
      forced_value = ChangeSingleEncValue(visible_track, ui_selected_step, incrementer, forced_value, change_gate);
178 tk 84
      if( forced_value < 0 )
85
    return 0; // no change
86
      value_changed |= 1;
168 tk 87
    }
88
 
178 tk 89
    // change value of all selected steps
90
    u8 track;
303 tk 91
    u16 step;
178 tk 92
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
93
      if( SEQ_UI_IsSelectedTrack(track) ) {
318 tk 94
    u16 num_steps = SEQ_PAR_NumStepsGet(track);
95
    for(step=0; step<num_steps; ++step) {
178 tk 96
      change_gate = step == ui_selected_step;
97
      if( change_gate || seq_ui_button_state.CHANGE_ALL_STEPS ) {
98
        if( ChangeSingleEncValue(track, step, incrementer, forced_value, change_gate) >= 0 )
99
          value_changed |= 1;
100
      }
101
    }
102
      }
176 tk 103
    }
168 tk 104
 
178 tk 105
    return value_changed;
168 tk 106
  }
107
 
108
  return -1; // invalid or unsupported encoder
167 tk 109
}
110
 
111
 
112
/////////////////////////////////////////////////////////////////////////////
168 tk 113
// Local button callback function
114
// Should return:
115
//   1 if value has been changed
116
//   0 if value hasn't been changed
117
//  -1 if invalid or unsupported button
167 tk 118
/////////////////////////////////////////////////////////////////////////////
168 tk 119
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
167 tk 120
{
168 tk 121
  if( depressed ) return 0; // ignore when button depressed
167 tk 122
 
306 tk 123
  u8 visible_track = SEQ_UI_VisibleTrackGet();
124
 
168 tk 125
#if 0
126
  // leads to: comparison is always true due to limited range of data type
127
  if( button >= SEQ_UI_BUTTON_GP1 && button <= SEQ_UI_BUTTON_GP16 ) {
128
#else
129
  if( button <= SEQ_UI_BUTTON_GP16 ) {
130
#endif
180 tk 131
    ui_selected_step = button + ui_selected_step_view*16;
168 tk 132
    // toggle trigger layer
178 tk 133
    // we've three cases:
134
    // a) ALL function active, but ALL button not pressed: invert complete trigger layer
135
    // b) ALL function active and ALL button pressed: toggle step, set remaining steps to same new value
136
    // c) ALL function not active: toggle step
137
    if( seq_ui_button_state.CHANGE_ALL_STEPS ) {
138
      if( seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
139
    // b) ALL function active and ALL button pressed: toggle step, set remaining steps to same new value
303 tk 140
    u16 step = ui_selected_step;
328 tk 141
    u8 new_value = SEQ_TRG_Get(visible_track, step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
178 tk 142
 
143
    u8 track;
144
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
318 tk 145
      if( SEQ_UI_IsSelectedTrack(track) ) {
146
        u16 num_steps = SEQ_TRG_NumStepsGet(track);
147
        for(step=0; step<num_steps; ++step)
328 tk 148
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, ui_selected_instrument, new_value);
318 tk 149
      }
178 tk 150
      } else {
151
    // a) ALL function active, but ALL button not pressed: invert complete trigger layer
303 tk 152
    u8 track;
153
    u16 step;
178 tk 154
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
155
      if( SEQ_UI_IsSelectedTrack(track) ) {
318 tk 156
        u16 num_steps = SEQ_TRG_NumStepsGet(track);
157
        for(step=0; step<num_steps; ++step) {
328 tk 158
          u8 new_value = SEQ_TRG_Get(track, step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
159
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, ui_selected_instrument, new_value);
178 tk 160
        }
161
      }
162
    }
163
      }
164
    } else {
165
      // c) ALL function not active: toggle step
166
      u8 track;
484 tk 167
 
168
      u8 new_value = SEQ_TRG_Get(visible_track, ui_selected_step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
178 tk 169
      for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
170
    if( SEQ_UI_IsSelectedTrack(track) ) {
328 tk 171
      SEQ_TRG_Set(track, ui_selected_step, ui_selected_trg_layer, ui_selected_instrument, new_value);
178 tk 172
    }
173
      }
174
    }
168 tk 175
    return 1; // value always changed
178 tk 176
 
168 tk 177
  } else {
178
    switch( button ) {
179
      case SEQ_UI_BUTTON_Select:
303 tk 180
      case SEQ_UI_BUTTON_Right: {
181
    int next_step = ui_selected_step + 1; // (required, since ui_selected_step is only u8, but we could have up to 256 steps)
306 tk 182
    if( next_step >= (SEQ_CC_Get(visible_track, SEQ_CC_LENGTH)+1) )
303 tk 183
      next_step = 0;
184
    ui_selected_step = next_step;
168 tk 185
    ui_selected_step_view = ui_selected_step / 16;
186
    return 1; // value always changed
303 tk 187
      } break;
167 tk 188
 
168 tk 189
      case SEQ_UI_BUTTON_Left:
190
    if( ui_selected_step == 0 )
306 tk 191
      ui_selected_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
168 tk 192
    ui_selected_step_view = ui_selected_step / 16;
193
    return 1; // value always changed
167 tk 194
 
168 tk 195
      case SEQ_UI_BUTTON_Up:
196
    return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
197
 
198
      case SEQ_UI_BUTTON_Down:
199
    return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
200
    }
167 tk 201
  }
202
 
168 tk 203
  return -1; // invalid or unsupported button
167 tk 204
}
205
 
206
 
207
/////////////////////////////////////////////////////////////////////////////
240 tk 208
// Global Display Handler function
167 tk 209
// IN: <high_prio>: if set, a high-priority LCD update is requested
240 tk 210
//     <edit_page>: selects the normal, or copy/paste/move/scroll view
167 tk 211
/////////////////////////////////////////////////////////////////////////////
240 tk 212
s32 SEQ_UI_EDIT_LCD_Handler(u8 high_prio, seq_ui_edit_mode_t edit_mode)
167 tk 213
{
214
  if( high_prio )
215
    return 0; // there are no high-priority updates
216
 
326 tk 217
 
218
  // layout common track:
219
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
220
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
221
  // G1T1 xxxxxxxxxxxxxxx  PC:Length TA:Gate Step  1   G#1_ Vel:127_Len: 75%    xxxxx
222
  // ....
223
 
224
  // layout drum track:
225
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
226
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
227
  // G1T1 xxxxxxxxxxxxxxx  PA:Vel.   TA:Gate Step  1   G#1_ Vel:127_Len: 75%    xxxxx
228
  // ....
229
 
230
 
167 tk 231
  u8 visible_track = SEQ_UI_VisibleTrackGet();
323 tk 232
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
167 tk 233
 
176 tk 234
  seq_layer_evnt_t layer_event;
336 tk 235
  SEQ_LAYER_GetEvntOfLayer(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
168 tk 236
 
333 tk 237
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
176 tk 238
 
333 tk 239
  // TODO: tmp. solution to print chord velocity correctly
240
  if( layer_type == SEQ_PAR_Type_Velocity && (seq_cc_trk[visible_track].link_par_layer_chord == 0) )
241
    layer_type = SEQ_PAR_Type_Chord;
326 tk 242
 
333 tk 243
 
167 tk 244
  ///////////////////////////////////////////////////////////////////////////
278 tk 245
  SEQ_LCD_CursorSet(0, 0);
167 tk 246
 
326 tk 247
  SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
248
  SEQ_LCD_PrintSpaces(1);
249
 
240 tk 250
  switch( edit_mode ) {
251
    case SEQ_UI_EDIT_MODE_COPY: {
252
      if( ui_cursor_flash ) {
253
    SEQ_LCD_PrintSpaces(15);
254
      } else {
255
    char str_buffer[10];
256
    sprintf(str_buffer, "%d-%d", SEQ_UI_UTIL_CopyPasteBeginGet()+1, SEQ_UI_UTIL_CopyPasteEndGet()+1);
278 tk 257
    SEQ_LCD_PrintFormattedString("COPY S%-9s", str_buffer);
240 tk 258
      }
259
    } break;
167 tk 260
 
240 tk 261
    case SEQ_UI_EDIT_MODE_PASTE: {
262
      if( ui_cursor_flash ) {
263
    SEQ_LCD_PrintSpaces(15);
264
      } else {
278 tk 265
    SEQ_LCD_PrintFormattedString("PASTE OFFS.%3d ", ui_selected_step+1);
240 tk 266
      }
267
    } break;
167 tk 268
 
240 tk 269
    case SEQ_UI_EDIT_MODE_MOVE: {
270
      if( ui_cursor_flash ) {
271
    SEQ_LCD_PrintSpaces(15);
272
      } else {
278 tk 273
    SEQ_LCD_PrintString("MOVE STEPS     ");
240 tk 274
      }
275
    } break;
176 tk 276
 
240 tk 277
    case SEQ_UI_EDIT_MODE_SCROLL: {
278
      if( ui_cursor_flash ) {
279
    SEQ_LCD_PrintSpaces(15);
280
      } else {
278 tk 281
    SEQ_LCD_PrintString("SCROLL TRACK   ");
240 tk 282
      }
283
    } break;
176 tk 284
 
240 tk 285
    case SEQ_UI_EDIT_MODE_RANDOM: {
286
      if( ui_cursor_flash ) {
287
    SEQ_LCD_PrintSpaces(15);
288
      } else {
278 tk 289
    SEQ_LCD_PrintString("RANDOMIZED     ");
240 tk 290
      }
291
    } break;
176 tk 292
 
240 tk 293
    case SEQ_UI_EDIT_MODE_RECORD: {
294
      if( ui_cursor_flash ) {
295
    SEQ_LCD_PrintSpaces(15);
296
      } else {
416 tk 297
    SEQ_LCD_PrintString("RECORDING      ");
240 tk 298
      }
299
    } break;
176 tk 300
 
240 tk 301
    default: {
326 tk 302
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
303
    SEQ_LCD_PrintChar(' ');
304
    SEQ_LCD_PrintChar(' ');
305
    SEQ_LCD_PrintMIDIOutPort(SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT));
306
    SEQ_LCD_PrintChar(' ');
307
    SEQ_LCD_PrintFormattedString("Chn.%2d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
308
      } else {
309
    SEQ_LCD_PrintTrackLabel(visible_track, (char *)seq_core_trk[visible_track].name);
310
      }
311
    }
312
  }
176 tk 313
 
326 tk 314
  SEQ_LCD_PrintSpaces(2);
176 tk 315
 
326 tk 316
  SEQ_LCD_PrintChar('P');
317
  SEQ_LCD_PrintChar('A' + ui_selected_par_layer);
318
  SEQ_LCD_PrintChar(':');
240 tk 319
 
333 tk 320
  if( layer_type == SEQ_PAR_Type_CC ) {
321
    SEQ_LCD_PrintFormattedString("CC#%3d ", layer_event.midi_package.cc_number);
322
  } else {
323
    SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, ui_selected_par_layer));
324
    SEQ_LCD_PrintSpaces(2);
176 tk 325
  }
167 tk 326
 
328 tk 327
  SEQ_LCD_PrintFormattedString("T%c:%s", 'A' + ui_selected_trg_layer, SEQ_TRG_AssignedTypeStr(visible_track, ui_selected_trg_layer));
327 tk 328
 
329
 
167 tk 330
  ///////////////////////////////////////////////////////////////////////////
278 tk 331
  SEQ_LCD_CursorSet(40, 0);
167 tk 332
 
326 tk 333
  SEQ_LCD_PrintFormattedString("Step%3d   ", ui_selected_step+1);
167 tk 334
 
176 tk 335
  if( layer_event.midi_package.event == CC ) {
278 tk 336
    SEQ_LCD_PrintFormattedString("CC#%3d %3d",
176 tk 337
                    layer_event.midi_package.cc_number,
338
                    layer_event.midi_package.value);
339
    SEQ_LCD_PrintVBar(layer_event.midi_package.value >> 4);
340
  } else {
178 tk 341
    if( layer_event.midi_package.note && layer_event.midi_package.velocity && (layer_event.len >= 0) ) {
288 tk 342
      if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator ) {
182 tk 343
    SEQ_LCD_PrintArp(layer_event.midi_package.note);
333 tk 344
      } else if( layer_type == SEQ_PAR_Type_Chord ) {
328 tk 345
    u8 par_value = SEQ_PAR_Get(visible_track, ui_selected_step, 0, ui_selected_instrument);
288 tk 346
    u8 chord_ix = par_value & 0x0f;
347
    u8 chord_oct = par_value >> 4;
348
    SEQ_LCD_PrintString(SEQ_CHORD_NameGet(chord_ix));
349
    SEQ_LCD_PrintFormattedString("/%d", chord_oct);
350
      } else {
182 tk 351
    SEQ_LCD_PrintNote(layer_event.midi_package.note);
288 tk 352
      }
176 tk 353
      SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
354
    }
355
    else {
278 tk 356
      SEQ_LCD_PrintString("....");
176 tk 357
    }
278 tk 358
    SEQ_LCD_PrintFormattedString(" Vel:%3d", layer_event.midi_package.velocity);
176 tk 359
  }
167 tk 360
 
278 tk 361
  SEQ_LCD_PrintString(" Len:");
176 tk 362
  SEQ_LCD_PrintGatelength(layer_event.len);
326 tk 363
  SEQ_LCD_PrintSpaces(4);
167 tk 364
 
326 tk 365
  if( event_mode == SEQ_EVENT_MODE_Drum ) {
328 tk 366
    SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
326 tk 367
  } else {
368
    SEQ_LCD_PrintTrackCategory(visible_track, (char *)seq_core_trk[visible_track].name);
180 tk 369
  }
167 tk 370
 
371
  ///////////////////////////////////////////////////////////////////////////
372
 
336 tk 373
  u8 show_drum_triggers = (event_mode == SEQ_EVENT_MODE_Drum && (edit_mode || !ui_hold_msg_ctr));
335 tk 374
 
176 tk 375
  // extra handling for gatelength (shows vertical bars)
335 tk 376
  if( !show_drum_triggers && layer_type == SEQ_PAR_Type_Length ) {
167 tk 377
 
176 tk 378
    // we want to show horizontal bars
379
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_HBars);
167 tk 380
 
176 tk 381
    // initial cursor position
278 tk 382
    SEQ_LCD_CursorSet(0, 1);
167 tk 383
 
176 tk 384
    // determine length of previous step (depends on selected view and track length)
385
    int previous_step = 16*ui_selected_step_view - 1;
386
    if( previous_step < 0 )
387
      previous_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
388
 
389
    seq_layer_evnt_t layer_event;
336 tk 390
    SEQ_LAYER_GetEvntOfLayer(visible_track, previous_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
176 tk 391
    u16 previous_length = layer_event.len;
330 tk 392
 
393
    // show length of 16 steps
336 tk 394
    u16 step;
330 tk 395
    for(step=0; step<16; ++step) {
336 tk 396
      u16 visible_step = step + 16*ui_selected_step_view;
397
      SEQ_LAYER_GetEvntOfLayer(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
330 tk 398
 
338 tk 399
      // muted step? if previous gatelength <= 96, print spaces
400
      if( !layer_event.midi_package.velocity && previous_length < 96 ) {
401
    SEQ_LCD_PrintSpaces(5);
402
      } else {
403
    if( layer_event.len >= 96 )
404
      SEQ_LCD_PrintHBar(15); // glide or stretched event
330 tk 405
    else
338 tk 406
      SEQ_LCD_PrintHBar(((layer_event.len-1)*16)/100);
330 tk 407
      }
338 tk 408
      previous_length = (layer_event.midi_package.velocity || (previous_length >= 96 && layer_event.len >= 96)) ? layer_event.len : 0;
330 tk 409
    }
410
 
176 tk 411
  } else {
412
 
335 tk 413
    if( show_drum_triggers ) {
323 tk 414
      // we want to show triggers
325 tk 415
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_DrumSymbolsBig);
323 tk 416
    } else {
417
      // we want to show vertical bars
418
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
419
    }
176 tk 420
 
421
    // initial cursor position
278 tk 422
    SEQ_LCD_CursorSet(0, 1);
176 tk 423
 
323 tk 424
    int step_region_begin;
425
    int step_region_end;
240 tk 426
    switch( edit_mode ) {
427
      case SEQ_UI_EDIT_MODE_COPY:
428
    step_region_begin = SEQ_UI_UTIL_CopyPasteBeginGet();
429
    step_region_end = SEQ_UI_UTIL_CopyPasteEndGet();
430
    break;
431
      case SEQ_UI_EDIT_MODE_PASTE:
432
    step_region_begin = ui_selected_step;
433
    step_region_end = ui_selected_step + SEQ_UI_UTIL_CopyPasteEndGet() - SEQ_UI_UTIL_CopyPasteBeginGet();
434
    break;
435
      case SEQ_UI_EDIT_MODE_SCROLL:
436
    step_region_begin = ui_selected_step;
437
    step_region_end = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
438
    break;
439
      default:
336 tk 440
    step_region_begin = ui_selected_step;
441
    step_region_end = ui_selected_step;
240 tk 442
    }
443
 
336 tk 444
    u16 step;
176 tk 445
    for(step=0; step<16; ++step) {
336 tk 446
      u16 visible_step = step + 16*ui_selected_step_view;
240 tk 447
 
448
      if( ui_cursor_flash &&
449
      edit_mode != SEQ_UI_EDIT_MODE_NORMAL &&
450
      visible_step >= step_region_begin && visible_step <= step_region_end ) {
451
    SEQ_LCD_PrintSpaces(5);
452
    continue;
453
      }
454
 
176 tk 455
      seq_layer_evnt_t layer_event;
336 tk 456
      SEQ_LAYER_GetEvntOfLayer(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
176 tk 457
 
335 tk 458
      if( show_drum_triggers ) {
336 tk 459
    u8 gate_accent = SEQ_TRG_Get(visible_track, visible_step, 0, ui_selected_instrument);
328 tk 460
    if( SEQ_TRG_NumLayersGet(visible_track) >= 2 )
336 tk 461
      gate_accent |= SEQ_TRG_Get(visible_track, visible_step, 1, ui_selected_instrument) << 1;
335 tk 462
 
323 tk 463
    SEQ_LCD_PrintChar(' ');
464
    SEQ_LCD_PrintChar(' ');
327 tk 465
    SEQ_LCD_PrintChar(gate_accent);
323 tk 466
    SEQ_LCD_PrintChar(' ');
467
    SEQ_LCD_PrintChar(' ');
468
      } else {
333 tk 469
    switch( layer_type ) {
470
          case SEQ_PAR_Type_None:
471
        SEQ_LCD_PrintString("None");
472
        break;
473
 
474
          case SEQ_PAR_Type_Note:
475
          case SEQ_PAR_Type_Velocity:
323 tk 476
        if( layer_event.midi_package.note && layer_event.midi_package.velocity ) {
477
          if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator )
478
        SEQ_LCD_PrintArp(layer_event.midi_package.note);
479
          else
480
        SEQ_LCD_PrintNote(layer_event.midi_package.note);
481
          SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
482
        } else {
483
          SEQ_LCD_PrintString("----");
484
        }
485
        break;
486
 
333 tk 487
      case SEQ_PAR_Type_Chord:
323 tk 488
        if( layer_event.midi_package.note && layer_event.midi_package.velocity ) {
336 tk 489
          u8 par_value;
490
          // more or less dirty - a velocity layer can force SEQ_PAR_Type_Chord
491
          if( SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer) == SEQ_PAR_Type_Velocity )
492
        par_value = SEQ_PAR_ChordGet(visible_track, visible_step, ui_selected_instrument);
493
          else
494
        par_value = SEQ_PAR_Get(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument);
323 tk 495
          u8 chord_ix = par_value & 0x0f;
496
          u8 chord_oct = par_value >> 4;
497
          SEQ_LCD_PrintFormattedString("%X/%d", chord_ix, chord_oct);
498
          SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
499
        } else {
500
          SEQ_LCD_PrintString("----");
501
        }
502
        break;
176 tk 503
 
333 tk 504
      //case SEQ_PAR_Type_Length:
323 tk 505
      //break;
506
      // extra handling -- see code above
176 tk 507
 
333 tk 508
      case SEQ_PAR_Type_CC:
509
      case SEQ_PAR_Type_PitchBend: {
510
        u8 value = layer_event.midi_package.value;
511
        SEQ_LCD_PrintFormattedString("%3d", value);
512
        SEQ_LCD_PrintVBar(value >> 4);
513
      } break;
514
 
515
      case SEQ_PAR_Type_Probability:
336 tk 516
        SEQ_LCD_PrintProbability(SEQ_PAR_ProbabilityGet(visible_track, visible_step, ui_selected_instrument));
323 tk 517
        break;
176 tk 518
 
333 tk 519
      case SEQ_PAR_Type_Delay:
336 tk 520
        SEQ_LCD_PrintStepDelay(SEQ_PAR_StepDelayGet(visible_track, visible_step, ui_selected_instrument));
333 tk 521
        break;
522
 
523
      case SEQ_PAR_Type_Roll:
336 tk 524
        SEQ_LCD_PrintRollMode(SEQ_PAR_RollModeGet(visible_track, visible_step, ui_selected_instrument));
333 tk 525
        break;
526
 
323 tk 527
          default:
528
        SEQ_LCD_PrintString("????");
529
        break;
530
    }
176 tk 531
      }
532
 
336 tk 533
      if( !show_drum_triggers ) {
323 tk 534
    SEQ_LCD_PrintChar((visible_step == step_region_end) ? '<'
535
              : ((visible_step == (step_region_begin-1)) ? '>' : ' '));
536
      }
240 tk 537
 
176 tk 538
    }
167 tk 539
  }
540
 
541
  return 0; // no error
542
}
543
 
544
 
545
/////////////////////////////////////////////////////////////////////////////
240 tk 546
// Local Display Handler function
547
// IN: <high_prio>: if set, a high-priority LCD update is requested
548
/////////////////////////////////////////////////////////////////////////////
549
static s32 LCD_Handler(u8 high_prio)
550
{
551
  return SEQ_UI_EDIT_LCD_Handler(high_prio, SEQ_UI_EDIT_MODE_NORMAL);
552
}
553
 
554
 
555
/////////////////////////////////////////////////////////////////////////////
167 tk 556
// Initialisation
557
/////////////////////////////////////////////////////////////////////////////
558
s32 SEQ_UI_EDIT_Init(u32 mode)
559
{
560
  // install callback routines
168 tk 561
  SEQ_UI_InstallButtonCallback(Button_Handler);
562
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
240 tk 563
  SEQ_UI_InstallLEDCallback(SEQ_UI_EDIT_LED_Handler);
168 tk 564
  SEQ_UI_InstallLCDCallback(LCD_Handler);
167 tk 565
 
566
  return 0; // no error
567
}
178 tk 568
 
569
 
570
 
571
/////////////////////////////////////////////////////////////////////////////
572
// help function to change/set a single encoder value
573
// if forced_value >= 0: new value will be set to the given value
574
// if forced_value < 0: new value will be changed via incrementer
575
// returns >= 0 if new value has been set (value change)
576
// returns < 0 if no change
577
/////////////////////////////////////////////////////////////////////////////
318 tk 578
static s32 ChangeSingleEncValue(u8 track, u16 step, s32 incrementer, s32 forced_value, u8 change_gate)
178 tk 579
{
333 tk 580
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(track, ui_selected_par_layer);
335 tk 581
  u8 visible_track = SEQ_UI_VisibleTrackGet();
178 tk 582
 
333 tk 583
  // if note/chord/velocity parameter: only change gate if requested
584
  if( (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord || layer_type == SEQ_PAR_Type_Velocity) &&
178 tk 585
      !change_gate &&
328 tk 586
      !SEQ_TRG_GateGet(track, step, ui_selected_instrument) )
178 tk 587
    return -1;
588
 
335 tk 589
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
590
  if( event_mode == SEQ_EVENT_MODE_Drum )
591
    ui_hold_msg_ctr = 1000; // show value for 1 second
592
 
328 tk 593
  s32 old_value = SEQ_PAR_Get(track, step, ui_selected_par_layer, ui_selected_instrument);
178 tk 594
  s32 new_value = (forced_value >= 0) ? forced_value : (old_value + incrementer);
595
  if( new_value < 0 )
596
    new_value = 0;
597
  else if( new_value >= 128 )
598
    new_value = 127;
599
 
600
  // take over if changed
601
  if( new_value == old_value )
602
    return -1;
603
 
328 tk 604
  SEQ_PAR_Set(track, step, ui_selected_par_layer, ui_selected_instrument, (u8)new_value);
178 tk 605
 
333 tk 606
  if( layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord || layer_type == SEQ_PAR_Type_Velocity ) {
178 tk 607
    // (de)activate gate depending on value
608
    if( new_value )
328 tk 609
      SEQ_TRG_GateSet(track, step, ui_selected_instrument, 1);
178 tk 610
    else
328 tk 611
      SEQ_TRG_GateSet(track, step, ui_selected_instrument, 0);
178 tk 612
  }
613
 
614
  return new_value;
615
}