Subversion Repositories svn.mios32

Rev

Rev 1351 | Rev 1751 | 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 1483 2012-07-01 17:54:40Z 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"
741 tk 24
#include "seq_cc_labels.h"
176 tk 25
#include "seq_layer.h"
167 tk 26
#include "seq_par.h"
27
#include "seq_trg.h"
690 tk 28
#include "seq_chord.h"
1349 tk 29
#include "seq_record.h"
600 tk 30
#include "seq_hwcfg.h"
167 tk 31
 
32
 
33
/////////////////////////////////////////////////////////////////////////////
1203 tk 34
// Global Variables
1142 tk 35
/////////////////////////////////////////////////////////////////////////////
1203 tk 36
seq_ui_edit_view_t seq_ui_edit_view = SEQ_UI_EDIT_VIEW_STEPS;
1142 tk 37
 
1203 tk 38
 
1142 tk 39
/////////////////////////////////////////////////////////////////////////////
1348 tk 40
// Global Defines
41
/////////////////////////////////////////////////////////////////////////////
42
#define DATAWHEEL_MODE_SCROLL_CURSOR   0
43
#define DATAWHEEL_MODE_SCROLL_VIEW     1
44
#define DATAWHEEL_MODE_CHANGE_VALUE    2
45
#define DATAWHEEL_MODE_CHANGE_PARLAYER 3
46
#define DATAWHEEL_MODE_CHANGE_TRGLAYER 4
47
 
48
#define DATAWHEEL_MODE_NUM             5
49
 
50
 
51
/////////////////////////////////////////////////////////////////////////////
729 tk 52
// Local Variables
53
/////////////////////////////////////////////////////////////////////////////
54
 
1142 tk 55
static u8 show_edit_config_page;
56
 
729 tk 57
static u16 selected_steps = 0xffff; // will only be initialized once after startup
58
 
1348 tk 59
static u8 datawheel_mode = 0; // will only be initialized once after startup
1211 tk 60
 
1350 tk 61
// activated by pressing EDIT button: encoder value will be taken over by releasing EDIT button
62
// mode 0: function not active (EDIT button released)
63
// mode 1: function activated (EDIT button pressed)
64
// mode 2: value has been changed while EDIT button pressed (a message will pop up on screen)
65
static u8 edit_passive_mode;
66
static u8 edit_passive_value;      // the tmp. edited value
67
static u8 edit_passive_track;      // to store the track of the edit value
68
static u8 edit_passive_step;       // to store the step of the edit value
69
static u8 edit_passive_par_layer;  // to store the layer of the edit value
70
static u8 edit_passive_instrument; // to store the instrument of the edit value
1348 tk 71
 
729 tk 72
/////////////////////////////////////////////////////////////////////////////
178 tk 73
// Local prototypes
74
/////////////////////////////////////////////////////////////////////////////
75
 
747 tk 76
static s32 ChangeSingleEncValue(u8 track, u16 par_step, u16 trg_step, s32 incrementer, s32 forced_value, u8 change_gate, u8 dont_change_gate);
1350 tk 77
static s32 PassiveEditEnter(void);
78
static s32 PassiveEditValid(void);
79
static s32 PassiveEditTakeOver(void);
178 tk 80
 
81
 
82
/////////////////////////////////////////////////////////////////////////////
240 tk 83
// LED handler function (globally accessible, since it's re-used by UTIL page)
167 tk 84
/////////////////////////////////////////////////////////////////////////////
240 tk 85
s32 SEQ_UI_EDIT_LED_Handler(u16 *gp_leds)
167 tk 86
{
87
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1142 tk 88
 
89
  if( show_edit_config_page ) {
90
    switch( seq_ui_edit_view ) {
91
    case SEQ_UI_EDIT_VIEW_STEPS: *gp_leds = (1 << 0); break;
92
    case SEQ_UI_EDIT_VIEW_TRG: *gp_leds = (1 << 1); break;
93
    case SEQ_UI_EDIT_VIEW_LAYERS: *gp_leds = (1 << 2); break;
94
    case SEQ_UI_EDIT_VIEW_303: *gp_leds = (1 << 3); break;
95
    case SEQ_UI_EDIT_VIEW_STEPSEL: *gp_leds = (1 << 8); break;
96
    }
97
  } else {
167 tk 98
 
1142 tk 99
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
100
      *gp_leds = selected_steps;
101
    } else {
167 tk 102
 
1142 tk 103
      u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
104
 
105
      if( event_mode != SEQ_EVENT_MODE_Drum &&
106
      (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_303) ) {
107
 
108
    if( SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) )
109
      *gp_leds |= (1 << 1);
110
    if( SEQ_TRG_AccentGet(visible_track, ui_selected_step, ui_selected_instrument) )
111
      *gp_leds |= (1 << 2);
112
    if( SEQ_TRG_GlideGet(visible_track, ui_selected_step, ui_selected_instrument) )
113
      *gp_leds |= (1 << 3);
114
 
115
    if( ui_selected_par_layer == 0 )
116
      *gp_leds |= (3 << 4);
117
    else
118
      *gp_leds |= (1 << (ui_selected_par_layer+5));
119
 
120
      } else if( event_mode != SEQ_EVENT_MODE_Drum &&
121
      (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_LAYERS || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG) ) {
122
 
123
    u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
124
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
125
      // maximum 7 parameter layers due to "Step" item!
126
      if( num_t_layers >= 7 )
127
        num_t_layers = 7;
128
    } else {
129
      // single trigger layer (gate)
130
      num_t_layers = 1;
131
    }
132
 
133
    int i;
134
    for(i=0; i<num_t_layers; ++i)
135
      if( SEQ_TRG_Get(visible_track, ui_selected_step, i, ui_selected_instrument) )
136
        *gp_leds |= (1 << (i+1));
137
 
138
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
139
      *gp_leds |= (1 << (ui_selected_par_layer+8));
140
    } else {
141
      *gp_leds |= (1 << (ui_selected_par_layer+2));
142
    }
143
      } else {
144
    *gp_leds =
145
      (SEQ_TRG_Get8(visible_track, 2*ui_selected_step_view+1, ui_selected_trg_layer, ui_selected_instrument) << 8) |
146
      (SEQ_TRG_Get8(visible_track, 2*ui_selected_step_view+0, ui_selected_trg_layer, ui_selected_instrument) << 0);
147
      }
148
    }
149
  }
150
 
167 tk 151
  return 0; // no error
152
}
153
 
154
 
