Subversion Repositories svn.mios32

Rev

Rev 324 | Rev 326 | 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 325 2009-01-28 20:31:18Z 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 =
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;
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;
178 tk 141
    u8 new_value = SEQ_TRG_Get(visible_track, step, ui_selected_trg_layer) ? 0 : 1;
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)
178 tk 148
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, 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) {
178 tk 158
          u8 new_value = SEQ_TRG_Get(track, step, ui_selected_trg_layer) ? 0 : 1;
159
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, new_value);
160
        }
161
      }
162
    }
163
      }
164
    } else {
165
      // c) ALL function not active: toggle step
166
      u8 track;
167
      for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
168
    if( SEQ_UI_IsSelectedTrack(track) ) {
180 tk 169
      u8 new_value = SEQ_TRG_Get(track, ui_selected_step, ui_selected_trg_layer) ? 0 : 1;
170
      SEQ_TRG_Set(track, ui_selected_step, ui_selected_trg_layer, new_value);
178 tk 171
    }
172
      }
173
    }
168 tk 174
    return 1; // value always changed
178 tk 175
 
168 tk 176
  } else {
177
    switch( button ) {
178
      case SEQ_UI_BUTTON_Select:
303 tk 179
      case SEQ_UI_BUTTON_Right: {
180
    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 181
    if( next_step >= (SEQ_CC_Get(visible_track, SEQ_CC_LENGTH)+1) )
303 tk 182
      next_step = 0;
183
    ui_selected_step = next_step;
168 tk 184
    ui_selected_step_view = ui_selected_step / 16;
185
    return 1; // value always changed
303 tk 186
      } break;
167 tk 187
 
168 tk 188
      case SEQ_UI_BUTTON_Left:
189
    if( ui_selected_step == 0 )
306 tk 190
      ui_selected_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
168 tk 191
    ui_selected_step_view = ui_selected_step / 16;
192
    return 1; // value always changed
167 tk 193
 
168 tk 194
      case SEQ_UI_BUTTON_Up:
195
    return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
196
 
197
      case SEQ_UI_BUTTON_Down:
198
    return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
199
    }
167 tk 200
  }
201
 
168 tk 202
  return -1; // invalid or unsupported button
167 tk 203
}
204
 
205
 
