Subversion Repositories svn.mios32

Rev

Rev 327 | Rev 330 | 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 328 2009-01-30 21:21:05Z tk $
2
/*
3
 * Edit page
4
 *
5
 * ==========================================================================
6
 *
7
 *  Copyright (C) 2008 Thorsten Klose (tk@midibox.org)
8
 *  Licensed for personal non-commercial use only.
9
 *  All other rights reserved.
10
 *
11
 * ==========================================================================
12
 */
13
 
14
/////////////////////////////////////////////////////////////////////////////
15
// Include files
16
/////////////////////////////////////////////////////////////////////////////
17
 
18
#include <mios32.h>
19
#include "seq_lcd.h"
20
#include "seq_ui.h"
21
 
22
#include "seq_core.h"
168 tk 23
#include "seq_cc.h"
176 tk 24
#include "seq_layer.h"
167 tk 25
#include "seq_par.h"
26
#include "seq_trg.h"
27
 
28
 
29
/////////////////////////////////////////////////////////////////////////////
178 tk 30
// Local prototypes
31
/////////////////////////////////////////////////////////////////////////////
32
 
318 tk 33
static s32 ChangeSingleEncValue(u8 track, u16 step, s32 incrementer, s32 forced_value, u8 change_gate);
178 tk 34
 
35
 
36
/////////////////////////////////////////////////////////////////////////////
240 tk 37
// LED handler function (globally accessible, since it's re-used by UTIL page)
167 tk 38
/////////////////////////////////////////////////////////////////////////////
240 tk 39
s32 SEQ_UI_EDIT_LED_Handler(u16 *gp_leds)
167 tk 40
{
41
  u8 visible_track = SEQ_UI_VisibleTrackGet();
42
 
43
  *gp_leds =
328 tk 44
    (SEQ_TRG_Get8(visible_track, 2*ui_selected_step_view+1, ui_selected_trg_layer, ui_selected_instrument) << 8) |
45
    (SEQ_TRG_Get8(visible_track, 2*ui_selected_step_view+0, ui_selected_trg_layer, ui_selected_instrument) << 0);
167 tk 46
 
47
  return 0; // no error
48
}
49
 
50
 
