Subversion Repositories svn.mios32

Rev

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