Subversion Repositories svn.mios32

Rev

Rev 190 | Rev 278 | 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 240 2009-01-04 00:26:14Z 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
 
33
static s32 ChangeSingleEncValue(u8 track, u8 step, s32 incrementer, s32 forced_value, u8 change_gate);
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 =
240 tk 44
    (SEQ_TRG_Get8(visible_track, 2*ui_selected_step_view+1, ui_selected_trg_layer) << 8) |
45
    (SEQ_TRG_Get8(visible_track, 2*ui_selected_step_view+0, ui_selected_trg_layer) << 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 &&
77
    SEQ_LAYER_GetVControlType(visible_track, ui_selected_par_layer) == SEQ_LAYER_ControlType_Note )
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;
91
    u8 step;
92
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
93
      if( SEQ_UI_IsSelectedTrack(track) ) {
94
    for(step=0; step<SEQ_CORE_NUM_STEPS; ++step) {
95
      change_gate = step == ui_selected_step;
96
      if( change_gate || seq_ui_button_state.CHANGE_ALL_STEPS ) {
97
        if( ChangeSingleEncValue(track, step, incrementer, forced_value, change_gate) >= 0 )
98
          value_changed |= 1;
99
      }
100
    }
101
      }
176 tk 102
    }
168 tk 103
 
178 tk 104
    return value_changed;
168 tk 105
  }
106
 
107
  return -1; // invalid or unsupported encoder
167 tk 108
}
109
 
110
 
111
/////////////////////////////////////////////////////////////////////////////
168 tk 112
// Local button callback function
113
// Should return:
114
//   1 if value has been changed
115
//   0 if value hasn't been changed
116
//  -1 if invalid or unsupported button
167 tk 117
/////////////////////////////////////////////////////////////////////////////
168 tk 118
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
167 tk 119
{
168 tk 120
  if( depressed ) return 0; // ignore when button depressed
167 tk 121
 
168 tk 122
#if 0
123
  // leads to: comparison is always true due to limited range of data type
124
  if( button >= SEQ_UI_BUTTON_GP1 && button <= SEQ_UI_BUTTON_GP16 ) {
125
#else
126
  if( button <= SEQ_UI_BUTTON_GP16 ) {
127
#endif
180 tk 128
    ui_selected_step = button + ui_selected_step_view*16;
168 tk 129
    // toggle trigger layer
178 tk 130
    // we've three cases:
131
    // a) ALL function active, but ALL button not pressed: invert complete trigger layer
132
    // b) ALL function active and ALL button pressed: toggle step, set remaining steps to same new value
133
    // c) ALL function not active: toggle step
134
    if( seq_ui_button_state.CHANGE_ALL_STEPS ) {
135
      if( seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
136
    // b) ALL function active and ALL button pressed: toggle step, set remaining steps to same new value
137
    u8 visible_track = SEQ_UI_VisibleTrackGet();
180 tk 138
    u8 step = ui_selected_step;
178 tk 139
    u8 new_value = SEQ_TRG_Get(visible_track, step, ui_selected_trg_layer) ? 0 : 1;
140
 
141
    u8 track;
142
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
143
      if( SEQ_UI_IsSelectedTrack(track) )
144
        for(step=0; step<SEQ_CORE_NUM_STEPS; ++step)
145
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, new_value);
146
      } else {
147
    // a) ALL function active, but ALL button not pressed: invert complete trigger layer
148
    u8 track, step;
149
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
150
      if( SEQ_UI_IsSelectedTrack(track) ) {
151
        for(step=0; step<SEQ_CORE_NUM_STEPS; ++step) {
152
          u8 new_value = SEQ_TRG_Get(track, step, ui_selected_trg_layer) ? 0 : 1;
153
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, new_value);
154
        }
155
      }
156
    }
157
      }
158
    } else {
159
      // c) ALL function not active: toggle step
160
      u8 track;
161
      for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
162
    if( SEQ_UI_IsSelectedTrack(track) ) {
180 tk 163
      u8 new_value = SEQ_TRG_Get(track, ui_selected_step, ui_selected_trg_layer) ? 0 : 1;
164
      SEQ_TRG_Set(track, ui_selected_step, ui_selected_trg_layer, new_value);
178 tk 165
    }
166
      }