51
/////////////////////////////////////////////////////////////////////////////
168 tk 52
// Local encoder callback function
53
// Should return:
54
//   1 if value has been changed
55
//   0 if value hasn't been changed
56
//  -1 if invalid or unsupported encoder
167 tk 57
/////////////////////////////////////////////////////////////////////////////
168 tk 58
static s32 Encoder_Handler(seq_ui_encoder_t encoder, s32 incrementer)
167 tk 59
{
168 tk 60
#if 0
61
  // leads to: comparison is always true due to limited range of data type
62
  if( (encoder >= SEQ_UI_ENCODER_GP1 && encoder <= SEQ_UI_ENCODER_GP16) || encoder == SEQ_UI_ENCODER_Datawheel ) {
63
#else
64
  if( encoder <= SEQ_UI_ENCODER_GP16 || encoder == SEQ_UI_ENCODER_Datawheel ) {
65
#endif
178 tk 66
    ui_selected_step = ((encoder == SEQ_UI_ENCODER_Datawheel) ? (ui_selected_step%16) : encoder) + ui_selected_step_view*16;
167 tk 67
 
182 tk 68
    u8 visible_track = SEQ_UI_VisibleTrackGet();
69
 
178 tk 70
    s32 value_changed = 0;
71
    s32 forced_value = -1;
72
    u8  change_gate = 1;
168 tk 73
 
182 tk 74
    // due to historical reasons (from old times where MBSEQ CS was stuffed with pots): 
75
    // in arp mode, we increment in steps of 4
76
    if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator &&
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;
328 tk 141
    u8 new_value = SEQ_TRG_Get(visible_track, step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
178 tk 142
 
143
    u8 track;
144
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
318 tk 145
      if( SEQ_UI_IsSelectedTrack(track) ) {
146
        u16 num_steps = SEQ_TRG_NumStepsGet(track);
147
        for(step=0; step<num_steps; ++step)
328 tk 148
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, ui_selected_instrument, new_value);
318 tk 149
      }
178 tk 150
      } else {
151
    // a) ALL function active, but ALL button not pressed: invert complete trigger layer
303 tk 152
    u8 track;
153
    u16 step;
178 tk 154
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
155
      if( SEQ_UI_IsSelectedTrack(track) ) {
318 tk 156
        u16 num_steps = SEQ_TRG_NumStepsGet(track);
157
        for(step=0; step<num_steps; ++step) {
328 tk 158
          u8 new_value = SEQ_TRG_Get(track, step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
159
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, ui_selected_instrument, new_value);
178 tk 160
        }
161
      }
162
    }
163
      }
164
    } else {
165
      // c) ALL function not active: toggle step
166
      u8 track;
167
      for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
168
    if( SEQ_UI_IsSelectedTrack(track) ) {
328 tk 169
      u8 new_value = SEQ_TRG_Get(track, ui_selected_step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
170
      SEQ_TRG_Set(track, ui_selected_step, ui_selected_trg_layer, ui_selected_instrument, 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
 
328 tk 342
  SEQ_LCD_PrintFormattedString("T%c:%s", 'A' + ui_selected_trg_layer, SEQ_TRG_AssignedTypeStr(visible_track, ui_selected_trg_layer));
327 tk 343
 
344
 
167 tk 345
  ///////////////////////////////////////////////////////////////////////////
278 tk 346
  SEQ_LCD_CursorSet(40, 0);
167 tk 347
 
326 tk 348
  SEQ_LCD_PrintFormattedString("Step%3d   ", ui_selected_step+1);
167 tk 349
 
176 tk 350
  if( layer_event.midi_package.event == CC ) {
278 tk 351
    SEQ_LCD_PrintFormattedString("CC#%3d %3d",
176 tk 352
                    layer_event.midi_package.cc_number,
353
                    layer_event.midi_package.value);
354
    SEQ_LCD_PrintVBar(layer_event.midi_package.value >> 4);
355
  } else {
178 tk 356
    if( layer_event.midi_package.note && layer_event.midi_package.velocity && (layer_event.len >= 0) ) {
288 tk 357
      if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator ) {
182 tk 358
    SEQ_LCD_PrintArp(layer_event.midi_package.note);
323 tk 359
      } else if( layer_ctrl_type == SEQ_LAYER_ControlType_Chord ||
360
           layer_ctrl_type == SEQ_LAYER_ControlType_Chord_Velocity ) {
328 tk 361
    u8 par_value = SEQ_PAR_Get(visible_track, ui_selected_step, 0, ui_selected_instrument);
288 tk 362
    u8 chord_ix = par_value & 0x0f;
363
    u8 chord_oct = par_value >> 4;
364
    SEQ_LCD_PrintString(SEQ_CHORD_NameGet(chord_ix));
365
    SEQ_LCD_PrintFormattedString("/%d", chord_oct);
366
      } else {
182 tk 367
    SEQ_LCD_PrintNote(layer_event.midi_package.note);
288 tk 368
      }
176 tk 369
      SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
370
    }
371
    else {
278 tk 372
      SEQ_LCD_PrintString("....");
176 tk 373
    }
278 tk 374
    SEQ_LCD_PrintFormattedString(" Vel:%3d", layer_event.midi_package.velocity);
176 tk 375
  }
167 tk 376
 
278 tk 377
  SEQ_LCD_PrintString(" Len:");
176 tk 378
  SEQ_LCD_PrintGatelength(layer_event.len);
326 tk 379
  SEQ_LCD_PrintSpaces(4);
167 tk 380
 
326 tk 381
  if( event_mode == SEQ_EVENT_MODE_Drum ) {
328 tk 382
    SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
326 tk 383
  } else {
384
    SEQ_LCD_PrintTrackCategory(visible_track, (char *)seq_core_trk[visible_track].name);
180 tk 385
  }
167 tk 386
 
387
  ///////////////////////////////////////////////////////////////////////////
388
 
176 tk 389
  // extra handling for gatelength (shows vertical bars)
390
  if( layer_ctrl_type == SEQ_LAYER_ControlType_Length ) {
167 tk 391
 
176 tk 392
    // we want to show horizontal bars
393
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_HBars);
167 tk 394
 
176 tk 395
    // initial cursor position
278 tk 396
    SEQ_LCD_CursorSet(0, 1);
167 tk 397
 
176 tk 398
    // determine length of previous step (depends on selected view and track length)
399
    int previous_step = 16*ui_selected_step_view - 1;
400
    if( previous_step < 0 )
401
      previous_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
402
 
403
    seq_layer_evnt_t layer_event;
323 tk 404
    SEQ_LAYER_GetEvntOfLayer(visible_track, previous_step, ui_selected_par_layer, &layer_event);
176 tk 405
    u16 previous_length = layer_event.len;
406
    u8 previous_step_was_long_multi = 0; // hard to determine here... TODO
407
 
408
    // show length of 16 steps
180 tk 409
    u8 step;
176 tk 410
    for(step=0; step<16; ++step) {
411
      u8 visible_step = step + 16*ui_selected_step_view;
323 tk 412
      SEQ_LAYER_GetEvntOfLayer(visible_track, visible_step, ui_selected_par_layer, &layer_event);
176 tk 413
 
178 tk 414
      if( previous_step_was_long_multi || layer_event.len >= 32 ) { // multi note trigger?
176 tk 415
    if( !previous_step_was_long_multi ) {
178 tk 416
      if( previous_length <= 24 && !layer_event.midi_package.velocity ) {
176 tk 417
        SEQ_LCD_PrintSpaces(5);
418
        previous_length = 0;
419
      } else {
420
        SEQ_LCD_PrintGatelength(layer_event.len);
278 tk 421
        SEQ_LCD_PrintChar(layer_event.midi_package.velocity ? ' ' : '?'); // notify about multi-triggered events 
176 tk 422
        // with gate=0 and previous length >= 24 - we don't know how the core will react here
423
 
424
        // calculate total length of events -> previous_length
178 tk 425
        previous_length = (layer_event.len>>5) * (layer_event.len & 0x1f);
426
        // long event if >= 24
427
        previous_step_was_long_multi = previous_length >= 24;
176 tk 428
      }
167 tk 429
    } else {
176 tk 430
      // continued long event
431
      // previous step took 24 steps
432
      previous_length -= 24;
178 tk 433
      // print warning (!!!) if current step activated and overlapped by long multi trigger
176 tk 434
      if( previous_step_was_long_multi && !layer_event.midi_package.velocity )
278 tk 435
        SEQ_LCD_PrintString(">>>> ");
178 tk 436
      else
278 tk 437
        SEQ_LCD_PrintString("!!!! ");
178 tk 438
      // still long event if >= 24
439
      previous_step_was_long_multi = previous_length >= 24;
167 tk 440
    }
176 tk 441
      } else {
442
    previous_step_was_long_multi = 0;
178 tk 443
    // muted step? if previous gatelength <= 24, print spaces
444
    if( !layer_event.midi_package.velocity && previous_length <= 24 ) {
176 tk 445
      SEQ_LCD_PrintSpaces(5);
446
    } else {
178 tk 447
      if( layer_event.len >= 24 )
176 tk 448
        SEQ_LCD_PrintHBar(15); // glide
449
      else
450
        SEQ_LCD_PrintHBar((layer_event.len-1) >> 1);
451
    }
178 tk 452
    previous_length = (layer_event.midi_package.velocity || (previous_length > 24 && layer_event.len > 24)) ? layer_event.len : 0;
176 tk 453
      }
167 tk 454
    }
455
 
176 tk 456
  } else {
457
 
323 tk 458
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
459
      // we want to show triggers
325 tk 460
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_DrumSymbolsBig);
323 tk 461
    } else {
462
      // we want to show vertical bars
463
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
464
    }
176 tk 465
 
466
    // initial cursor position
278 tk 467
    SEQ_LCD_CursorSet(0, 1);
176 tk 468
 
323 tk 469
    int step_region_begin;
470
    int step_region_end;
240 tk 471
    switch( edit_mode ) {
472
      case SEQ_UI_EDIT_MODE_COPY:
473
    step_region_begin = SEQ_UI_UTIL_CopyPasteBeginGet();
474
    step_region_end = SEQ_UI_UTIL_CopyPasteEndGet();
475
    break;
476
      case SEQ_UI_EDIT_MODE_PASTE:
477
    step_region_begin = ui_selected_step;
478
    step_region_end = ui_selected_step + SEQ_UI_UTIL_CopyPasteEndGet() - SEQ_UI_UTIL_CopyPasteBeginGet();
479
    break;
480
      case SEQ_UI_EDIT_MODE_SCROLL:
481
    step_region_begin = ui_selected_step;
482
    step_region_end = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
483
    break;
484
      default:
323 tk 485
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
486
      step_region_begin = -1;
487
      step_region_end = -1;
488
    } else {
489
      step_region_begin = ui_selected_step;
490
      step_region_end = ui_selected_step;
491
    }
240 tk 492
    }