206
/////////////////////////////////////////////////////////////////////////////
240 tk 207
// Global Display Handler function
167 tk 208
// IN: <high_prio>: if set, a high-priority LCD update is requested
240 tk 209
//     <edit_page>: selects the normal, or copy/paste/move/scroll view
167 tk 210
/////////////////////////////////////////////////////////////////////////////
240 tk 211
s32 SEQ_UI_EDIT_LCD_Handler(u8 high_prio, seq_ui_edit_mode_t edit_mode)
167 tk 212
{
213
  if( high_prio )
214
    return 0; // there are no high-priority updates
215
 
216
  u8 visible_track = SEQ_UI_VisibleTrackGet();
323 tk 217
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
167 tk 218
 
176 tk 219
  seq_layer_evnt_t layer_event;
323 tk 220
  SEQ_LAYER_GetEvntOfLayer(visible_track, ui_selected_step, ui_selected_par_layer, &layer_event);
168 tk 221
 
176 tk 222
 
167 tk 223
  ///////////////////////////////////////////////////////////////////////////
278 tk 224
  SEQ_LCD_CursorSet(0, 0);
167 tk 225
 
240 tk 226
  switch( edit_mode ) {
227
    case SEQ_UI_EDIT_MODE_COPY: {
228
      if( ui_cursor_flash ) {
229
    SEQ_LCD_PrintSpaces(15);
230
      } else {
231
    char str_buffer[10];
232
    sprintf(str_buffer, "%d-%d", SEQ_UI_UTIL_CopyPasteBeginGet()+1, SEQ_UI_UTIL_CopyPasteEndGet()+1);
278 tk 233
    SEQ_LCD_PrintFormattedString("COPY S%-9s", str_buffer);
240 tk 234
      }
235
    } break;
167 tk 236
 
240 tk 237
    case SEQ_UI_EDIT_MODE_PASTE: {
238
      if( ui_cursor_flash ) {
239
    SEQ_LCD_PrintSpaces(15);
240
      } else {
278 tk 241
    SEQ_LCD_PrintFormattedString("PASTE OFFS.%3d ", ui_selected_step+1);
240 tk 242
      }
243
    } break;
167 tk 244
 
240 tk 245
    case SEQ_UI_EDIT_MODE_MOVE: {
246
      if( ui_cursor_flash ) {
247
    SEQ_LCD_PrintSpaces(15);
248
      } else {
278 tk 249
    SEQ_LCD_PrintString("MOVE STEPS     ");
240 tk 250
      }
251
    } break;
176 tk 252
 
240 tk 253
    case SEQ_UI_EDIT_MODE_SCROLL: {
254
      if( ui_cursor_flash ) {
255
    SEQ_LCD_PrintSpaces(15);
256
      } else {
278 tk 257
    SEQ_LCD_PrintString("SCROLL TRACK   ");
240 tk 258
      }
259
    } break;
176 tk 260
 
240 tk 261
    case SEQ_UI_EDIT_MODE_RANDOM: {
262
      if( ui_cursor_flash ) {
263
    SEQ_LCD_PrintSpaces(15);
264
      } else {
278 tk 265
    SEQ_LCD_PrintString("RANDOMIZED     ");
240 tk 266
      }
267
    } break;
176 tk 268
 
240 tk 269
    case SEQ_UI_EDIT_MODE_RECORD: {
270
      if( ui_cursor_flash ) {
271
    SEQ_LCD_PrintSpaces(15);
272
      } else {
278 tk 273
    SEQ_LCD_PrintString("RECORDING MODE ");
240 tk 274
      }
275
    } break;
176 tk 276
 
240 tk 277
    default: {
278
      SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
279
      SEQ_LCD_PrintSpaces(2);
176 tk 280
 
278 tk 281
      SEQ_LCD_PrintChar('A' + ui_selected_par_layer);
282
      SEQ_LCD_PrintChar(':');
176 tk 283
 
240 tk 284
      switch( SEQ_LAYER_GetVControlType(visible_track, ui_selected_par_layer) ) {
285
        case SEQ_LAYER_ControlType_Note:
278 tk 286
      SEQ_LCD_PrintString("Note   ");
240 tk 287
      break;
288
 
289
        case SEQ_LAYER_ControlType_Velocity:
323 tk 290
        case SEQ_LAYER_ControlType_Chord_Velocity:
278 tk 291
          SEQ_LCD_PrintString("Vel.   ");
240 tk 292
          break;
293
 
323 tk 294
        case SEQ_LAYER_ControlType_Chord:
295
          SEQ_LCD_PrintString("Chord  ");
240 tk 296
          break;
297
 
298
        case SEQ_LAYER_ControlType_Length:
278 tk 299
          SEQ_LCD_PrintString("Length ");
240 tk 300
          break;
301
 
302
        case SEQ_LAYER_ControlType_CC:
278 tk 303
          SEQ_LCD_PrintFormattedString("CC#%3d ", layer_event.midi_package.cc_number);
240 tk 304
          break;
305
 
306
        default:
278 tk 307
          SEQ_LCD_PrintString("???    ");
240 tk 308
          break;
309
      }
310
    }
176 tk 311
  }
240 tk 312
 
278 tk 313
  SEQ_LCD_PrintFormattedString("Chn%2d", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
314
  SEQ_LCD_PrintChar('/');
285 tk 315
  SEQ_LCD_PrintMIDIOutPort(SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT));
167 tk 316
  SEQ_LCD_PrintSpaces(1);
317
 
325 tk 318
  SEQ_LCD_PrintFormattedString("%c:%s", 'A' + ui_selected_trg_layer, SEQ_TRG_AssignedTypeStr(visible_track, ui_selected_trg_layer));
278 tk 319
  SEQ_LCD_PrintChar(' ');
167 tk 320
 
321
  SEQ_LCD_PrintStepView(ui_selected_step_view);
322
 
323
 
324
  ///////////////////////////////////////////////////////////////////////////
288 tk 325
  seq_layer_ctrl_type_t layer_ctrl_type = SEQ_LAYER_GetVControlType(visible_track, ui_selected_par_layer);
326
 
327
  ///////////////////////////////////////////////////////////////////////////
278 tk 328
  SEQ_LCD_CursorSet(40, 0);
167 tk 329
 
278 tk 330
  SEQ_LCD_PrintFormattedString("Step");
167 tk 331
  SEQ_LCD_PrintSelectedStep(ui_selected_step, 15);
278 tk 332
  SEQ_LCD_PrintChar(':');
167 tk 333
 
176 tk 334
  if( layer_event.midi_package.event == CC ) {
278 tk 335
    SEQ_LCD_PrintFormattedString("CC#%3d %3d",
176 tk 336
                    layer_event.midi_package.cc_number,
337
                    layer_event.midi_package.value);
338
    SEQ_LCD_PrintVBar(layer_event.midi_package.value >> 4);
339
  } else {
178 tk 340
    if( layer_event.midi_package.note && layer_event.midi_package.velocity && (layer_event.len >= 0) ) {
288 tk 341
      if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator ) {
182 tk 342
    SEQ_LCD_PrintArp(layer_event.midi_package.note);
323 tk 343
      } else if( layer_ctrl_type == SEQ_LAYER_ControlType_Chord ||
344
           layer_ctrl_type == SEQ_LAYER_ControlType_Chord_Velocity ) {
288 tk 345
    u8 par_value = SEQ_PAR_Get(visible_track, ui_selected_step, 0);
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);
167 tk 363
  SEQ_LCD_PrintSpaces(1);
364
 
180 tk 365
  int i;
366
  const char trg_chars[8] = "gsagrgv";
367
  for(i=0; i<7; ++i) {
368
    u8 trg_layer;
369
    if( !(trg_layer=SEQ_TRG_AssignmentGet(visible_track, i)) )
278 tk 370
      SEQ_LCD_PrintChar('-');
180 tk 371
    else
278 tk 372
      SEQ_LCD_PrintChar(SEQ_TRG_Get(visible_track, ui_selected_step, trg_layer-1) ? (trg_chars[i]-32) : trg_chars[i]);
180 tk 373
  }
167 tk 374
 
180 tk 375
 
167 tk 376
  ///////////////////////////////////////////////////////////////////////////
377
 
176 tk 378
  // extra handling for gatelength (shows vertical bars)
379
  if( layer_ctrl_type == SEQ_LAYER_ControlType_Length ) {
167 tk 380
 
176 tk 381
    // we want to show horizontal bars
382
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_HBars);
167 tk 383
 
176 tk 384
    // initial cursor position
278 tk 385
    SEQ_LCD_CursorSet(0, 1);
167 tk 386
 
176 tk 387
    // determine length of previous step (depends on selected view and track length)
388
    int previous_step = 16*ui_selected_step_view - 1;
389
    if( previous_step < 0 )
390
      previous_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
391
 
392
    seq_layer_evnt_t layer_event;
323 tk 393
    SEQ_LAYER_GetEvntOfLayer(visible_track, previous_step, ui_selected_par_layer, &layer_event);
176 tk 394
    u16 previous_length = layer_event.len;
395
    u8 previous_step_was_long_multi = 0; // hard to determine here... TODO
396
 
397
    // show length of 16 steps
180 tk 398
    u8 step;
176 tk 399
    for(step=0; step<16; ++step) {
400
      u8 visible_step = step + 16*ui_selected_step_view;
323 tk 401
      SEQ_LAYER_GetEvntOfLayer(visible_track, visible_step, ui_selected_par_layer, &layer_event);
176 tk 402
 
178 tk 403
      if( previous_step_was_long_multi || layer_event.len >= 32 ) { // multi note trigger?
176 tk 404
    if( !previous_step_was_long_multi ) {
178 tk 405
      if( previous_length <= 24 && !layer_event.midi_package.velocity ) {
176 tk 406
        SEQ_LCD_PrintSpaces(5);
407
        previous_length = 0;
408
      } else {
409
        SEQ_LCD_PrintGatelength(layer_event.len);
278 tk 410
        SEQ_LCD_PrintChar(layer_event.midi_package.velocity ? ' ' : '?'); // notify about multi-triggered events 
176 tk 411
        // with gate=0 and previous length >= 24 - we don't know how the core will react here
412
 
413
        // calculate total length of events -> previous_length
178 tk 414
        previous_length = (layer_event.len>>5) * (layer_event.len & 0x1f);
415
        // long event if >= 24
416
        previous_step_was_long_multi = previous_length >= 24;
176 tk 417
      }
167 tk 418
    } else {
176 tk 419
      // continued long event
420
      // previous step took 24 steps
421
      previous_length -= 24;
178 tk 422
      // print warning (!!!) if current step activated and overlapped by long multi trigger
176 tk 423
      if( previous_step_was_long_multi && !layer_event.midi_package.velocity )
278 tk 424
        SEQ_LCD_PrintString(">>>> ");
178 tk 425
      else
278 tk 426
        SEQ_LCD_PrintString("!!!! ");
178 tk 427
      // still long event if >= 24
428
      previous_step_was_long_multi = previous_length >= 24;
167 tk 429
    }
176 tk 430
      } else {
431
    previous_step_was_long_multi = 0;
178 tk 432
    // muted step? if previous gatelength <= 24, print spaces
433
    if( !layer_event.midi_package.velocity && previous_length <= 24 ) {
176 tk 434
      SEQ_LCD_PrintSpaces(5);
435
    } else {
178 tk 436
      if( layer_event.len >= 24 )
176 tk 437
        SEQ_LCD_PrintHBar(15); // glide
438
      else
439
        SEQ_LCD_PrintHBar((layer_event.len-1) >> 1);
440
    }
178 tk 441
    previous_length = (layer_event.midi_package.velocity || (previous_length > 24 && layer_event.len > 24)) ? layer_event.len : 0;
176 tk 442
      }
167 tk 443
    }
444
 
176 tk 445
  } else {
446
 
323 tk 447
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
448
      // we want to show triggers
325 tk 449
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_DrumSymbolsBig);
323 tk 450
    } else {
451
      // we want to show vertical bars
452
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
453
    }