155
/////////////////////////////////////////////////////////////////////////////
168 tk 156
// Local encoder callback function
157
// Should return:
158
//   1 if value has been changed
159
//   0 if value hasn't been changed
160
//  -1 if invalid or unsupported encoder
167 tk 161
/////////////////////////////////////////////////////////////////////////////
168 tk 162
static s32 Encoder_Handler(seq_ui_encoder_t encoder, s32 incrementer)
167 tk 163
{
1348 tk 164
  u8 visible_track = SEQ_UI_VisibleTrackGet();
165
 
166
  if( encoder == SEQ_UI_ENCODER_Datawheel ) {
167
    u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
168
 
169
    switch( datawheel_mode ) {
170
    case DATAWHEEL_MODE_SCROLL_CURSOR:
171
      // note: SEQ_UI_CheckSelections() will automatically change the page if required
172
      if( SEQ_UI_Var8_Inc(&ui_selected_step, 0, num_steps-1, incrementer) >= 1 )
173
    return 1;
174
      else
175
    return 0;
176
 
177
    case DATAWHEEL_MODE_SCROLL_VIEW:
178
      if( SEQ_UI_Var8_Inc(&ui_selected_step_view, 0, (num_steps-1)/16, incrementer) >= 1 ) {
179
    // select step within view
180
    ui_selected_step = (ui_selected_step_view << 4) | (ui_selected_step & 0xf);
181
    return 1;
182
      } else {
183
    return 0;
184
      }
185
 
186
    case DATAWHEEL_MODE_CHANGE_VALUE:
187
      break; // drop... continue below with common encoder value change routine
188
 
189
    case DATAWHEEL_MODE_CHANGE_PARLAYER: {
190
      u8 num_layers = SEQ_PAR_NumLayersGet(visible_track);
191
 
192
      if( SEQ_UI_Var8_Inc(&ui_selected_par_layer, 0, num_layers-1, incrementer) >= 1 )
193
    return 1;
194
      else
195
    return 0;
196
    } break;
197
 
198
    case DATAWHEEL_MODE_CHANGE_TRGLAYER: {
199
      u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
200
 
201
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
202
    u8 num_layers = SEQ_TRG_NumInstrumentsGet(visible_track);
203
    if( SEQ_UI_Var8_Inc(&ui_selected_instrument, 0, num_layers-1, incrementer) >= 1 )
204
      return 1;
205
    else
206
      return 0;
207
      } else {
208
    u8 num_layers = SEQ_TRG_NumLayersGet(visible_track);
209
    if( SEQ_UI_Var8_Inc(&ui_selected_trg_layer, 0, num_layers-1, incrementer) >= 1 )
210
      return 1;
211
    else
212
      return 0;
213
      }
214
    } break;
215
    }
216
  }
217
 
168 tk 218
#if 0
219
  // leads to: comparison is always true due to limited range of data type
220
  if( (encoder >= SEQ_UI_ENCODER_GP1 && encoder <= SEQ_UI_ENCODER_GP16) || encoder == SEQ_UI_ENCODER_Datawheel ) {
221
#else
222
  if( encoder <= SEQ_UI_ENCODER_GP16 || encoder == SEQ_UI_ENCODER_Datawheel ) {
223
#endif
1142 tk 224
 
225
    if( show_edit_config_page ) {
226
      switch( encoder ) {
227
      case SEQ_UI_ENCODER_GP1: seq_ui_edit_view = SEQ_UI_EDIT_VIEW_STEPS; break;
228
      case SEQ_UI_ENCODER_GP2: seq_ui_edit_view = SEQ_UI_EDIT_VIEW_TRG; break;
229
      case SEQ_UI_ENCODER_GP3: seq_ui_edit_view = SEQ_UI_EDIT_VIEW_LAYERS; break;
230
      case SEQ_UI_ENCODER_GP4: seq_ui_edit_view = SEQ_UI_EDIT_VIEW_303; break;
1483 tk 231
      case SEQ_UI_ENCODER_GP8: seq_ui_edit_view = SEQ_UI_EDIT_VIEW_STEPSEL; break;
1348 tk 232
 
1483 tk 233
      case SEQ_UI_ENCODER_GP9:
234
      case SEQ_UI_ENCODER_GP10: {
1348 tk 235
    if( incrementer == 0 ) // button
236
      incrementer = (encoder == SEQ_UI_ENCODER_GP7) ? -1 : 1;
237
 
238
    if( SEQ_UI_Var8_Inc(&datawheel_mode, 0, DATAWHEEL_MODE_NUM-1, incrementer) >= 1 )
239
      return 1;
240
    else
241
      return 0;
1142 tk 242
      }
1483 tk 243
 
244
      case SEQ_UI_ENCODER_GP13:
245
      case SEQ_UI_ENCODER_GP14:
246
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRKRND);
247
    break;
248
 
249
      case SEQ_UI_ENCODER_GP15:
250
      case SEQ_UI_ENCODER_GP16:
251
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRKEUCLID);
252
    break;
1348 tk 253
      }
254
 
1142 tk 255
      show_edit_config_page = 0; // switch back to view
256
      return 1; // value changed
257
    }
258
 
259
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
729 tk 260
      if( incrementer > 0 )
261
    selected_steps |= (1 << encoder);
262
      else
263
    selected_steps &= ~(1 << encoder);
264
      return 1; // value changed
265
    }
266
 
1142 tk 267
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
182 tk 268
 
1142 tk 269
    if( event_mode != SEQ_EVENT_MODE_Drum &&
270
    (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_303) ) {
271
      u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
272
 
273
      if( encoder == SEQ_UI_ENCODER_GP1 ) {
1348 tk 274
    if( SEQ_UI_Var8_Inc(&ui_selected_step, 0, num_steps-1, incrementer) >= 1 )
1142 tk 275
      return 1;
276
    else
277
      return 0;
278
      } else if( encoder == SEQ_UI_ENCODER_GP2 ) {
279
    SEQ_TRG_GateSet(visible_track, ui_selected_step, ui_selected_instrument, incrementer > 0 ? 1 : 0);
280
    return 1;
281
      } else if( encoder == SEQ_UI_ENCODER_GP3 ) {
282
    SEQ_TRG_AccentSet(visible_track, ui_selected_step, ui_selected_instrument, incrementer > 0 ? 1 : 0);
283
    return 1;
284
      } else if( encoder == SEQ_UI_ENCODER_GP4 ) {
285
    SEQ_TRG_GlideSet(visible_track, ui_selected_step, ui_selected_instrument, incrementer > 0 ? 1 : 0);
286
    return 1;
287
      } else if( encoder == SEQ_UI_ENCODER_GP5 ) {
288
    ui_selected_par_layer = 0;
289
    u8 note = SEQ_PAR_Get(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument);
290
    u8 note_octave = note / 12;
291
    u8 note_key = note % 12;
292
 
293
    if( SEQ_UI_Var8_Inc(&note_octave, 0, 9, incrementer) >= 1 ) {
294
      SEQ_PAR_Set(visible_track, ui_selected_step, 0, ui_selected_instrument, 12*note_octave + note_key);
295
      return 1;
296
    }
297
    return 0;
298
      } else if( encoder == SEQ_UI_ENCODER_GP6 ) {
299
    ui_selected_par_layer = 0;
300
    u8 note = SEQ_PAR_Get(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument);
301
    u8 note_octave = note / 12;
302
    u8 note_key = note % 12;
303
 
304
    if( SEQ_UI_Var8_Inc(&note_key, 0, 11, incrementer) >= 1 ) {
305
      SEQ_PAR_Set(visible_track, ui_selected_step, 0, ui_selected_instrument, 12*note_octave + note_key);
306
      return 1;
307
    }
308
    return 0;
309
      } else if( encoder <= SEQ_UI_ENCODER_GP16 ) {
310
    u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
311
    if( ((int)encoder-5) >= num_p_layers )
312
        return 0; // ignore
313
      ui_selected_par_layer = encoder-5;
314
      }
315
 
316
      if( !incrementer ) // button selection only...
317
    return 1;
318
    }
319
 