493
 
180 tk 494
    u8 step;
176 tk 495
    for(step=0; step<16; ++step) {
496
      u8 visible_step = step + 16*ui_selected_step_view;
240 tk 497
 
498
      if( ui_cursor_flash &&
499
      edit_mode != SEQ_UI_EDIT_MODE_NORMAL &&
500
      visible_step >= step_region_begin && visible_step <= step_region_end ) {
501
    SEQ_LCD_PrintSpaces(5);
502
    continue;
503
      }
504
 
176 tk 505
      seq_layer_evnt_t layer_event;
323 tk 506
      SEQ_LAYER_GetEvntOfLayer(visible_track, visible_step, ui_selected_par_layer, &layer_event);
176 tk 507
 
323 tk 508
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
328 tk 509
    u8 gate_accent = SEQ_TRG_Get(visible_track, step + 16*ui_selected_step_view, 0, ui_selected_instrument);
510
    if( SEQ_TRG_NumLayersGet(visible_track) >= 2 )
511
      gate_accent |= SEQ_TRG_Get(visible_track, step + 16*ui_selected_step_view, 1, ui_selected_instrument) << 1;
323 tk 512
    SEQ_LCD_PrintChar(' ');
513
    SEQ_LCD_PrintChar(' ');
327 tk 514
    SEQ_LCD_PrintChar(gate_accent);
323 tk 515
    SEQ_LCD_PrintChar(' ');
516
    SEQ_LCD_PrintChar(' ');
517
      } else {
518
    switch( layer_ctrl_type ) {
519
          case SEQ_LAYER_ControlType_Note:
520
          case SEQ_LAYER_ControlType_Velocity:
521
        if( layer_event.midi_package.note && layer_event.midi_package.velocity ) {
522
          if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator )
523
        SEQ_LCD_PrintArp(layer_event.midi_package.note);
524
          else
525
        SEQ_LCD_PrintNote(layer_event.midi_package.note);
526
          SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
527
        } else {
528
          SEQ_LCD_PrintString("----");
529
        }
530
        break;
531
 
532
          case SEQ_LAYER_ControlType_Chord:
533
          case SEQ_LAYER_ControlType_Chord_Velocity:
534
        if( layer_event.midi_package.note && layer_event.midi_package.velocity ) {
328 tk 535
          u8 par_value = SEQ_PAR_Get(visible_track, step, 0, ui_selected_instrument);
323 tk 536
          u8 chord_ix = par_value & 0x0f;
537
          u8 chord_oct = par_value >> 4;
538
          SEQ_LCD_PrintFormattedString("%X/%d", chord_ix, chord_oct);
539
          SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
540
        } else {
541
          SEQ_LCD_PrintString("----");
542
        }
543
        break;
176 tk 544
 
323 tk 545
      //case SEQ_LAYER_ControlType_Length:
546
      //break;
547
      // extra handling -- see code above
176 tk 548
 
323 tk 549
          case SEQ_LAYER_ControlType_CC:
550
        SEQ_LCD_PrintFormattedString("%3d", layer_event.midi_package.value);
551
        SEQ_LCD_PrintVBar(layer_event.midi_package.value >> 4);
552
        break;
176 tk 553
 
323 tk 554
          default:
555
        SEQ_LCD_PrintString("????");
556
        break;
557
    }