167
    }
168 tk 168
    return 1; // value always changed
178 tk 169
 
168 tk 170
  } else {
171
    switch( button ) {
172
      case SEQ_UI_BUTTON_Select:
173
      case SEQ_UI_BUTTON_Right:
174
    if( ++ui_selected_step >= SEQ_CORE_NUM_STEPS )
175
      ui_selected_step = 0;
176
    ui_selected_step_view = ui_selected_step / 16;
177
    return 1; // value always changed
167 tk 178
 
168 tk 179
      case SEQ_UI_BUTTON_Left:
180
    if( ui_selected_step == 0 )
181
      ui_selected_step = SEQ_CORE_NUM_STEPS-1;
182
    ui_selected_step_view = ui_selected_step / 16;
183
    return 1; // value always changed
167 tk 184
 
168 tk 185
      case SEQ_UI_BUTTON_Up:
186
    return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
187
 
188
      case SEQ_UI_BUTTON_Down:
189
    return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
190
    }
167 tk 191
  }
192
 
168 tk 193
  return -1; // invalid or unsupported button
167 tk 194
}
195
 
196
 
197
/////////////////////////////////////////////////////////////////////////////
240 tk 198
// Global Display Handler function
167 tk 199
// IN: <high_prio>: if set, a high-priority LCD update is requested
240 tk 200
//     <edit_page>: selects the normal, or copy/paste/move/scroll view
167 tk 201
/////////////////////////////////////////////////////////////////////////////
240 tk 202
s32 SEQ_UI_EDIT_LCD_Handler(u8 high_prio, seq_ui_edit_mode_t edit_mode)
167 tk 203
{
204
  if( high_prio )
205
    return 0; // there are no high-priority updates
206
 
207
  u8 visible_track = SEQ_UI_VisibleTrackGet();
208
 
176 tk 209
  seq_layer_evnt_t layer_event;
180 tk 210
  SEQ_LAYER_GetEvntOfParLayer(visible_track, ui_selected_step, ui_selected_par_layer, &layer_event);
168 tk 211
 
176 tk 212
 
167 tk 213
  ///////////////////////////////////////////////////////////////////////////
214
  MIOS32_LCD_DeviceSet(0);
215
  MIOS32_LCD_CursorSet(0, 0);
216
 
240 tk 217
  switch( edit_mode ) {
218
    case SEQ_UI_EDIT_MODE_COPY: {
219
      if( ui_cursor_flash ) {
220
    SEQ_LCD_PrintSpaces(15);
221
      } else {
222
    char str_buffer[10];
223
    sprintf(str_buffer, "%d-%d", SEQ_UI_UTIL_CopyPasteBeginGet()+1, SEQ_UI_UTIL_CopyPasteEndGet()+1);
224
    MIOS32_LCD_PrintFormattedString("COPY S%-9s", str_buffer);
225
      }
226
    } break;
167 tk 227
 
240 tk 228
    case SEQ_UI_EDIT_MODE_PASTE: {
229
      if( ui_cursor_flash ) {
230
    SEQ_LCD_PrintSpaces(15);
231
      } else {
232
    MIOS32_LCD_PrintFormattedString("PASTE OFFS.%3d ", ui_selected_step+1);
233
      }
234
    } break;
167 tk 235
 
240 tk 236
    case SEQ_UI_EDIT_MODE_MOVE: {
237
      if( ui_cursor_flash ) {
238
    SEQ_LCD_PrintSpaces(15);
239
      } else {
240
    MIOS32_LCD_PrintString("MOVE STEPS     ");
241
      }
242
    } break;
176 tk 243
 
240 tk 244
    case SEQ_UI_EDIT_MODE_SCROLL: {
245
      if( ui_cursor_flash ) {
246
    SEQ_LCD_PrintSpaces(15);
247
      } else {
248
    MIOS32_LCD_PrintString("SCROLL TRACK   ");
249
      }
250
    } break;
176 tk 251
 
240 tk 252
    case SEQ_UI_EDIT_MODE_RANDOM: {
253
      if( ui_cursor_flash ) {
254
    SEQ_LCD_PrintSpaces(15);
255
      } else {
256
    MIOS32_LCD_PrintString("RANDOMIZED     ");
257
      }
258
    } break;
176 tk 259
 
240 tk 260
    case SEQ_UI_EDIT_MODE_RECORD: {
261
      if( ui_cursor_flash ) {
262
    SEQ_LCD_PrintSpaces(15);
263
      } else {
264
    MIOS32_LCD_PrintString("RECORDING MODE ");
265
      }
266
    } break;
176 tk 267
 
240 tk 268
    default: {
269
      SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
270
      SEQ_LCD_PrintSpaces(2);
176 tk 271
 
240 tk 272
      MIOS32_LCD_PrintChar('A' + ui_selected_par_layer);
273
      MIOS32_LCD_PrintChar(':');
176 tk 274
 
240 tk 275
      switch( SEQ_LAYER_GetVControlType(visible_track, ui_selected_par_layer) ) {
276
        case SEQ_LAYER_ControlType_Note:
277
      MIOS32_LCD_PrintString("Note   ");
278
      break;
279
 
280
        case SEQ_LAYER_ControlType_Velocity:
281
        case SEQ_LAYER_ControlType_Chord1_Velocity:
282
        case SEQ_LAYER_ControlType_Chord2_Velocity:
283
          MIOS32_LCD_PrintString("Vel.   ");
284
          break;
285
 
286
        case SEQ_LAYER_ControlType_Chord1:
287
          MIOS32_LCD_PrintString("Chord1 ");
288
          break;
289
 
290
        case SEQ_LAYER_ControlType_Chord2:
291
          MIOS32_LCD_PrintString("Chord2 ");
292
          break;
293
 
294
        case SEQ_LAYER_ControlType_Length:
295
          MIOS32_LCD_PrintString("Length ");
296
          break;
297
 
298
        case SEQ_LAYER_ControlType_CC:
299
          MIOS32_LCD_PrintFormattedString("CC#%3d ", layer_event.midi_package.cc_number);
300
          break;
301
 
302
        default:
303
          MIOS32_LCD_PrintString("???    ");
304
          break;
305
      }
306
    }
176 tk 307
  }
240 tk 308
 
168 tk 309
  MIOS32_LCD_PrintFormattedString("Chn%2d", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
167 tk 310
  MIOS32_LCD_PrintChar('/');
168 tk 311
  SEQ_LCD_PrintMIDIPort(SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT));
167 tk 312
  SEQ_LCD_PrintSpaces(1);
313
 
180 tk 314
  MIOS32_LCD_PrintFormattedString("%c:%s", 'A' + ui_selected_par_layer, SEQ_TRG_AssignedTypeStr(visible_track, ui_selected_trg_layer));
315
  MIOS32_LCD_PrintChar(' ');
167 tk 316
 
317
  SEQ_LCD_PrintStepView(ui_selected_step_view);
318
 
319
 
320
  ///////////////////////////////////////////////////////////////////////////
321
  MIOS32_LCD_DeviceSet(1);
322
  MIOS32_LCD_CursorSet(0, 0);
323
 
324
  MIOS32_LCD_PrintFormattedString("Step");
325
  SEQ_LCD_PrintSelectedStep(ui_selected_step, 15);
326
  MIOS32_LCD_PrintChar(':');
327
 
176 tk 328
  if( layer_event.midi_package.event == CC ) {
329
    MIOS32_LCD_PrintFormattedString("CC#%3d %3d",
330
                    layer_event.midi_package.cc_number,
331
                    layer_event.midi_package.value);
332
    SEQ_LCD_PrintVBar(layer_event.midi_package.value >> 4);
333
  } else {
178 tk 334
    if( layer_event.midi_package.note && layer_event.midi_package.velocity && (layer_event.len >= 0) ) {
182 tk 335
      if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator )
336
    SEQ_LCD_PrintArp(layer_event.midi_package.note);
337
      else
338
    SEQ_LCD_PrintNote(layer_event.midi_package.note);
176 tk 339
      SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
340
    }
341
    else {
342
      MIOS32_LCD_PrintString("....");
343
    }
344
    MIOS32_LCD_PrintFormattedString(" Vel:%3d", layer_event.midi_package.velocity);
345
  }