176 tk 454
 
455
    // initial cursor position
278 tk 456
    SEQ_LCD_CursorSet(0, 1);
176 tk 457
 
323 tk 458
    int step_region_begin;
459
    int step_region_end;
240 tk 460
    switch( edit_mode ) {
461
      case SEQ_UI_EDIT_MODE_COPY:
462
    step_region_begin = SEQ_UI_UTIL_CopyPasteBeginGet();
463
    step_region_end = SEQ_UI_UTIL_CopyPasteEndGet();
464
    break;
465
      case SEQ_UI_EDIT_MODE_PASTE:
466
    step_region_begin = ui_selected_step;
467
    step_region_end = ui_selected_step + SEQ_UI_UTIL_CopyPasteEndGet() - SEQ_UI_UTIL_CopyPasteBeginGet();
468
    break;
469
      case SEQ_UI_EDIT_MODE_SCROLL:
470
    step_region_begin = ui_selected_step;
471
    step_region_end = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
472
    break;
473
      default:
323 tk 474
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
475
      step_region_begin = -1;
476
      step_region_end = -1;
477
    } else {
478
      step_region_begin = ui_selected_step;
479
      step_region_end = ui_selected_step;
480
    }
240 tk 481
    }
482
 
180 tk 483
    u8 step;
176 tk 484
    for(step=0; step<16; ++step) {
485
      u8 visible_step = step + 16*ui_selected_step_view;
240 tk 486
 
487
      if( ui_cursor_flash &&
488
      edit_mode != SEQ_UI_EDIT_MODE_NORMAL &&
489
      visible_step >= step_region_begin && visible_step <= step_region_end ) {
490
    SEQ_LCD_PrintSpaces(5);
491
    continue;
492
      }
493
 
176 tk 494
      seq_layer_evnt_t layer_event;
323 tk 495
      SEQ_LAYER_GetEvntOfLayer(visible_track, visible_step, ui_selected_par_layer, &layer_event);
176 tk 496
 
323 tk 497
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
498
    u8 gate = SEQ_TRG_Get(visible_track, step, ui_selected_trg_layer);
324 tk 499
    u8 accent_available = SEQ_TRG_AssignmentGet(visible_track, 1);
500
    u8 accent = accent_available ? SEQ_TRG_Get(visible_track, step, ui_selected_trg_layer + 16) : 0;
323 tk 501
 
502
    SEQ_LCD_PrintChar(' ');
503
    SEQ_LCD_PrintChar(' ');
324 tk 504
    // TODO: show accent flag if available with character 4/5
325 tk 505
    SEQ_LCD_PrintChar(gate ? 0x01 : 0x00);
323 tk 506
    SEQ_LCD_PrintChar(' ');
507
    SEQ_LCD_PrintChar(' ');
508
      } else {
509
    switch( layer_ctrl_type ) {
510
          case SEQ_LAYER_ControlType_Note:
511
          case SEQ_LAYER_ControlType_Velocity:
512
        if( layer_event.midi_package.note && layer_event.midi_package.velocity ) {
513
          if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator )
514
        SEQ_LCD_PrintArp(layer_event.midi_package.note);
515
          else
516
        SEQ_LCD_PrintNote(layer_event.midi_package.note);
517
          SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
518
        } else {
519
          SEQ_LCD_PrintString("----");
520
        }
521
        break;
522
 
523
          case SEQ_LAYER_ControlType_Chord:
524
          case SEQ_LAYER_ControlType_Chord_Velocity:
525
        if( layer_event.midi_package.note && layer_event.midi_package.velocity ) {
526
          u8 par_value = SEQ_PAR_Get(visible_track, step, 0);
527
          u8 chord_ix = par_value & 0x0f;
528
          u8 chord_oct = par_value >> 4;
529
          SEQ_LCD_PrintFormattedString("%X/%d", chord_ix, chord_oct);
530
          SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
531
        } else {
532
          SEQ_LCD_PrintString("----");
533
        }
534
        break;
176 tk 535
 
323 tk 536
      //case SEQ_LAYER_ControlType_Length:
537
      //break;
538
      // extra handling -- see code above
176 tk 539
 
323 tk 540
          case SEQ_LAYER_ControlType_CC:
541
        SEQ_LCD_PrintFormattedString("%3d", layer_event.midi_package.value);
542
        SEQ_LCD_PrintVBar(layer_event.midi_package.value >> 4);
543
        break;
176 tk 544
 
323 tk 545
          default:
546
        SEQ_LCD_PrintString("????");
547
        break;
548
    }