320
    if( event_mode != SEQ_EVENT_MODE_Drum &&
321
      (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_LAYERS || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG) ) {
322
      u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
323
 
324
      if( encoder == SEQ_UI_ENCODER_GP1 ) {
1348 tk 325
    if( SEQ_UI_Var8_Inc(&ui_selected_step, 0, num_steps-1, incrementer) >= 1 )
1142 tk 326
      return 1;
327
    else
328
      return 0;
329
      } else if( encoder == SEQ_UI_ENCODER_GP2 ||
330
         (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG && encoder <= SEQ_UI_ENCODER_GP8) ) {
331
    u8 sel = (u8)encoder-1;
332
    SEQ_TRG_Set(visible_track, ui_selected_step, sel, ui_selected_instrument, incrementer > 0 ? 1 : 0);
333
    return 1;
334
      } else if( encoder <= SEQ_UI_ENCODER_GP16 ) {
335
 
336
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
337
      if( encoder <= SEQ_UI_ENCODER_GP8 ) {
338
        u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
339
        if( ((int)encoder-2) >= num_t_layers )
340
          return 0; // ignore
341
        ui_selected_trg_layer = encoder-2;
342
      } else {
343
        u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
344
        if( ((int)encoder-8) >= num_p_layers )
345
          return 0; // ignore
346
        ui_selected_par_layer = encoder-8;
347
      }
348
    } else {
349
      u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
350
      if( ((int)encoder-2) >= num_p_layers )
351
        return 0; // ignore
352
      ui_selected_par_layer = encoder-2;
353
    }
354
 
355
    if( !incrementer ) // button selection only...
356
      return 1;
357
      }
358
    }
359
 
1350 tk 360
    if( event_mode == SEQ_EVENT_MODE_Drum || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPS ) {
361
      u8 new_step = ((encoder == SEQ_UI_ENCODER_Datawheel) ? (ui_selected_step%16) : encoder) + ui_selected_step_view*16;
1142 tk 362
 
1350 tk 363
      // in passive edit mode: take over the edit value if step has changed, thereafter switch to new step
1351 tk 364
      if( ui_selected_step != new_step && edit_passive_mode ) {
1350 tk 365
    PassiveEditTakeOver();
366
    ui_selected_step = new_step;
367
    PassiveEditEnter();
368
      } else {
369
    ui_selected_step = new_step;
370
      }
371
 
372
    }
373
 
374
 
375
    // in passive edit mode: change value, but don't take over yet!
376
    if( edit_passive_mode ) {
377
      if( SEQ_UI_Var8_Inc(&edit_passive_value, 0, 127, incrementer) >= 1 ) {
378
    edit_passive_mode = 2; // value has been changed
379
    return 1;
380
      } else
381
    return 0;
382
    }
383
 
384
    // normal edit mode
178 tk 385
    s32 value_changed = 0;
386
    s32 forced_value = -1;
387
    u8  change_gate = 1;
168 tk 388
 
182 tk 389
    // due to historical reasons (from old times where MBSEQ CS was stuffed with pots): 
390
    // in arp mode, we increment in steps of 4
1143 tk 391
    u8 par_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
182 tk 392
    if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator &&
1143 tk 393
    par_type == SEQ_PAR_Type_Note )
182 tk 394
      incrementer *= 4;
395
 
178 tk 396
    // first change the selected value
397
    if( seq_ui_button_state.CHANGE_ALL_STEPS && seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
652 tk 398
      u16 num_steps = SEQ_PAR_NumStepsGet(visible_track);
399
      u16 par_step = ui_selected_step;
400
      u16 trg_step = ui_selected_step;
401
 
402
      // mirrored layer in drum mode?
403
      u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
404
      if( event_mode == SEQ_EVENT_MODE_Drum && par_step >= num_steps )
405
    par_step %= num_steps;
406
 
747 tk 407
      forced_value = ChangeSingleEncValue(visible_track, par_step, trg_step, incrementer, forced_value, change_gate, 0);
178 tk 408
      if( forced_value < 0 )
409
    return 0; // no change
410
      value_changed |= 1;
168 tk 411
    }
412
 
178 tk 413
    // change value of all selected steps
414
    u8 track;
415
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
416
      if( SEQ_UI_IsSelectedTrack(track) ) {
318 tk 417
    u16 num_steps = SEQ_PAR_NumStepsGet(track);
652 tk 418
    u16 trg_step = (ui_selected_step & ~(num_steps-1));
1142 tk 419
 
652 tk 420
    u16 par_step;
421
    for(par_step=0; par_step<num_steps; ++par_step, ++trg_step) {
729 tk 422
      if( !seq_ui_button_state.CHANGE_ALL_STEPS || par_step == ui_selected_step || (selected_steps & (1 << (par_step % 16))) ) {
423
        change_gate = trg_step == ui_selected_step;
747 tk 424
        u8 dont_change_gate = par_step != ui_selected_step;
729 tk 425
        if( change_gate || seq_ui_button_state.CHANGE_ALL_STEPS ) {
747 tk 426
          if( ChangeSingleEncValue(track, par_step, trg_step, incrementer, forced_value, change_gate, dont_change_gate) >= 0 )
729 tk 427
        value_changed |= 1;
428
        }
178 tk 429
      }
430
    }
431
      }
176 tk 432
    }
1142 tk 433
 
178 tk 434
    return value_changed;
168 tk 435
  }
436
 
437
  return -1; // invalid or unsupported encoder
167 tk 438
}
439
 
440
 