176 tk 558
      }
559
 
323 tk 560
      if( step_region_begin != -1 && step_region_end != -1 ) {
561
    SEQ_LCD_PrintChar((visible_step == step_region_end) ? '<'
562
              : ((visible_step == (step_region_begin-1)) ? '>' : ' '));
563
      }
240 tk 564
 
176 tk 565
    }
167 tk 566
  }
567
 
568
  return 0; // no error
569
}
570
 
571
 
572
/////////////////////////////////////////////////////////////////////////////
240 tk 573
// Local Display Handler function
574
// IN: <high_prio>: if set, a high-priority LCD update is requested
575
/////////////////////////////////////////////////////////////////////////////
576
static s32 LCD_Handler(u8 high_prio)
577
{
578
  return SEQ_UI_EDIT_LCD_Handler(high_prio, SEQ_UI_EDIT_MODE_NORMAL);
579
}
580
 
581
 
582
/////////////////////////////////////////////////////////////////////////////
167 tk 583
// Initialisation
584
/////////////////////////////////////////////////////////////////////////////
585
s32 SEQ_UI_EDIT_Init(u32 mode)
586
{
587
  // install callback routines
168 tk 588
  SEQ_UI_InstallButtonCallback(Button_Handler);
589
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
240 tk 590
  SEQ_UI_InstallLEDCallback(SEQ_UI_EDIT_LED_Handler);
168 tk 591
  SEQ_UI_InstallLCDCallback(LCD_Handler);
167 tk 592
 
593
  return 0; // no error
594
}
178 tk 595
 