167 tk 346
 
176 tk 347
  MIOS32_LCD_PrintString(" Len:");
348
  SEQ_LCD_PrintGatelength(layer_event.len);
167 tk 349
  SEQ_LCD_PrintSpaces(1);
350
 
180 tk 351
  int i;
352
  const char trg_chars[8] = "gsagrgv";
353
  for(i=0; i<7; ++i) {
354
    u8 trg_layer;
355
    if( !(trg_layer=SEQ_TRG_AssignmentGet(visible_track, i)) )
356
      MIOS32_LCD_PrintChar('-');
357
    else
358
      MIOS32_LCD_PrintChar(SEQ_TRG_Get(visible_track, ui_selected_step, trg_layer-1) ? (trg_chars[i]-32) : trg_chars[i]);
359
  }
167 tk 360
 
180 tk 361
 
167 tk 362
  ///////////////////////////////////////////////////////////////////////////
176 tk 363
  seq_layer_ctrl_type_t layer_ctrl_type = SEQ_LAYER_GetVControlType(visible_track, ui_selected_par_layer);
167 tk 364
 
176 tk 365
  // extra handling for gatelength (shows vertical bars)
366
  if( layer_ctrl_type == SEQ_LAYER_ControlType_Length ) {
167 tk 367
 
176 tk 368
    // we want to show horizontal bars
369
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_HBars);
167 tk 370
 