441
/////////////////////////////////////////////////////////////////////////////
168 tk 442
// Local button callback function
443
// Should return:
444
//   1 if value has been changed
445
//   0 if value hasn't been changed
446
//  -1 if invalid or unsupported button
167 tk 447
/////////////////////////////////////////////////////////////////////////////
758 tk 448
s32 SEQ_UI_EDIT_Button_Handler(seq_ui_button_t button, s32 depressed)
167 tk 449
{
306 tk 450
  u8 visible_track = SEQ_UI_VisibleTrackGet();
451
 
168 tk 452
#if 0
453
  // leads to: comparison is always true due to limited range of data type
454
  if( button >= SEQ_UI_BUTTON_GP1 && button <= SEQ_UI_BUTTON_GP16 ) {
455
#else
456
  if( button <= SEQ_UI_BUTTON_GP16 ) {
457
#endif
729 tk 458
    if( depressed ) return 0; // ignore when button depressed
459
 
1142 tk 460
    if( show_edit_config_page )
461
      return Encoder_Handler(button, 0);
462
 
463
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
729 tk 464
      selected_steps ^= (1 << button);
465
      return 1; // value changed
466
    }
467
 
1142 tk 468
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
469
 
470
    if( event_mode != SEQ_EVENT_MODE_Drum &&
471
    (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_303) ) {
472
 
473
      if( button == SEQ_UI_BUTTON_GP1 ) {
474
    int next_step = ui_selected_step + 1; // (required, since ui_selected_step is only u8, but we could have up to 256 steps)
475
    if( next_step >= (SEQ_CC_Get(visible_track, SEQ_CC_LENGTH)+1) )
476
      next_step = 0;
477
    ui_selected_step = next_step;
478
    ui_selected_step_view = ui_selected_step / 16;
479
    return 1; // value always changed
480
      } else if( button == SEQ_UI_BUTTON_GP2 ) {
481
    u8 trg = SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument);
482
    return Encoder_Handler(button, trg ? -1 : 1);
483
      } else if( button == SEQ_UI_BUTTON_GP3 ) {
484
    u8 trg = SEQ_TRG_AccentGet(visible_track, ui_selected_step, ui_selected_instrument);
485
    return Encoder_Handler(button, trg ? -1 : 1);
486
      } else if( button == SEQ_UI_BUTTON_GP4 ) {
487
    u8 trg = SEQ_TRG_GlideGet(visible_track, ui_selected_step, ui_selected_instrument);
488
    return Encoder_Handler(button, trg ? -1 : 1);
489
      } else if( button <= SEQ_UI_BUTTON_GP16 ) {
490
    return Encoder_Handler(button, 0);
491
      }
492
    }
493
 
494
 
495
    if( event_mode != SEQ_EVENT_MODE_Drum &&
496
      (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_LAYERS || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG) ) {
497
 
498
      if( button == SEQ_UI_BUTTON_GP1 ) {
499
    int next_step = ui_selected_step + 1; // (required, since ui_selected_step is only u8, but we could have up to 256 steps)
500
    if( next_step >= (SEQ_CC_Get(visible_track, SEQ_CC_LENGTH)+1) )
501
      next_step = 0;
502
    ui_selected_step = next_step;
503
    ui_selected_step_view = ui_selected_step / 16;
504
    return 1; // value always changed
505
      } else if( button == SEQ_UI_BUTTON_GP2 ||
506
         (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG && button <= SEQ_UI_BUTTON_GP8) ) {
507
    u8 trg = SEQ_TRG_Get(visible_track, ui_selected_step, (u8)button-1, ui_selected_instrument);
508
    return Encoder_Handler(button, trg ? -1 : 1);
509
      } else if( button <= SEQ_UI_BUTTON_GP16 ) {
510
    return Encoder_Handler(button, 0);
511
      }
512
    }
513
 
180 tk 514
    ui_selected_step = button + ui_selected_step_view*16;
1142 tk 515
 
168 tk 516
    // toggle trigger layer
600 tk 517
    // if seq_hwcfg_button_beh.all_with_triggers set, we've three cases:
178 tk 518
    // a) ALL function active, but ALL button not pressed: invert complete trigger layer
519
    // b) ALL function active and ALL button pressed: toggle step, set remaining steps to same new value
520
    // c) ALL function not active: toggle step
600 tk 521
    if( seq_hwcfg_button_beh.all_with_triggers && seq_ui_button_state.CHANGE_ALL_STEPS ) {
178 tk 522
      if( seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
523
    // b) ALL function active and ALL button pressed: toggle step, set remaining steps to same new value
303 tk 524
    u16 step = ui_selected_step;
328 tk 525
    u8 new_value = SEQ_TRG_Get(visible_track, step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
1142 tk 526
 
178 tk 527
    u8 track;
528
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
318 tk 529
      if( SEQ_UI_IsSelectedTrack(track) ) {
530
        u16 num_steps = SEQ_TRG_NumStepsGet(track);
531
        for(step=0; step<num_steps; ++step)
328 tk 532
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, ui_selected_instrument, new_value);
318 tk 533
      }
178 tk 534
      } else {
535
    // a) ALL function active, but ALL button not pressed: invert complete trigger layer
303 tk 536
    u8 track;
537
    u16 step;
178 tk 538
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
539
      if( SEQ_UI_IsSelectedTrack(track) ) {
318 tk 540
        u16 num_steps = SEQ_TRG_NumStepsGet(track);
541
        for(step=0; step<num_steps; ++step) {
328 tk 542
          u8 new_value = SEQ_TRG_Get(track, step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
543
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, ui_selected_instrument, new_value);
178 tk 544
        }
545
      }
546
    }
547
      }
548
    } else {
549
      // c) ALL function not active: toggle step
550
      u8 track;
1142 tk 551
 
484 tk 552
      u8 new_value = SEQ_TRG_Get(visible_track, ui_selected_step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
178 tk 553
      for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
554
    if( SEQ_UI_IsSelectedTrack(track) ) {
328 tk 555
      SEQ_TRG_Set(track, ui_selected_step, ui_selected_trg_layer, ui_selected_instrument, new_value);
178 tk 556
    }
557
      }
558
    }
1142 tk 559
 
168 tk 560
    return 1; // value always changed
178 tk 561
 
168 tk 562
  } else {
563
    switch( button ) {
564
      case SEQ_UI_BUTTON_Select:
1142 tk 565
    show_edit_config_page = depressed ? 0 : 1;
729 tk 566
    return 1; // value always changed
567
 
303 tk 568
      case SEQ_UI_BUTTON_Right: {
729 tk 569
    if( depressed ) return 0; // ignore when button depressed
570
 
303 tk 571
    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 572
    if( next_step >= (SEQ_CC_Get(visible_track, SEQ_CC_LENGTH)+1) )
303 tk 573
      next_step = 0;
574
    ui_selected_step = next_step;
168 tk 575
    ui_selected_step_view = ui_selected_step / 16;
576
    return 1; // value always changed
303 tk 577
      } break;
167 tk 578
 
168 tk 579
      case SEQ_UI_BUTTON_Left:
729 tk 580
    if( depressed ) return 0; // ignore when button depressed
581
 
168 tk 582
    if( ui_selected_step == 0 )
306 tk 583
      ui_selected_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
1142 tk 584
    else
585
      --ui_selected_step;
586
 
168 tk 587
    ui_selected_step_view = ui_selected_step / 16;
588
    return 1; // value always changed
167 tk 589
 
168 tk 590
      case SEQ_UI_BUTTON_Up:
729 tk 591
    if( depressed ) return 0; // ignore when button depressed
168 tk 592
    return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
593
 
594
      case SEQ_UI_BUTTON_Down:
729 tk 595
    if( depressed ) return 0; // ignore when button depressed
168 tk 596
    return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
1350 tk 597
 
598
      // this button is currently only notified to EDIT page
599
      case SEQ_UI_BUTTON_Edit:
600
    if( !depressed )
601
      PassiveEditEnter();
1351 tk 602
    else {
1350 tk 603
      PassiveEditTakeOver();
1351 tk 604
      edit_passive_mode = 0;
605
    }
1350 tk 606
    return 1;
168 tk 607
    }
167 tk 608
  }
609
 
168 tk 610
  return -1; // invalid or unsupported button
167 tk 611
}
612
 
613
 