176 tk 549
      }
550
 
323 tk 551
      if( step_region_begin != -1 && step_region_end != -1 ) {
552
    SEQ_LCD_PrintChar((visible_step == step_region_end) ? '<'
553
              : ((visible_step == (step_region_begin-1)) ? '>' : ' '));
554
      }
240 tk 555
 
176 tk 556
    }
167 tk 557
  }
558
 
559
  return 0; // no error
560
}
561
 
562
 
563
/////////////////////////////////////////////////////////////////////////////
240 tk 564
// Local Display Handler function
565
// IN: <high_prio>: if set, a high-priority LCD update is requested
566
/////////////////////////////////////////////////////////////////////////////
567
static s32 LCD_Handler(u8 high_prio)
568
{
569
  return SEQ_UI_EDIT_LCD_Handler(high_prio, SEQ_UI_EDIT_MODE_NORMAL);
570
}
571
 
572
 
573
/////////////////////////////////////////////////////////////////////////////
167 tk 574
// Initialisation
575
/////////////////////////////////////////////////////////////////////////////
576
s32 SEQ_UI_EDIT_Init(u32 mode)
577
{
578
  // install callback routines
168 tk 579
  SEQ_UI_InstallButtonCallback(Button_Handler);
580
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
240 tk 581
  SEQ_UI_InstallLEDCallback(SEQ_UI_EDIT_LED_Handler);
168 tk 582
  SEQ_UI_InstallLCDCallback(LCD_Handler);
167 tk 583
 
584
  return 0; // no error
585
}
178 tk 586
 