176 tk 371
    // initial cursor position
372
    MIOS32_LCD_DeviceSet(0);
373
    MIOS32_LCD_CursorSet(0, 1);
167 tk 374
 
176 tk 375
    // determine length of previous step (depends on selected view and track length)
376
    int previous_step = 16*ui_selected_step_view - 1;
377
    if( previous_step < 0 )
378
      previous_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
379
 
380
    seq_layer_evnt_t layer_event;
381
    SEQ_LAYER_GetEvntOfParLayer(visible_track, previous_step, ui_selected_par_layer, &layer_event);
382
    u16 previous_length = layer_event.len;
383
    u8 previous_step_was_long_multi = 0; // hard to determine here... TODO
384
 
385
    // show length of 16 steps
180 tk 386
    u8 step;
176 tk 387
    for(step=0; step<16; ++step) {
388
      // 9th step reached: switch to second LCD
389
      if( step == 8 ) {
390
    MIOS32_LCD_DeviceSet(1);
391
    MIOS32_LCD_CursorSet(0, 1);
392
      }
393
 
394
      u8 visible_step = step + 16*ui_selected_step_view;
395
      SEQ_LAYER_GetEvntOfParLayer(visible_track, visible_step, ui_selected_par_layer, &layer_event);
396
 
178 tk 397
      if( previous_step_was_long_multi || layer_event.len >= 32 ) { // multi note trigger?
176 tk 398
    if( !previous_step_was_long_multi ) {
178 tk 399
      if( previous_length <= 24 && !layer_event.midi_package.velocity ) {
176 tk 400
        SEQ_LCD_PrintSpaces(5);
401
        previous_length = 0;
402
      } else {
403
        SEQ_LCD_PrintGatelength(layer_event.len);
404
        MIOS32_LCD_PrintChar(layer_event.midi_package.velocity ? ' ' : '?'); // notify about multi-triggered events 
405
        // with gate=0 and previous length >= 24 - we don't know how the core will react here
406
 
407
        // calculate total length of events -> previous_length
178 tk 408
        previous_length = (layer_event.len>>5) * (layer_event.len & 0x1f);
409
        // long event if >= 24
410
        previous_step_was_long_multi = previous_length >= 24;
176 tk 411
      }
167 tk 412
    } else {
176 tk 413
      // continued long event
414
      // previous step took 24 steps
415
      previous_length -= 24;
178 tk 416
      // print warning (!!!) if current step activated and overlapped by long multi trigger
176 tk 417
      if( previous_step_was_long_multi && !layer_event.midi_package.velocity )
178 tk 418
        MIOS32_LCD_PrintString(">>>> ");
419
      else
176 tk 420
        MIOS32_LCD_PrintString("!!!! ");
178 tk 421
      // still long event if >= 24
422
      previous_step_was_long_multi = previous_length >= 24;
167 tk 423
    }
176 tk 424
      } else {
425
    previous_step_was_long_multi = 0;
178 tk 426
    // muted step? if previous gatelength <= 24, print spaces
427
    if( !layer_event.midi_package.velocity && previous_length <= 24 ) {
176 tk 428
      SEQ_LCD_PrintSpaces(5);
429
    } else {
178 tk 430
      if( layer_event.len >= 24 )
176 tk 431
        SEQ_LCD_PrintHBar(15); // glide
432
      else
433
        SEQ_LCD_PrintHBar((layer_event.len-1) >> 1);
434
    }
178 tk 435
    previous_length = (layer_event.midi_package.velocity || (previous_length > 24 && layer_event.len > 24)) ? layer_event.len : 0;
176 tk 436
      }
167 tk 437
    }
