Subversion Repositories svn.mios32

Rev

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