596
 
597
 
598
/////////////////////////////////////////////////////////////////////////////
599
// help function to change/set a single encoder value
600
// if forced_value >= 0: new value will be set to the given value
601
// if forced_value < 0: new value will be changed via incrementer
602
// returns >= 0 if new value has been set (value change)
603
// returns < 0 if no change
604
/////////////////////////////////////////////////////////////////////////////
318 tk 605
static s32 ChangeSingleEncValue(u8 track, u16 step, s32 incrementer, s32 forced_value, u8 change_gate)
178 tk 606
{
607
  seq_layer_ctrl_type_t layer_ctrl_type = SEQ_LAYER_GetVControlType(track, ui_selected_par_layer);
608
 
609
  // if not length or CC parameter: only change gate if requested
610
  if( layer_ctrl_type != SEQ_LAYER_ControlType_Length &&
611
      layer_ctrl_type != SEQ_LAYER_ControlType_CC &&
612
      !change_gate &&
328 tk 613
      !SEQ_TRG_GateGet(track, step, ui_selected_instrument) )
178 tk 614
    return -1;
615
 
328 tk 616
  s32 old_value = SEQ_PAR_Get(track, step, ui_selected_par_layer, ui_selected_instrument);
178 tk 617
  s32 new_value = (forced_value >= 0) ? forced_value : (old_value + incrementer);
618
  if( new_value < 0 )
619
    new_value = 0;
620
  else if( new_value >= 128 )
621
    new_value = 127;
622
 
623
  // take over if changed
624
  if( new_value == old_value )
625
    return -1;
626
 
328 tk 627
  SEQ_PAR_Set(track, step, ui_selected_par_layer, ui_selected_instrument, (u8)new_value);
178 tk 628
 
306 tk 629
  if( layer_ctrl_type != SEQ_LAYER_ControlType_Length && layer_ctrl_type != SEQ_LAYER_ControlType_CC ) {
178 tk 630
    // (de)activate gate depending on value
631
    if( new_value )
328 tk 632
      SEQ_TRG_GateSet(track, step, ui_selected_instrument, 1);
178 tk 633
    else
328 tk 634
      SEQ_TRG_GateSet(track, step, ui_selected_instrument, 0);
178 tk 635
  }
636
 
637
  return new_value;
638
}