614
/////////////////////////////////////////////////////////////////////////////
240 tk 615
// Global Display Handler function
167 tk 616
// IN: <high_prio>: if set, a high-priority LCD update is requested
240 tk 617
//     <edit_page>: selects the normal, or copy/paste/move/scroll view
167 tk 618
/////////////////////////////////////////////////////////////////////////////
240 tk 619
s32 SEQ_UI_EDIT_LCD_Handler(u8 high_prio, seq_ui_edit_mode_t edit_mode)
167 tk 620
{
621
  if( high_prio )
622
    return 0; // there are no high-priority updates
623
 
326 tk 624
 
625
  // layout common track:
626
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
627
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
628
  // G1T1 xxxxxxxxxxxxxxx  PC:Length TA:Gate Step  1   G#1_ Vel:127_Len: 75%    xxxxx
629
  // ....
630
 
631
  // layout drum track:
632
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
633
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
634
  // G1T1 xxxxxxxxxxxxxxx  PA:Vel.   TA:Gate Step  1   G#1_ Vel:127_Len: 75%    xxxxx
635
  // ....
636
 
1142 tk 637
  // layout edit config
638
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
1483 tk 639
  // Step Trg  Layer 303                Step Datawheel:           Random    Euclid   
640
  // View View View View               Select Scroll             Generator Generator 
1142 tk 641
 
642
  // layout trigger view
643
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
644
  // Step Gate Acc. Roll Glide Skip R.G  R.V Note Vel. Len. Roll Note Note Note Note 
645
  //   1    *    o    o    o    o    o    o  C-3  100   75% ---- E-3  G-3  ---- ---- 
646
 
647
  // layout layer view
648
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
649
  // Step Gate Note Vel. Len. Roll Note Note Note Note Note Note Note Note Note Note 
650
  //   1    *  C-3  100   75% ---- E-3  G-3  ---- ---- ---- ---- ---- ---- ---- ---- 
651
 
652
  // layout 303 view
653
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
654
  // Step Gate Acc. Glide Oct, Key Vel. Prob  CC   CC   CC   CC   CC   CC   CC   CC  
655
  //   1    *   o     o    3    C  100  100%  64   64   64   64   64   64   64   64  
656
 
729 tk 657
  // layout step selection:
658
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
659
  //        Select the steps which should be  controlled by the ALL function:        
660
  //   *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *  
326 tk 661
 
1142 tk 662
  if( show_edit_config_page ) {
1348 tk 663
    const char datawheel_mode_str[DATAWHEEL_MODE_NUM][11] = {
664
      " Cursor   ",
665
      " StepView ",
666
      " Value    ",
667
      " ParLayer ",
668
      " TrgLayer ",
669
    };
670
 
1142 tk 671
    SEQ_LCD_CursorSet(0, 0);
1483 tk 672
    SEQ_LCD_PrintString("Step Trg  Layer 303                Step Datawheel:           Random    Euclid   ");
1142 tk 673
    SEQ_LCD_CursorSet(0, 1);
1483 tk 674
    SEQ_LCD_PrintString("View View View View               Select");
1348 tk 675
    SEQ_LCD_PrintString((char *)datawheel_mode_str[datawheel_mode]);
1483 tk 676
    SEQ_LCD_PrintString("          Generator Generator ");
1142 tk 677
    return 0; // no error
678
  }
679
 
680
  if( !edit_mode && seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
729 tk 681
    int step;
682
 
683
    SEQ_LCD_CursorSet(0, 0);
684
    SEQ_LCD_PrintString("       Select the steps which should be  controlled by the ALL function:        ");
685
    SEQ_LCD_CursorSet(0, 1);
686
    for(step=0; step<16; ++step)
687
      SEQ_LCD_PrintFormattedString("  %c  ", (selected_steps & (1 << step)) ? '*' : 'o');
688
    return 0; // no error
689
  }
690
 
691
 
167 tk 692
  u8 visible_track = SEQ_UI_VisibleTrackGet();
323 tk 693
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
167 tk 694
 
1142 tk 695
 
1316 tk 696
  if( !edit_mode && event_mode != SEQ_EVENT_MODE_Drum &&
1142 tk 697
      (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_303) ) {
698
    // we want to show vertical bars
699
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
700
 
701
    u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
702
    // maximum 10 parameter layers
703
    if( num_p_layers >= 11 )
704
      num_p_layers = 11;
705
 
706
    ///////////////////////////////////////////////////////////////////////////
707
    SEQ_LCD_CursorSet(0, 0);
708
    SEQ_LCD_PrintString("Step Gate Acc. Glide Oct. Key ");
709
    int i;
710
    for(i=1; i<num_p_layers; ++i)
711
    SEQ_LCD_PrintString((char *)SEQ_PAR_AssignedTypeStr(visible_track, i));
712
 
713
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
714
 
715
    ///////////////////////////////////////////////////////////////////////////
716
    SEQ_LCD_CursorSet(0, 1);
717
    SEQ_LCD_PrintFormattedString("%3d  ", ui_selected_step+1);
718
    SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? '*' : 'o');
719
    SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_AccentGet(visible_track, ui_selected_step, ui_selected_instrument) ? '*' : 'o');
720
    SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_GlideGet(visible_track, ui_selected_step, ui_selected_instrument) ? '*' : 'o');
721
 
1351 tk 722
    u8 note = SEQ_PAR_Get(visible_track, ui_selected_step, 0, ui_selected_instrument);
1142 tk 723
    u8 note_octave = note / 12;
724
    u8 note_key = note % 12;
725
 
726
    SEQ_LCD_PrintFormattedString(" %2d  ", (int)note_octave-2);
727
    const char note_tab[12][2] = { "C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B " };
728
    SEQ_LCD_PrintFormattedString("  %c%c ", note_tab[note_key][0], note_tab[note_key][1]);
729
 
730
    for(i=1; i<num_p_layers; ++i)
731
      if( i == ui_selected_par_layer && ui_cursor_flash )
732
    SEQ_LCD_PrintSpaces(5);
733
      else {
1351 tk 734
    int print_edit_value = PassiveEditValid() ? edit_passive_value : -1;
735
    SEQ_LCD_PrintLayerEvent(visible_track, ui_selected_step, i, ui_selected_instrument, 0, print_edit_value);
1142 tk 736
    SEQ_LCD_PrintChar(' ');
737
      }
738
 
739
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
740
 
741
    return 0;
742
  }
743
 
1316 tk 744
  if( !edit_mode && event_mode != SEQ_EVENT_MODE_Drum &&
1142 tk 745
      (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_LAYERS || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG) ) {
746
 
747
    // we want to show vertical bars
748
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
749
 
750
    u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
751
    u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
752
 
753
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
754
      // maximum 7 parameter layers due to "Step" item!
755
      if( num_t_layers >= 7 )
756
    num_t_layers = 7;
757
 
758
      // maximum 8 parameter layers
759
      if( num_p_layers >= 8 )
760
    num_p_layers = 8;
761
    } else {
762
      // single trigger layer (gate)
763
      num_t_layers = 1;
764
 
765
      // maximum 14 parameter layers due to "Step" and "Gate" item!
766
      if( num_p_layers >= 14 )
767
    num_p_layers = 14;
768
    }
769
 
770
    ///////////////////////////////////////////////////////////////////////////
771
    SEQ_LCD_CursorSet(0, 0);
772
    SEQ_LCD_PrintString("Step ");
773
    int i;
774
    for(i=0; i<num_t_layers; ++i)
775
    SEQ_LCD_PrintString(SEQ_TRG_AssignedTypeStr(visible_track, i));
776
    for(i=0; i<num_p_layers; ++i)
777
    SEQ_LCD_PrintString((char *)SEQ_PAR_AssignedTypeStr(visible_track, i));
778
 
779
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
780
 
781
    ///////////////////////////////////////////////////////////////////////////
782
    SEQ_LCD_CursorSet(0, 1);
783
    SEQ_LCD_PrintFormattedString("%3d  ", ui_selected_step+1);
784
    for(i=0; i<num_t_layers; ++i)
785
      SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_Get(visible_track, ui_selected_step, i, ui_selected_instrument) ? '*' : 'o');
786
    for(i=0; i<num_p_layers; ++i)
787
      if( i == ui_selected_par_layer && ui_cursor_flash )
788
    SEQ_LCD_PrintSpaces(5);
789
      else {
1351 tk 790
    int print_edit_value = PassiveEditValid() ? edit_passive_value : -1;
791
    SEQ_LCD_PrintLayerEvent(visible_track, ui_selected_step, i, ui_selected_instrument, 0, print_edit_value);
1142 tk 792
    SEQ_LCD_PrintChar(' ');
793
      }
794
 
795
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
796
 
797
    return 0;
798
  }
799
 
176 tk 800
  seq_layer_evnt_t layer_event;