438
 
176 tk 439
  } else {
440
 
441
    // we want to show vertical bars
442
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
443
 
444
    // initial cursor position
445
    MIOS32_LCD_DeviceSet(0);
446
    MIOS32_LCD_CursorSet(0, 1);
447
 
240 tk 448
    u8 step_region_begin;
449
    u8 step_region_end;
450
    switch( edit_mode ) {
451
      case SEQ_UI_EDIT_MODE_COPY:
452
    step_region_begin = SEQ_UI_UTIL_CopyPasteBeginGet();
453
    step_region_end = SEQ_UI_UTIL_CopyPasteEndGet();
454
    break;
455
      case SEQ_UI_EDIT_MODE_PASTE:
456
    step_region_begin = ui_selected_step;
457
    step_region_end = ui_selected_step + SEQ_UI_UTIL_CopyPasteEndGet() - SEQ_UI_UTIL_CopyPasteBeginGet();
458
    break;
459
      case SEQ_UI_EDIT_MODE_SCROLL:
460
    step_region_begin = ui_selected_step;
461
    step_region_end = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
462
    break;
463
      default:
464
    step_region_begin = ui_selected_step;
465
    step_region_end = ui_selected_step;
466
    }
467
 
180 tk 468
    u8 step;
176 tk 469
    for(step=0; step<16; ++step) {
470
      // 9th step reached: switch to second LCD
471
      if( step == 8 ) {
472
    MIOS32_LCD_DeviceSet(1);
473
    MIOS32_LCD_CursorSet(0, 1);
474
      }
475
 
476
      u8 visible_step = step + 16*ui_selected_step_view;
240 tk 477
 
478
      if( ui_cursor_flash &&
479
      edit_mode != SEQ_UI_EDIT_MODE_NORMAL &&
480
      visible_step >= step_region_begin && visible_step <= step_region_end ) {
481
    SEQ_LCD_PrintSpaces(5);
482
    continue;
483
      }
484
 
176 tk 485
      seq_layer_evnt_t layer_event;
486
      SEQ_LAYER_GetEvntOfParLayer(visible_track, visible_step, ui_selected_par_layer, &layer_event);
487
 
488
      switch( layer_ctrl_type ) {
489
        case SEQ_LAYER_ControlType_Note:
490
        case SEQ_LAYER_ControlType_Velocity:
491
      if( layer_event.midi_package.note && layer_event.midi_package.velocity ) {
182 tk 492
        if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator )
493
          SEQ_LCD_PrintArp(layer_event.midi_package.note);
494
        else
495
          SEQ_LCD_PrintNote(layer_event.midi_package.note);
176 tk 496
        SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
497
      } else {
498
        MIOS32_LCD_PrintString("----");
499
      }
500
      break;
501
 
502
        case SEQ_LAYER_ControlType_Chord1:
178 tk 503
        case SEQ_LAYER_ControlType_Chord1_Velocity:
176 tk 504
      if( layer_event.midi_package.velocity ) {
178 tk 505
        MIOS32_LCD_PrintFormattedString("S%2d", (SEQ_PAR_Get(visible_track, step, 0) % SEQ_CORE_NUM_STEPS) + 1);
176 tk 506
        SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
507
      } else {
508
        MIOS32_LCD_PrintString("----");
509
      }
510
      break;
511
 
512
        case SEQ_LAYER_ControlType_Chord2:
178 tk 513
        case SEQ_LAYER_ControlType_Chord2_Velocity:
176 tk 514
      if( layer_event.midi_package.note && layer_event.midi_package.velocity ) {
515
        u8 par_value = SEQ_PAR_Get(visible_track, step, 0);
516
        u8 chord_ix = par_value & 0x0f;
517
        u8 chord_oct = par_value >> 4;
518
        MIOS32_LCD_PrintFormattedString("%d/%d", chord_ix, chord_oct);
519
        SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
520
      } else {
521
        MIOS32_LCD_PrintString("----");
522
      }
523
      break;
524
 
525
    //case SEQ_LAYER_ControlType_Lenght:
526
    //break;
527
    // extra handling -- see code above
528
 
529
        case SEQ_LAYER_ControlType_CC:
530
      MIOS32_LCD_PrintFormattedString("%3d", layer_event.midi_package.value);
531
      SEQ_LCD_PrintVBar(layer_event.midi_package.value >> 4);
532
      break;
533
 
534
        default:
535
      MIOS32_LCD_PrintString("????");
536
      break;
537
      }
538
 
240 tk 539
      MIOS32_LCD_PrintChar((visible_step == step_region_end) ? '<'
540
               : ((visible_step == (step_region_begin-1)) ? '>' : ' '));
541
 
176 tk 542
    }