587
 
588
 
589
/////////////////////////////////////////////////////////////////////////////
590
// help function to change/set a single encoder value
591
// if forced_value >= 0: new value will be set to the given value
592
// if forced_value < 0: new value will be changed via incrementer
593
// returns >= 0 if new value has been set (value change)
594
// returns < 0 if no change
595
/////////////////////////////////////////////////////////////////////////////
318 tk 596
static s32 ChangeSingleEncValue(u8 track, u16 step, s32 incrementer, s32 forced_value, u8 change_gate)
178 tk 597
{
598
  seq_layer_ctrl_type_t layer_ctrl_type = SEQ_LAYER_GetVControlType(track, ui_selected_par_layer);
599
 
600
  // if not length or CC parameter: only change gate if requested
601
  if( layer_ctrl_type != SEQ_LAYER_ControlType_Length &&
602
      layer_ctrl_type != SEQ_LAYER_ControlType_CC &&
603
      !change_gate &&
604
      !SEQ_TRG_GateGet(track, step) )
605
    return -1;
606
 
607
  s32 old_value = SEQ_PAR_Get(track, step, ui_selected_par_layer);
608
  s32 new_value = (forced_value >= 0) ? forced_value : (old_value + incrementer);
609
  if( new_value < 0 )
610
    new_value = 0;
611
  else if( new_value >= 128 )
612
    new_value = 127;
613
 
614
  // take over if changed
615
  if( new_value == old_value )
616
    return -1;
617
 
618
  SEQ_PAR_Set(track, step, ui_selected_par_layer, (u8)new_value);
619
 
306 tk 620
  if( layer_ctrl_type != SEQ_LAYER_ControlType_Length && layer_ctrl_type != SEQ_LAYER_ControlType_CC ) {
178 tk 621
    // (de)activate gate depending on value
622
    if( new_value )
623
      SEQ_TRG_GateSet(track, step, 1);
624
    else
625
      SEQ_TRG_GateSet(track, step, 0);
626
  }
627
 
628
  return new_value;
629
}