336 tk 801
  SEQ_LAYER_GetEvntOfLayer(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
168 tk 802
 
333 tk 803
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
176 tk 804
 
333 tk 805
  // TODO: tmp. solution to print chord velocity correctly
806
  if( layer_type == SEQ_PAR_Type_Velocity && (seq_cc_trk[visible_track].link_par_layer_chord == 0) )
807
    layer_type = SEQ_PAR_Type_Chord;
326 tk 808
 
333 tk 809
 
167 tk 810
  ///////////////////////////////////////////////////////////////////////////
278 tk 811
  SEQ_LCD_CursorSet(0, 0);
167 tk 812
 
326 tk 813
  SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
814
  SEQ_LCD_PrintSpaces(1);
815
 
1349 tk 816
 
1350 tk 817
  if( ui_page == SEQ_UI_PAGE_EDIT && edit_passive_mode == 2 ) {
1349 tk 818
    if( ui_cursor_flash ) {
819
      SEQ_LCD_PrintSpaces(15);
820
    } else {
1350 tk 821
      SEQ_LCD_PrintString("PASSIVE EDITING");
822
    }
823
  } else if( seq_record_state.ENABLED || edit_mode == SEQ_UI_EDIT_MODE_RECORD ) {
824
    if( ui_cursor_flash ) {
825
      SEQ_LCD_PrintSpaces(15);
826
    } else {
1349 tk 827
      SEQ_LCD_PrintString("RECORDING      ");
828
    }
829
  } else {
830
    switch( edit_mode ) {
240 tk 831
    case SEQ_UI_EDIT_MODE_COPY: {
832
      if( ui_cursor_flash ) {
833
    SEQ_LCD_PrintSpaces(15);
834
      } else {
835
    char str_buffer[10];
836
    sprintf(str_buffer, "%d-%d", SEQ_UI_UTIL_CopyPasteBeginGet()+1, SEQ_UI_UTIL_CopyPasteEndGet()+1);
278 tk 837
    SEQ_LCD_PrintFormattedString("COPY S%-9s", str_buffer);
240 tk 838
      }
839
    } break;
167 tk 840
 
240 tk 841
    case SEQ_UI_EDIT_MODE_PASTE: {
842
      if( ui_cursor_flash ) {
843
    SEQ_LCD_PrintSpaces(15);
844
      } else {
278 tk 845
    SEQ_LCD_PrintFormattedString("PASTE OFFS.%3d ", ui_selected_step+1);
240 tk 846
      }
847
    } break;
167 tk 848
 
240 tk 849
    case SEQ_UI_EDIT_MODE_MOVE: {
850
      if( ui_cursor_flash ) {
851
    SEQ_LCD_PrintSpaces(15);
852
      } else {
278 tk 853
    SEQ_LCD_PrintString("MOVE STEPS     ");
240 tk 854
      }
855
    } break;
176 tk 856
 
240 tk 857
    case SEQ_UI_EDIT_MODE_SCROLL: {
858
      if( ui_cursor_flash ) {
859
    SEQ_LCD_PrintSpaces(15);
860
      } else {
278 tk 861
    SEQ_LCD_PrintString("SCROLL TRACK   ");
240 tk 862
      }
863
    } break;
176 tk 864
 
240 tk 865
    case SEQ_UI_EDIT_MODE_RANDOM: {
866
      if( ui_cursor_flash ) {
867
    SEQ_LCD_PrintSpaces(15);
868
      } else {
278 tk 869
    SEQ_LCD_PrintString("RANDOMIZED     ");
240 tk 870
      }
871
    } break;
176 tk 872
 
600 tk 873
    case SEQ_UI_EDIT_MODE_MANUAL: {
874
      if( ui_cursor_flash ) {
875
    SEQ_LCD_PrintSpaces(15);
876
      } else {
877
    SEQ_LCD_PrintString("MANUAL TRIGGER ");
878
      }
879
    } break;
880
 
240 tk 881
    default: {
326 tk 882
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
883
    SEQ_LCD_PrintChar(' ');
884
    SEQ_LCD_PrintChar(' ');
885
    SEQ_LCD_PrintMIDIOutPort(SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT));
886
    SEQ_LCD_PrintChar(' ');
887
    SEQ_LCD_PrintFormattedString("Chn.%2d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
888
      } else {
889
    SEQ_LCD_PrintTrackLabel(visible_track, (char *)seq_core_trk[visible_track].name);
890
      }
891
    }
1349 tk 892
    }
326 tk 893
  }
176 tk 894
 
326 tk 895
  SEQ_LCD_PrintSpaces(2);
176 tk 896
 
326 tk 897
  SEQ_LCD_PrintChar('P');
898
  SEQ_LCD_PrintChar('A' + ui_selected_par_layer);
899
  SEQ_LCD_PrintChar(':');
240 tk 900
 
1316 tk 901
  if( layer_type == SEQ_PAR_Type_CC ) {
333 tk 902
    SEQ_LCD_PrintFormattedString("CC#%3d ", layer_event.midi_package.cc_number);
903
  } else {
904
    SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, ui_selected_par_layer));
905
    SEQ_LCD_PrintSpaces(2);
176 tk 906
  }
167 tk 907
 
328 tk 908
  SEQ_LCD_PrintFormattedString("T%c:%s", 'A' + ui_selected_trg_layer, SEQ_TRG_AssignedTypeStr(visible_track, ui_selected_trg_layer));
327 tk 909
 
910
 
167 tk 911
  ///////////////////////////////////////////////////////////////////////////
278 tk 912
  SEQ_LCD_CursorSet(40, 0);
167 tk 913
 
1316 tk 914
  SEQ_LCD_PrintFormattedString("Step%3d ", ui_selected_step+1);
167 tk 915
 
1316 tk 916
  if( layer_event.midi_package.event == CC ) {
917
    mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
918
    u8 loopback = port == 0xf0;
741 tk 919
 
1316 tk 920
    if( loopback )
921
      SEQ_LCD_PrintString((char *)SEQ_CC_LABELS_Get(port, layer_event.midi_package.cc_number));
922
    else
923
      SEQ_LCD_PrintFormattedString("  CC#%3d", layer_event.midi_package.cc_number);
1351 tk 924
    SEQ_LCD_PrintFormattedString(" %3d ", layer_event.midi_package.value);
925
    SEQ_LCD_PrintVBar(layer_event.midi_package.value >> 4);
1316 tk 926
  } else {
927
    SEQ_LCD_PrintSpaces(2);
741 tk 928
 
1316 tk 929
    if( layer_event.midi_package.note && layer_event.midi_package.velocity && (layer_event.len >= 0) ) {
930
      if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator ) {
1350 tk 931
    u8 par_value = PassiveEditValid() ? edit_passive_value : layer_event.midi_package.note;
932
    SEQ_LCD_PrintArp(par_value);
1316 tk 933
      } else if( layer_type == SEQ_PAR_Type_Chord ) {
1350 tk 934
    u8 par_value = PassiveEditValid()
935
      ? edit_passive_value
936
      : SEQ_PAR_Get(visible_track, ui_selected_step, 0, ui_selected_instrument);
937
 
1316 tk 938
    u8 chord_ix = par_value & 0x1f;
939
    u8 chord_oct = par_value >> 5;
940
    SEQ_LCD_PrintString(SEQ_CHORD_NameGet(chord_ix));
941
    SEQ_LCD_PrintFormattedString("/%d", chord_oct);
942
      } else {
1350 tk 943
    u8 par_value = PassiveEditValid() ? edit_passive_value : layer_event.midi_package.note;
944
    SEQ_LCD_PrintNote(par_value);
288 tk 945
      }
1351 tk 946
      SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
176 tk 947
    }
1316 tk 948
    else {
949
      SEQ_LCD_PrintString("....");
950
    }
951
    SEQ_LCD_PrintFormattedString(" Vel:%3d", layer_event.midi_package.velocity);
176 tk 952
  }
167 tk 953
 
1316 tk 954
  SEQ_LCD_PrintString(" Len:");
955
  SEQ_LCD_PrintGatelength(layer_event.len);
167 tk 956
 
1316 tk 957
 
740 tk 958
  // print flashing *LOOPED* at right corner if loop mode activated to remind that steps will be played differntly