167 tk 543
  }
544
 
545
  return 0; // no error
546
}
547
 
548
 
549
/////////////////////////////////////////////////////////////////////////////
240 tk 550
// Local Display Handler function
551
// IN: <high_prio>: if set, a high-priority LCD update is requested
552
/////////////////////////////////////////////////////////////////////////////
553
static s32 LCD_Handler(u8 high_prio)
554
{
555
  return SEQ_UI_EDIT_LCD_Handler(high_prio, SEQ_UI_EDIT_MODE_NORMAL);
556
}
557
 
558
 
559
/////////////////////////////////////////////////////////////////////////////
167 tk 560
// Initialisation
561
/////////////////////////////////////////////////////////////////////////////
562
s32 SEQ_UI_EDIT_Init(u32 mode)
563
{
564
  // install callback routines
168 tk 565
  SEQ_UI_InstallButtonCallback(Button_Handler);
566
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
240 tk 567
  SEQ_UI_InstallLEDCallback(SEQ_UI_EDIT_LED_Handler);
168 tk 568
  SEQ_UI_InstallLCDCallback(LCD_Handler);
167 tk 569
 
570
  return 0; // no error
571
}
178 tk 572
 
573
 
574
 
575
/////////////////////////////////////////////////////////////////////////////
576
// help function to change/set a single encoder value
577
// if forced_value >= 0: new value will be set to the given value
578
// if forced_value < 0: new value will be changed via incrementer
579
// returns >= 0 if new value has been set (value change)
580
// returns < 0 if no change
581
/////////////////////////////////////////////////////////////////////////////
582
static s32 ChangeSingleEncValue(u8 track, u8 step, s32 incrementer, s32 forced_value, u8 change_gate)
583
{
584
  seq_layer_ctrl_type_t layer_ctrl_type = SEQ_LAYER_GetVControlType(track, ui_selected_par_layer);
585
 
586
  // if not length or CC parameter: only change gate if requested
587
  if( layer_ctrl_type != SEQ_LAYER_ControlType_Length &&
588
      layer_ctrl_type != SEQ_LAYER_ControlType_CC &&
589
      !change_gate &&
590
      !SEQ_TRG_GateGet(track, step) )
591
    return -1;
592
 
593
  s32 old_value = SEQ_PAR_Get(track, step, ui_selected_par_layer);
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
 
604
  SEQ_PAR_Set(track, step, ui_selected_par_layer, (u8)new_value);
605
 
606
  if( layer_ctrl_type != SEQ_LAYER_ControlType_Length ) {
607
    // (de)activate gate depending on value
608
    if( new_value )
609
      SEQ_TRG_GateSet(track, step, 1);
610
    else
611
      SEQ_TRG_GateSet(track, step, 0);
612
  }
613
 
614
  return new_value;
615
}