Subversion Repositories svn.mios32

Rev

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