959
  if( (ui_cursor_flash_overrun_ctr & 1) && seq_core_state.LOOP ) {
960
    SEQ_LCD_PrintString(" *LOOPED*");
828 tk 961
  } else if( (ui_cursor_flash_overrun_ctr & 1) && seq_core_trk[visible_track].play_section > 0 ) {
962
    SEQ_LCD_PrintFormattedString(" *Sect.%c*", 'A'+seq_core_trk[visible_track].play_section);
326 tk 963
  } else {
740 tk 964
    SEQ_LCD_PrintSpaces(4);
965
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
966
      SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
967
    } else {
968
      SEQ_LCD_PrintTrackCategory(visible_track, (char *)seq_core_trk[visible_track].name);
969
    }
180 tk 970
  }
167 tk 971
 
972
  ///////////////////////////////////////////////////////////////////////////
1211 tk 973
  // Second Line
974
  ///////////////////////////////////////////////////////////////////////////
167 tk 975
 
336 tk 976
  u8 show_drum_triggers = (event_mode == SEQ_EVENT_MODE_Drum && (edit_mode || !ui_hold_msg_ctr));
335 tk 977
 
176 tk 978
  // extra handling for gatelength (shows vertical bars)
335 tk 979
  if( !show_drum_triggers && layer_type == SEQ_PAR_Type_Length ) {
167 tk 980
 
176 tk 981
    // we want to show horizontal bars
982
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_HBars);
167 tk 983
 
176 tk 984
    // initial cursor position
278 tk 985
    SEQ_LCD_CursorSet(0, 1);
167 tk 986
 
176 tk 987
    // determine length of previous step (depends on selected view and track length)
988
    int previous_step = 16*ui_selected_step_view - 1;
989
    if( previous_step < 0 )
990
      previous_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
991
 
992
    seq_layer_evnt_t layer_event;
336 tk 993
    SEQ_LAYER_GetEvntOfLayer(visible_track, previous_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
176 tk 994
    u16 previous_length = layer_event.len;
330 tk 995
 
996
    // show length of 16 steps
336 tk 997
    u16 step;
330 tk 998
    for(step=0; step<16; ++step) {
336 tk 999
      u16 visible_step = step + 16*ui_selected_step_view;
1000
      SEQ_LAYER_GetEvntOfLayer(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
330 tk 1001
 
1143 tk 1002
      u8 gate = SEQ_TRG_GateGet(visible_track, visible_step, ui_selected_instrument);
1003
 
338 tk 1004
      // muted step? if previous gatelength <= 96, print spaces
1143 tk 1005
      if( (!gate || !layer_event.midi_package.velocity) && previous_length < 96 ) {
338 tk 1006
    SEQ_LCD_PrintSpaces(5);
1007
      } else {
1008
    if( layer_event.len >= 96 )
1009
      SEQ_LCD_PrintHBar(15); // glide or stretched event
330 tk 1010
    else
338 tk 1011
      SEQ_LCD_PrintHBar(((layer_event.len-1)*16)/100);
330 tk 1012
      }
1143 tk 1013
      previous_length = ((gate && layer_event.midi_package.velocity) || (previous_length >= 96 && layer_event.len >= 96)) ? layer_event.len : 0;
330 tk 1014
    }
1015
 
176 tk 1016
  } else {
1017
 
335 tk 1018
    if( show_drum_triggers ) {
323 tk 1019
      // we want to show triggers
325 tk 1020
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_DrumSymbolsBig);
323 tk 1021
    } else {
1022
      // we want to show vertical bars
1023
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
1024
    }
176 tk 1025
 
1026
    // initial cursor position
278 tk 1027
    SEQ_LCD_CursorSet(0, 1);
176 tk 1028
 
323 tk 1029
    int step_region_begin;
1030
    int step_region_end;
240 tk 1031
    switch( edit_mode ) {
1032
      case SEQ_UI_EDIT_MODE_COPY:
1033
    step_region_begin = SEQ_UI_UTIL_CopyPasteBeginGet();
1034
    step_region_end = SEQ_UI_UTIL_CopyPasteEndGet();
1035
    break;
1036
      case SEQ_UI_EDIT_MODE_PASTE:
1037
    step_region_begin = ui_selected_step;
1038
    step_region_end = ui_selected_step + SEQ_UI_UTIL_CopyPasteEndGet() - SEQ_UI_UTIL_CopyPasteBeginGet();
1039
    break;
1040
      case SEQ_UI_EDIT_MODE_SCROLL:
1041
    step_region_begin = ui_selected_step;
1042
    step_region_end = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
1043
    break;
1044
      default:
336 tk 1045
    step_region_begin = ui_selected_step;
1046
    step_region_end = ui_selected_step;
240 tk 1047
    }
1048
 
336 tk 1049
    u16 step;
176 tk 1050
    for(step=0; step<16; ++step) {
336 tk 1051
      u16 visible_step = step + 16*ui_selected_step_view;
240 tk 1052
 
1053
      if( ui_cursor_flash &&
1054
      edit_mode != SEQ_UI_EDIT_MODE_NORMAL &&
1055
      visible_step >= step_region_begin && visible_step <= step_region_end ) {
1056
    SEQ_LCD_PrintSpaces(5);
1057
    continue;
1058
      }
1059
 
335 tk 1060
      if( show_drum_triggers ) {
336 tk 1061
    u8 gate_accent = SEQ_TRG_Get(visible_track, visible_step, 0, ui_selected_instrument);
328 tk 1062
    if( SEQ_TRG_NumLayersGet(visible_track) >= 2 )
336 tk 1063
      gate_accent |= SEQ_TRG_Get(visible_track, visible_step, 1, ui_selected_instrument) << 1;
335 tk 1064
 
323 tk 1065
    SEQ_LCD_PrintChar(' ');
1066
    SEQ_LCD_PrintChar(' ');
327 tk 1067
    SEQ_LCD_PrintChar(gate_accent);
323 tk 1068
    SEQ_LCD_PrintChar(' ');
1069
    SEQ_LCD_PrintChar(' ');
1070
      } else {
1351 tk 1071
    int print_edit_value = (visible_step == edit_passive_step && PassiveEditValid()) ? edit_passive_value : -1;
1072
    SEQ_LCD_PrintLayerEvent(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument, 1, print_edit_value);
176 tk 1073
      }
1074
 
336 tk 1075
      if( !show_drum_triggers ) {
323 tk 1076
    SEQ_LCD_PrintChar((visible_step == step_region_end) ? '<'
1077
              : ((visible_step == (step_region_begin-1)) ? '>' : ' '));
1078
      }
240 tk 1079
 
176 tk 1080
    }
167 tk 1081
  }
1082
 
1083
  return 0; // no error
1084
}
1085
 
1086
 
1087
/////////////////////////////////////////////////////////////////////////////
240 tk 1088
// Local Display Handler function
1089
// IN: <high_prio>: if set, a high-priority LCD update is requested
1090
/////////////////////////////////////////////////////////////////////////////
1091
static s32 LCD_Handler(u8 high_prio)
1092
{
1093
  return SEQ_UI_EDIT_LCD_Handler(high_prio, SEQ_UI_EDIT_MODE_NORMAL);
1094
}
1095
 
1096
 
1097
/////////////////////////////////////////////////////////////////////////////
167 tk 1098
// Initialisation
1099
/////////////////////////////////////////////////////////////////////////////
1100
s32 SEQ_UI_EDIT_Init(u32 mode)
1101
{
1102
  // install callback routines
758 tk 1103
  SEQ_UI_InstallButtonCallback(SEQ_UI_EDIT_Button_Handler);
168 tk 1104
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
240 tk 1105
  SEQ_UI_InstallLEDCallback(SEQ_UI_EDIT_LED_Handler);
168 tk 1106
  SEQ_UI_InstallLCDCallback(LCD_Handler);
167 tk 1107
 
1142 tk 1108
  show_edit_config_page = 0;
1350 tk 1109
  edit_passive_mode = 0;
729 tk 1110
 
1142 tk 1111
  if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL )
1112
    seq_ui_edit_view = SEQ_UI_EDIT_VIEW_STEPS;
1113
 
167 tk 1114
  return 0; // no error
1115
}
178 tk 1116
 
1117
 
1118
 
1119
/////////////////////////////////////////////////////////////////////////////
1120
// help function to change/set a single encoder value
1121
// if forced_value >= 0: new value will be set to the given value
1122
// if forced_value < 0: new value will be changed via incrementer
1123
// returns >= 0 if new value has been set (value change)
1124
// returns < 0 if no change
1125
/////////////////////////////////////////////////////////////////////////////
1052 tk 1126
static s32 ChangeSingleEncValue(u8 track, u16 par_step, u16 trg_step, s32 incrementer, s32 forced_value, u8 change_gate, u8 dont_change_gate)
178 tk 1127
{
333 tk 1128
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(track, ui_selected_par_layer);
335 tk 1129
  u8 visible_track = SEQ_UI_VisibleTrackGet();
178 tk 1130
 
828 tk 1131
#if 0
1132
  // disabled in MBSEQ V4.0beta15 due to issue reported by Gridracer:
1133
  // http://midibox.org/forums/index.php?/topic/13137-midibox-seq-v4-beta-release-feedback/page__st__100
1134
 
333 tk 1135
  // if note/chord/velocity parameter: only change gate if requested
1136
  if( (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord || layer_type == SEQ_PAR_Type_Velocity) &&
178 tk 1137
      !change_gate &&
652 tk 1138
      !SEQ_TRG_GateGet(track, trg_step, ui_selected_instrument) )
178 tk 1139
    return -1;
828 tk 1140
#endif
178 tk 1141
 
1052 tk 1142
  if( layer_type == SEQ_PAR_Type_Probability ) {
1143
    // due to another issue reported by Gridracer:
1144
    // invert incrementer so that clockwise move increases probability
1145
    incrementer = -incrementer;
1146
  }
1147
 
1148
 
335 tk 1149
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
652 tk 1150
  if( event_mode == SEQ_EVENT_MODE_Drum ) {
335 tk 1151
    ui_hold_msg_ctr = 1000; // show value for 1 second
652 tk 1152
  }
335 tk 1153
 
652 tk 1154
  s32 old_value = SEQ_PAR_Get(track, par_step, ui_selected_par_layer, ui_selected_instrument);
178 tk 1155
  s32 new_value = (forced_value >= 0) ? forced_value : (old_value + incrementer);
1156
  if( new_value < 0 )
1157
    new_value = 0;
1158
  else if( new_value >= 128 )
1159
    new_value = 127;
1160
 
1143 tk 1161
  // extra for more comfortable editing of multi-note tracks:
1162
  // if assigned parameter layer is Note or Chord, and currently 0, re-start at C-3 resp. A/2
1163
  // when value is incremented
1164
  if( incrementer > 0 && forced_value < 0 && old_value == 0x00 && (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord) )
1165
    new_value = (layer_type == SEQ_PAR_Type_Note && SEQ_CC_Get(track, SEQ_CC_MODE) != SEQ_CORE_TRKMODE_Arpeggiator) ? 0x3c : 0x40;
1166
 
1345 tk 1167
  if( !dont_change_gate ) {
1168
    u8 event_mode = SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
1169
 
1170
    // we do this always regardless if value has been changed or not (e.g. increment if value already 127)
1171
    if( event_mode == SEQ_EVENT_MODE_CC && layer_type == SEQ_PAR_Type_CC ) {
1172
      // in this mode gates are used to disable CC
1173
      // if a CC value has been changed, set gate
1174
      SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 1);
1175
    }
1176
  }
1177
 
178 tk 1178
  // take over if changed
1179
  if( new_value == old_value )
1180
    return -1;
1181
 
652 tk 1182
  SEQ_PAR_Set(track, par_step, ui_selected_par_layer, ui_selected_instrument, (u8)new_value);
178 tk 1183
 
747 tk 1184
  if( !dont_change_gate &&
1185
      (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord || layer_type == SEQ_PAR_Type_Velocity) ) {
178 tk 1186
    // (de)activate gate depending on value
1187
    if( new_value )
652 tk 1188
      SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 1);
1053 tk 1189
    else {
1190
      // due to another issue reported by Gridracer:
1191
      // if the track plays multiple notes, only clear gate if all notes are 0
1142 tk 1192
      u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1053 tk 1193
      u8 allNotesZero = 1;
1194
      int i;
1142 tk 1195
      for(i=0; i<num_p_layers; ++i) {
1053 tk 1196
    seq_par_layer_type_t localLayerType = SEQ_PAR_AssignmentGet(track, i);
1197
    if( (localLayerType == SEQ_PAR_Type_Note || localLayerType == SEQ_PAR_Type_Chord) &&
1198
        SEQ_PAR_Get(track, par_step, i, ui_selected_instrument) > 0 ) {
1199
      allNotesZero = 0;
1200
      break;
1201
    }
1202
      }
1203
 
1204
      if( allNotesZero )
1205
    SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 0);
1206
    }
178 tk 1207
  }
1208
 
1209
  return new_value;
1210
}
1350 tk 1211
 
1212
 
1213
/////////////////////////////////////////////////////////////////////////////
1214
// help functions for "passive edit mode"
1215
/////////////////////////////////////////////////////////////////////////////
1216
static s32 PassiveEditEnter(void)
1217
{
1218
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1351 tk 1219
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
1350 tk 1220
 
1351 tk 1221
  // passive edit mode currently only supported for notes/chords
1350 tk 1222
 
1351 tk 1223
  if( layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord ) {
1224
    // enter passive edit mode and store track/step/layer/instrument for later checks
1225
    edit_passive_mode = 1;
1226
    edit_passive_track = visible_track;
1227
    edit_passive_step = ui_selected_step;
1228
    edit_passive_par_layer = ui_selected_par_layer;
1229
    edit_passive_instrument = ui_selected_instrument;
1230
    edit_passive_value = SEQ_PAR_Get(edit_passive_track, edit_passive_step, edit_passive_par_layer, edit_passive_instrument);
1231
  } else {
1232
    edit_passive_mode = 0;
1233
  }
1234
 
1350 tk 1235
  return 0; // no error
1236
}
1237
 
1238
static s32 PassiveEditValid(void)
1239
{
1240
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1241
 
1242
  return (edit_passive_mode == 2 && // if mode is 2, the value has been changed!
1243
      edit_passive_track == visible_track &&
1244
      edit_passive_step == ui_selected_step &&
1245
      edit_passive_par_layer == ui_selected_par_layer &&
1246
      edit_passive_instrument == ui_selected_instrument) ? 1 : 0;
1247
}
1248
 
1249
static s32 PassiveEditTakeOver(void)
1250
{
1251
 
1252
  // only take over changed value if track/step/layer/instrument still passing
1253
  if( PassiveEditValid() ) {
1254
    // take over change
1255
    // handle it like a single increment/decrement so that no code needs to be duplicated
1256
    int current_value = SEQ_PAR_Get(edit_passive_track, edit_passive_step, edit_passive_par_layer, edit_passive_instrument);
1257
    int incrementer = (int)edit_passive_value - current_value;
1258
 
1259
    show_edit_config_page = 0; // just to avoid any overlay...
1260
    edit_passive_mode = 0; // to avoid recursion in encoder handler
1261
    Encoder_Handler(edit_passive_step % 16, incrementer);
1262
  } else {
1263
    edit_passive_mode = 1;
1264
  }
1265
 
1266
  return 0; // no error
1267
}