Subversion Repositories svn.mios32

Rev

Rev 2551 | Rev 2563 | 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 2553 2018-01-05 14:48:11Z 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>
2101 tk 19
#include "tasks.h"
20
 
167 tk 21
#include "seq_lcd.h"
22
#include "seq_ui.h"
23
 
2101 tk 24
#include "seq_file_gc.h"
25
 
167 tk 26
#include "seq_core.h"
168 tk 27
#include "seq_cc.h"
741 tk 28
#include "seq_cc_labels.h"
176 tk 29
#include "seq_layer.h"
167 tk 30
#include "seq_par.h"
31
#include "seq_trg.h"
690 tk 32
#include "seq_chord.h"
1349 tk 33
#include "seq_record.h"
600 tk 34
#include "seq_hwcfg.h"
167 tk 35
 
36
 
37
/////////////////////////////////////////////////////////////////////////////
1203 tk 38
// Global Variables
1142 tk 39
/////////////////////////////////////////////////////////////////////////////
1203 tk 40
seq_ui_edit_view_t seq_ui_edit_view = SEQ_UI_EDIT_VIEW_STEPS;
2101 tk 41
seq_ui_edit_datawheel_mode_t seq_ui_edit_datawheel_mode = SEQ_UI_EDIT_DATAWHEEL_MODE_SCROLL_CURSOR;
1142 tk 42
 
1203 tk 43
 
1142 tk 44
/////////////////////////////////////////////////////////////////////////////
729 tk 45
// Local Variables
46
/////////////////////////////////////////////////////////////////////////////
47
 
48
static u16 selected_steps = 0xffff; // will only be initialized once after startup
49
 
1350 tk 50
// activated by pressing EDIT button: encoder value will be taken over by releasing EDIT button
51
// mode 0: function not active (EDIT button released)
52
// mode 1: function activated (EDIT button pressed)
53
// mode 2: value has been changed while EDIT button pressed (a message will pop up on screen)
54
static u8 edit_passive_mode;
55
static u8 edit_passive_value;      // the tmp. edited value
56
static u8 edit_passive_track;      // to store the track of the edit value
57
static u8 edit_passive_step;       // to store the step of the edit value
58
static u8 edit_passive_par_layer;  // to store the layer of the edit value
59
static u8 edit_passive_instrument; // to store the instrument of the edit value
1348 tk 60
 
2533 tk 61
static u8 edit_ramp;
2101 tk 62
 
2533 tk 63
 
729 tk 64
/////////////////////////////////////////////////////////////////////////////
2047 tk 65
 
66
typedef enum {
67
  MIDI_LEARN_MODE_OFF = 0,
68
  MIDI_LEARN_MODE_ON,
69
} midi_learn_mode_t;
70
 
71
static midi_learn_mode_t midi_learn_mode = MIDI_LEARN_MODE_OFF;
72
 
73
 
74
/////////////////////////////////////////////////////////////////////////////
178 tk 75
// Local prototypes
76
/////////////////////////////////////////////////////////////////////////////
77
 
2101 tk 78
static s32 CheckStoreFile(void);
747 tk 79
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 80
static s32 PassiveEditEnter(void);
81
static s32 PassiveEditValid(void);
82
static s32 PassiveEditTakeOver(void);
178 tk 83
 
84
 
85
/////////////////////////////////////////////////////////////////////////////
240 tk 86
// LED handler function (globally accessible, since it's re-used by UTIL page)
167 tk 87
/////////////////////////////////////////////////////////////////////////////
240 tk 88
s32 SEQ_UI_EDIT_LED_Handler(u16 *gp_leds)
167 tk 89
{
90
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1142 tk 91
 
2048 tk 92
  if( seq_ui_button_state.EDIT_PRESSED ) {
1142 tk 93
    switch( seq_ui_edit_view ) {
94
    case SEQ_UI_EDIT_VIEW_STEPS: *gp_leds = (1 << 0); break;
95
    case SEQ_UI_EDIT_VIEW_TRG: *gp_leds = (1 << 1); break;
96
    case SEQ_UI_EDIT_VIEW_LAYERS: *gp_leds = (1 << 2); break;
97
    case SEQ_UI_EDIT_VIEW_303: *gp_leds = (1 << 3); break;
98
    case SEQ_UI_EDIT_VIEW_STEPSEL: *gp_leds = (1 << 8); break;
99
    }
100
  } else {
167 tk 101
 
2533 tk 102
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPS && (seq_ui_button_state.CHANGE_ALL_STEPS || seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE) && midi_learn_mode == MIDI_LEARN_MODE_OFF && !seq_record_state.ENABLED ) {
1751 tk 103
      *gp_leds = ui_cursor_flash ? 0x0000 : selected_steps;
104
    } else if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
1142 tk 105
      *gp_leds = selected_steps;
106
    } else {
167 tk 107
 
1142 tk 108
      u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
109
 
110
      if( event_mode != SEQ_EVENT_MODE_Drum &&
111
      (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_303) ) {
112
 
113
    if( SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) )
114
      *gp_leds |= (1 << 1);
115
    if( SEQ_TRG_AccentGet(visible_track, ui_selected_step, ui_selected_instrument) )
116
      *gp_leds |= (1 << 2);
117
    if( SEQ_TRG_GlideGet(visible_track, ui_selected_step, ui_selected_instrument) )
118
      *gp_leds |= (1 << 3);
119
 
120
    if( ui_selected_par_layer == 0 )
121
      *gp_leds |= (3 << 4);
122
    else
123
      *gp_leds |= (1 << (ui_selected_par_layer+5));
124
 
2553 tk 125
      } else if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_LAYERS || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
1142 tk 126
 
127
    u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
128
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
129
      // maximum 7 parameter layers due to "Step" item!
2553 tk 130
      // if drum: only 6 parameter layers due to additional "Drum" item!
131
      u8 max_t_layers = (event_mode == SEQ_EVENT_MODE_Drum) ? 6 : 7;
132
      if( num_t_layers >= max_t_layers )
133
        num_t_layers = max_t_layers;
1142 tk 134
    } else {
135
      // single trigger layer (gate)
136
      num_t_layers = 1;
137
    }
138
 
2553 tk 139
    u8 t_layer_offset = (event_mode == SEQ_EVENT_MODE_Drum) ? 2 : 1;
1142 tk 140
    int i;
141
    for(i=0; i<num_t_layers; ++i)
142
      if( SEQ_TRG_Get(visible_track, ui_selected_step, i, ui_selected_instrument) )
2553 tk 143
        *gp_leds |= (1 << (i+t_layer_offset));
1142 tk 144
 
145
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
146
      *gp_leds |= (1 << (ui_selected_par_layer+8));
147
    } else {
2553 tk 148
      *gp_leds |= (1 << (ui_selected_par_layer+t_layer_offset+1));
1142 tk 149
    }
150
      } else {
151
    *gp_leds =
152
      (SEQ_TRG_Get8(visible_track, 2*ui_selected_step_view+1, ui_selected_trg_layer, ui_selected_instrument) << 8) |
153
      (SEQ_TRG_Get8(visible_track, 2*ui_selected_step_view+0, ui_selected_trg_layer, ui_selected_instrument) << 0);
154
      }
155
    }
156
  }
157
 
167 tk 158
  return 0; // no error
159
}
160
 
161
 
162
/////////////////////////////////////////////////////////////////////////////
168 tk 163
// Local encoder callback function
164
// Should return:
165
//   1 if value has been changed
166
//   0 if value hasn't been changed
167
//  -1 if invalid or unsupported encoder
167 tk 168
/////////////////////////////////////////////////////////////////////////////
168 tk 169
static s32 Encoder_Handler(seq_ui_encoder_t encoder, s32 incrementer)
167 tk 170
{
1348 tk 171
  u8 visible_track = SEQ_UI_VisibleTrackGet();
172
 
173
  if( encoder == SEQ_UI_ENCODER_Datawheel ) {
174
    u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
175
 
2101 tk 176
    switch( seq_ui_edit_datawheel_mode ) {
177
    case SEQ_UI_EDIT_DATAWHEEL_MODE_SCROLL_CURSOR:
1753 tk 178
      if( SEQ_UI_Var8_Inc(&ui_selected_step, 0, num_steps-1, incrementer) >= 1 ) {
179
    ui_selected_step_view = ui_selected_step / 16;
1348 tk 180
    return 1;
1753 tk 181
      } else
1348 tk 182
    return 0;
183
 
2101 tk 184
    case SEQ_UI_EDIT_DATAWHEEL_MODE_SCROLL_VIEW:
1348 tk 185
      if( SEQ_UI_Var8_Inc(&ui_selected_step_view, 0, (num_steps-1)/16, incrementer) >= 1 ) {
2533 tk 186
    if( !seq_ui_button_state.CHANGE_ALL_STEPS && !seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
1753 tk 187
      // select step within view
188
      ui_selected_step = (ui_selected_step_view << 4) | (ui_selected_step & 0xf);
189
    }
1348 tk 190
    return 1;
191
      } else {
192
    return 0;
193
      }
194
 
2101 tk 195
    case SEQ_UI_EDIT_DATAWHEEL_MODE_CHANGE_VALUE:
1348 tk 196
      break; // drop... continue below with common encoder value change routine
197
 
2101 tk 198
    case SEQ_UI_EDIT_DATAWHEEL_MODE_CHANGE_PARLAYER: {
1348 tk 199
      u8 num_layers = SEQ_PAR_NumLayersGet(visible_track);
200
 
201
      if( SEQ_UI_Var8_Inc(&ui_selected_par_layer, 0, num_layers-1, incrementer) >= 1 )
202
    return 1;
203
      else
204
    return 0;
205
    } break;
206
 
2101 tk 207
    case SEQ_UI_EDIT_DATAWHEEL_MODE_CHANGE_TRGLAYER: {
1348 tk 208
      u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
209
 
210
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
211
    u8 num_layers = SEQ_TRG_NumInstrumentsGet(visible_track);
212
    if( SEQ_UI_Var8_Inc(&ui_selected_instrument, 0, num_layers-1, incrementer) >= 1 )
213
      return 1;
214
    else
215
      return 0;
216
      } else {
217
    u8 num_layers = SEQ_TRG_NumLayersGet(visible_track);
218
    if( SEQ_UI_Var8_Inc(&ui_selected_trg_layer, 0, num_layers-1, incrementer) >= 1 )
219
      return 1;
220
    else
221
      return 0;
222
      }
223
    } break;
224
    }
225
  }
226
 
168 tk 227
#if 0
228
  // leads to: comparison is always true due to limited range of data type
229
  if( (encoder >= SEQ_UI_ENCODER_GP1 && encoder <= SEQ_UI_ENCODER_GP16) || encoder == SEQ_UI_ENCODER_Datawheel ) {
230
#else
231
  if( encoder <= SEQ_UI_ENCODER_GP16 || encoder == SEQ_UI_ENCODER_Datawheel ) {
232
#endif
1142 tk 233
 
2048 tk 234
    if( seq_ui_button_state.EDIT_PRESSED ) {
1142 tk 235
      switch( encoder ) {
236
      case SEQ_UI_ENCODER_GP1: seq_ui_edit_view = SEQ_UI_EDIT_VIEW_STEPS; break;
237
      case SEQ_UI_ENCODER_GP2: seq_ui_edit_view = SEQ_UI_EDIT_VIEW_TRG; break;
238
      case SEQ_UI_ENCODER_GP3: seq_ui_edit_view = SEQ_UI_EDIT_VIEW_LAYERS; break;
239
      case SEQ_UI_ENCODER_GP4: seq_ui_edit_view = SEQ_UI_EDIT_VIEW_303; break;
1483 tk 240
      case SEQ_UI_ENCODER_GP8: seq_ui_edit_view = SEQ_UI_EDIT_VIEW_STEPSEL; break;
1348 tk 241
 
1483 tk 242
      case SEQ_UI_ENCODER_GP9:
243
      case SEQ_UI_ENCODER_GP10: {
1348 tk 244
    if( incrementer == 0 ) // button
1753 tk 245
      incrementer = (encoder == SEQ_UI_ENCODER_GP9) ? -1 : 1;
1348 tk 246
 
2101 tk 247
    if( SEQ_UI_Var8_Inc(&seq_ui_edit_datawheel_mode, 0, SEQ_UI_EDIT_DATAWHEEL_MODE_NUM-1, incrementer) >= 1 ) {
2102 tk 248
      ui_store_file_required = 1;
1348 tk 249
      return 1;
2101 tk 250
    } else
1348 tk 251
      return 0;
1142 tk 252
      }
1483 tk 253
 
2050 tk 254
      case SEQ_UI_ENCODER_GP11:
255
      case SEQ_UI_ENCODER_GP12:
2164 tk 256
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRKJAM);
2050 tk 257
    break;
258
 
1483 tk 259
      case SEQ_UI_ENCODER_GP13:
260
      case SEQ_UI_ENCODER_GP14:
261
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRKRND);
262
    break;
263
 
264
      case SEQ_UI_ENCODER_GP15:
265
      case SEQ_UI_ENCODER_GP16:
266
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRKEUCLID);
267
    break;
1348 tk 268
      }
269
 
2048 tk 270
      seq_ui_button_state.EDIT_PRESSED = 0; // switch back to view
1142 tk 271
      return 1; // value changed
272
    }
273
 
274
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
729 tk 275
      if( incrementer > 0 )
276
    selected_steps |= (1 << encoder);
277
      else
278
    selected_steps &= ~(1 << encoder);
279
      return 1; // value changed
280
    }
281
 
1142 tk 282
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
182 tk 283
 
1142 tk 284
    if( event_mode != SEQ_EVENT_MODE_Drum &&
285
    (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_303) ) {
286
      u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
287
 
288
      if( encoder == SEQ_UI_ENCODER_GP1 ) {
1348 tk 289
    if( SEQ_UI_Var8_Inc(&ui_selected_step, 0, num_steps-1, incrementer) >= 1 )
1142 tk 290
      return 1;
291
    else
292
      return 0;
293
      } else if( encoder == SEQ_UI_ENCODER_GP2 ) {
294
    SEQ_TRG_GateSet(visible_track, ui_selected_step, ui_selected_instrument, incrementer > 0 ? 1 : 0);
295
    return 1;
296
      } else if( encoder == SEQ_UI_ENCODER_GP3 ) {
297
    SEQ_TRG_AccentSet(visible_track, ui_selected_step, ui_selected_instrument, incrementer > 0 ? 1 : 0);
298
    return 1;
299
      } else if( encoder == SEQ_UI_ENCODER_GP4 ) {
300
    SEQ_TRG_GlideSet(visible_track, ui_selected_step, ui_selected_instrument, incrementer > 0 ? 1 : 0);
301
    return 1;
302
      } else if( encoder == SEQ_UI_ENCODER_GP5 ) {
303
    ui_selected_par_layer = 0;
304
    u8 note = SEQ_PAR_Get(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument);
305
    u8 note_octave = note / 12;
306
    u8 note_key = note % 12;
307
 
308
    if( SEQ_UI_Var8_Inc(&note_octave, 0, 9, incrementer) >= 1 ) {
309
      SEQ_PAR_Set(visible_track, ui_selected_step, 0, ui_selected_instrument, 12*note_octave + note_key);
310
      return 1;
311
    }
312
    return 0;
313
      } else if( encoder == SEQ_UI_ENCODER_GP6 ) {
314
    ui_selected_par_layer = 0;
315
    u8 note = SEQ_PAR_Get(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument);
316
    u8 note_octave = note / 12;
317
    u8 note_key = note % 12;
318
 
319
    if( SEQ_UI_Var8_Inc(&note_key, 0, 11, incrementer) >= 1 ) {
320
      SEQ_PAR_Set(visible_track, ui_selected_step, 0, ui_selected_instrument, 12*note_octave + note_key);
321
      return 1;
322
    }
323
    return 0;
324
      } else if( encoder <= SEQ_UI_ENCODER_GP16 ) {
325
    u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
326
    if( ((int)encoder-5) >= num_p_layers )
327
        return 0; // ignore
328
      ui_selected_par_layer = encoder-5;
329
      }
330
 
331
      if( !incrementer ) // button selection only...
332
    return 1;
333
    }
334
 
2553 tk 335
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_LAYERS || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
336
      u16 num_instruments = SEQ_PAR_NumInstrumentsGet(visible_track);
1142 tk 337
      u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
2553 tk 338
      u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
339
      u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1142 tk 340
 
2553 tk 341
      seq_ui_encoder_t drum_encoder;
342
      seq_ui_encoder_t step_encoder;
343
      seq_ui_encoder_t gate_encoder;
344
      u8 trg_encoder_offset;
345
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
346
    drum_encoder = SEQ_UI_ENCODER_GP1;
347
    step_encoder = SEQ_UI_ENCODER_GP2;
348
    gate_encoder = SEQ_UI_ENCODER_GP3;
349
    trg_encoder_offset = 2;
350
      } else {
351
    drum_encoder = 0xff; // no drum selection
352
    step_encoder = SEQ_UI_ENCODER_GP1;
353
    gate_encoder = SEQ_UI_ENCODER_GP2;
354
    trg_encoder_offset = 1;
355
      }
356
 
357
      if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
358
    if( num_t_layers > (8-trg_encoder_offset) )
359
        num_t_layers = 8-trg_encoder_offset;
360
      }
361
 
362
      if( encoder == drum_encoder ) {
363
    if( SEQ_UI_Var8_Inc(&ui_selected_instrument, 0, num_instruments-1, incrementer) >= 1 )
1142 tk 364
      return 1;
365
    else
366
      return 0;
2553 tk 367
      } else if( encoder == step_encoder ) {
368
    if( SEQ_UI_Var8_Inc(&ui_selected_step, 0, num_steps-1, incrementer) >= 1 ) {
369
      ui_selected_step_view = ui_selected_step / 16;
370
      return 1;
371
    } else
372
      return 0;
373
      } else if( encoder == gate_encoder ||
374
         (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG && encoder < trg_encoder_offset+num_t_layers) ) {
375
    u8 sel = (u8)encoder-trg_encoder_offset;
1142 tk 376
    SEQ_TRG_Set(visible_track, ui_selected_step, sel, ui_selected_instrument, incrementer > 0 ? 1 : 0);
2230 tk 377
    SEQ_CORE_CancelSustainedNotes(visible_track); // cancel sustain if there are no notes played by the track anymore
1142 tk 378
    return 1;
379
      } else if( encoder <= SEQ_UI_ENCODER_GP16 ) {
380
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
2553 tk 381
      u8 par_encoder_offset = trg_encoder_offset + num_t_layers;
382
      if( ((int)encoder-par_encoder_offset) >= num_p_layers )
383
        return 0; // ignore
384
      ui_selected_par_layer = encoder-par_encoder_offset;
1142 tk 385
    } else {
2553 tk 386
      if( ((int)encoder-trg_encoder_offset-1) >= num_p_layers )
1142 tk 387
        return 0; // ignore
2553 tk 388
      ui_selected_par_layer = encoder-trg_encoder_offset-1;
1142 tk 389
    }
390
 
391
    if( !incrementer ) // button selection only...
392
      return 1;
393
      }
394
    }
395
 
1809 tk 396
    u8 changed_step;
2553 tk 397
    u8 view_steps = seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPS || (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_303 && event_mode == SEQ_EVENT_MODE_Drum);
398
    if( view_steps ) {
1809 tk 399
      changed_step = ((encoder == SEQ_UI_ENCODER_Datawheel) ? (ui_selected_step%16) : encoder) + ui_selected_step_view*16;
400
    } else {
401
      changed_step = ui_selected_step;
402
    }
2533 tk 403
 
404
    edit_ramp = 0;
2553 tk 405
    if( view_steps ) {
1142 tk 406
 
1350 tk 407
      // in passive edit mode: take over the edit value if step has changed, thereafter switch to new step
1751 tk 408
      if( ui_selected_step != changed_step && edit_passive_mode ) {
1350 tk 409
    PassiveEditTakeOver();
1751 tk 410
    ui_selected_step = changed_step;
1350 tk 411
    PassiveEditEnter();
412
      } else {
1751 tk 413
    // take over new step if "ALL" button not pressed to support "ramp" editing
2533 tk 414
    if( !seq_ui_button_state.CHANGE_ALL_STEPS && !seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
1751 tk 415
      ui_selected_step = changed_step;
416
    } else {
417
      if( ui_selected_step != changed_step )
418
        edit_ramp = 1;
419
    }
1350 tk 420
      }
421
 
422
    }
423
 
424
 
425
    // in passive edit mode: change value, but don't take over yet!
426
    if( edit_passive_mode ) {
427
      if( SEQ_UI_Var8_Inc(&edit_passive_value, 0, 127, incrementer) >= 1 ) {
428
    edit_passive_mode = 2; // value has been changed
429
    return 1;
430
      } else
431
    return 0;
432
    }
433
 
434
    // normal edit mode
178 tk 435
    s32 value_changed = 0;
436
    s32 forced_value = -1;
437
    u8  change_gate = 1;
168 tk 438
 
182 tk 439
    // due to historical reasons (from old times where MBSEQ CS was stuffed with pots): 
440
    // in arp mode, we increment in steps of 4
1143 tk 441
    u8 par_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
182 tk 442
    if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator &&
1143 tk 443
    par_type == SEQ_PAR_Type_Note )
182 tk 444
      incrementer *= 4;
445
 
178 tk 446
    // first change the selected value
2533 tk 447
    if( (seq_ui_button_state.CHANGE_ALL_STEPS && edit_ramp) || seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
652 tk 448
      u16 num_steps = SEQ_PAR_NumStepsGet(visible_track);
1751 tk 449
      u16 par_step = changed_step;
450
      u16 trg_step = changed_step;
652 tk 451
 
452
      // mirrored layer in drum mode?
453
      u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
454
      if( event_mode == SEQ_EVENT_MODE_Drum && par_step >= num_steps )
455
    par_step %= num_steps;
456
 
747 tk 457
      forced_value = ChangeSingleEncValue(visible_track, par_step, trg_step, incrementer, forced_value, change_gate, 0);
178 tk 458
      if( forced_value < 0 )
459
    return 0; // no change
460
      value_changed |= 1;
168 tk 461
    }
462
 
1751 tk 463
    int value_selected_step = SEQ_PAR_Get(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument);
464
    int value_changed_step = SEQ_PAR_Get(visible_track, changed_step, ui_selected_par_layer, ui_selected_instrument);
465
 
178 tk 466
    // change value of all selected steps
467
    u8 track;
468
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
469
      if( SEQ_UI_IsSelectedTrack(track) ) {
318 tk 470
    u16 num_steps = SEQ_PAR_NumStepsGet(track);
1751 tk 471
    u16 trg_step = (changed_step & ~(num_steps-1));
472
 
652 tk 473
    u16 par_step;
474
    for(par_step=0; par_step<num_steps; ++par_step, ++trg_step) {
2533 tk 475
      if( !(seq_ui_button_state.CHANGE_ALL_STEPS || seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE) || (!edit_ramp && par_step == changed_step) || (selected_steps & (1 << (par_step % 16))) ) {
1751 tk 476
        change_gate = trg_step == changed_step;
477
        u8 dont_change_gate = par_step != changed_step;
2533 tk 478
        if( change_gate || seq_ui_button_state.CHANGE_ALL_STEPS || seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
1751 tk 479
          s32 local_forced_value = edit_ramp ? -1 : forced_value;
480
 
481
          s32 edit_ramp_num_steps = 0;
482
          if( edit_ramp ) {
483
        if( changed_step > ui_selected_step && par_step > ui_selected_step && par_step < changed_step ) {
484
          edit_ramp_num_steps = changed_step - ui_selected_step;
485
        } else if( changed_step < ui_selected_step && par_step < ui_selected_step && par_step > changed_step ) {
486
          edit_ramp_num_steps = ui_selected_step - changed_step;
487
        }
488
 
489
        if( edit_ramp_num_steps ) {
490
          if( par_step == changed_step ) {
491
            local_forced_value = value_changed_step;
492
          } else {
493
            int diff = value_changed_step - value_selected_step;
494
            if( diff == 0 ) {
495
              local_forced_value = value_changed_step;
496
            } else {
497
              if( changed_step > ui_selected_step ) {
498
            local_forced_value = value_selected_step + (((par_step - ui_selected_step) * diff) / edit_ramp_num_steps);
499
              } else {
500
            local_forced_value = value_selected_step + (((ui_selected_step - par_step) * diff) / edit_ramp_num_steps);
501
              }
502
            }
503
          }
504
        }
505
          }
506
 
507
          if( !edit_ramp || edit_ramp_num_steps ) {
508
        if( ChangeSingleEncValue(track, par_step, trg_step, incrementer, local_forced_value, change_gate, dont_change_gate) >= 0 )
509
          value_changed |= 1;
510
          }
729 tk 511
        }
178 tk 512
      }
513
    }
514
      }
176 tk 515
    }
1142 tk 516
 
178 tk 517
    return value_changed;
168 tk 518
  }
519
 
520
  return -1; // invalid or unsupported encoder
167 tk 521
}
522
 
523
 
524
/////////////////////////////////////////////////////////////////////////////
168 tk 525
// Local button callback function
526
// Should return:
527
//   1 if value has been changed
528
//   0 if value hasn't been changed
529
//  -1 if invalid or unsupported button
167 tk 530
/////////////////////////////////////////////////////////////////////////////
758 tk 531
s32 SEQ_UI_EDIT_Button_Handler(seq_ui_button_t button, s32 depressed)
167 tk 532
{
306 tk 533
  u8 visible_track = SEQ_UI_VisibleTrackGet();
534
 
168 tk 535
#if 0
536
  // leads to: comparison is always true due to limited range of data type
537
  if( button >= SEQ_UI_BUTTON_GP1 && button <= SEQ_UI_BUTTON_GP16 ) {
538
#else
539
  if( button <= SEQ_UI_BUTTON_GP16 ) {
540
#endif
2047 tk 541
 
2063 tk 542
    if( !seq_ui_button_state.EDIT_PRESSED &&
2533 tk 543
    ((seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPS && (seq_ui_button_state.CHANGE_ALL_STEPS || seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE)) ||
2063 tk 544
     seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL) ) {
545
      if( depressed ) return 0; // ignore when button depressed
546
 
547
      selected_steps ^= (1 << button);
548
      return 1; // value changed
549
    }
550
 
2047 tk 551
    // enable/disable MIDI Learn mode
552
    midi_learn_mode = depressed ? MIDI_LEARN_MODE_OFF : MIDI_LEARN_MODE_ON;
553
 
2168 tk 554
    if( depressed )
555
      return 0; // ignore when button depressed
729 tk 556
 
2048 tk 557
    if( seq_ui_button_state.EDIT_PRESSED )
1142 tk 558
      return Encoder_Handler(button, 0);
559
 
560
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
561
 
562
    if( event_mode != SEQ_EVENT_MODE_Drum &&
563
    (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_303) ) {
564
 
565
      if( button == SEQ_UI_BUTTON_GP1 ) {
566
    int next_step = ui_selected_step + 1; // (required, since ui_selected_step is only u8, but we could have up to 256 steps)
567
    if( next_step >= (SEQ_CC_Get(visible_track, SEQ_CC_LENGTH)+1) )
568
      next_step = 0;
569
    ui_selected_step = next_step;
570
    ui_selected_step_view = ui_selected_step / 16;
571
    return 1; // value always changed
572
      } else if( button == SEQ_UI_BUTTON_GP2 ) {
573
    u8 trg = SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument);
574
    return Encoder_Handler(button, trg ? -1 : 1);
575
      } else if( button == SEQ_UI_BUTTON_GP3 ) {
576
    u8 trg = SEQ_TRG_AccentGet(visible_track, ui_selected_step, ui_selected_instrument);
577
    return Encoder_Handler(button, trg ? -1 : 1);
578
      } else if( button == SEQ_UI_BUTTON_GP4 ) {
579
    u8 trg = SEQ_TRG_GlideGet(visible_track, ui_selected_step, ui_selected_instrument);
580
    return Encoder_Handler(button, trg ? -1 : 1);
581
      } else if( button <= SEQ_UI_BUTTON_GP16 ) {
582
    return Encoder_Handler(button, 0);
583
      }
584
    }
585
 
586
 
2553 tk 587
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_LAYERS || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
588
      u16 num_instruments = SEQ_PAR_NumInstrumentsGet(visible_track);
589
      u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
1142 tk 590
 
2553 tk 591
      seq_ui_button_t drum_button;
592
      seq_ui_button_t step_button;
593
      seq_ui_button_t gate_button;
594
      u8 trg_button_offset;
595
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
596
    drum_button = SEQ_UI_BUTTON_GP1;
597
    step_button = SEQ_UI_BUTTON_GP2;
598
    gate_button = SEQ_UI_BUTTON_GP3;
599
    trg_button_offset = 2;
600
      } else {
601
    drum_button = 0xff; // no drum selection
602
    step_button = SEQ_UI_BUTTON_GP1;
603
    gate_button = SEQ_UI_BUTTON_GP2;
604
    trg_button_offset = 1;
605
      }
606
 
607
 
608
      if( button == drum_button ) {
609
    u8 next_instrument = ui_selected_instrument + 1;
610
    if( next_instrument >= num_instruments )
611
      next_instrument = 0;
612
    ui_selected_instrument = next_instrument;
613
    return 1; // value always changed
614
      } else if( button == step_button ) {
1142 tk 615
    int next_step = ui_selected_step + 1; // (required, since ui_selected_step is only u8, but we could have up to 256 steps)
2553 tk 616
    if( next_step >= num_steps )
1142 tk 617
      next_step = 0;
618
    ui_selected_step = next_step;
619
    ui_selected_step_view = ui_selected_step / 16;
620
    return 1; // value always changed
2553 tk 621
      } else if( button == gate_button ||
1142 tk 622
         (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG && button <= SEQ_UI_BUTTON_GP8) ) {
2553 tk 623
    u8 trg = SEQ_TRG_Get(visible_track, ui_selected_step, (u8)button-trg_button_offset, ui_selected_instrument);
1142 tk 624
    return Encoder_Handler(button, trg ? -1 : 1);
625
      } else if( button <= SEQ_UI_BUTTON_GP16 ) {
626
    return Encoder_Handler(button, 0);
627
      }
628
    }
629
 
180 tk 630
    ui_selected_step = button + ui_selected_step_view*16;
1142 tk 631
 
168 tk 632
    // toggle trigger layer
600 tk 633
    // if seq_hwcfg_button_beh.all_with_triggers set, we've three cases:
178 tk 634
    // a) ALL function active, but ALL button not pressed: invert complete trigger layer
635
    // b) ALL function active and ALL button pressed: toggle step, set remaining steps to same new value
636
    // c) ALL function not active: toggle step
2533 tk 637
    if( seq_hwcfg_button_beh.all_with_triggers && (seq_ui_button_state.CHANGE_ALL_STEPS || seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE) ) {
178 tk 638
      if( seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
639
    // b) ALL function active and ALL button pressed: toggle step, set remaining steps to same new value
303 tk 640
    u16 step = ui_selected_step;
328 tk 641
    u8 new_value = SEQ_TRG_Get(visible_track, step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
1142 tk 642
 
178 tk 643
    u8 track;
644
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
318 tk 645
      if( SEQ_UI_IsSelectedTrack(track) ) {
646
        u16 num_steps = SEQ_TRG_NumStepsGet(track);
647
        for(step=0; step<num_steps; ++step)
328 tk 648
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, ui_selected_instrument, new_value);
2230 tk 649
        SEQ_CORE_CancelSustainedNotes(track); // cancel sustain if there are no notes played by the track anymore
318 tk 650
      }
178 tk 651
      } else {
652
    // a) ALL function active, but ALL button not pressed: invert complete trigger layer
303 tk 653
    u8 track;
654
    u16 step;
178 tk 655
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
656
      if( SEQ_UI_IsSelectedTrack(track) ) {
318 tk 657
        u16 num_steps = SEQ_TRG_NumStepsGet(track);
658
        for(step=0; step<num_steps; ++step) {
328 tk 659
          u8 new_value = SEQ_TRG_Get(track, step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
660
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, ui_selected_instrument, new_value);
178 tk 661
        }
2230 tk 662
        SEQ_CORE_CancelSustainedNotes(track); // cancel sustain if there are no notes played by the track anymore
178 tk 663
      }
664
    }
665
      }
666
    } else {
667
      // c) ALL function not active: toggle step
668
      u8 track;
1142 tk 669
 
484 tk 670
      u8 new_value = SEQ_TRG_Get(visible_track, ui_selected_step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
178 tk 671
      for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
672
    if( SEQ_UI_IsSelectedTrack(track) ) {
328 tk 673
      SEQ_TRG_Set(track, ui_selected_step, ui_selected_trg_layer, ui_selected_instrument, new_value);
2230 tk 674
      SEQ_CORE_CancelSustainedNotes(track); // cancel sustain if there are no notes played by the track anymore
178 tk 675
    }
676
      }
677
    }
1142 tk 678
 
168 tk 679
    return 1; // value always changed
178 tk 680
 
168 tk 681
  } else {
682
    switch( button ) {
683
      case SEQ_UI_BUTTON_Select:
2048 tk 684
    // toggle MIDI learn
685
    if( !depressed )
686
      midi_learn_mode = (midi_learn_mode == MIDI_LEARN_MODE_ON) ? MIDI_LEARN_MODE_OFF : MIDI_LEARN_MODE_ON;
729 tk 687
    return 1; // value always changed
688
 
303 tk 689
      case SEQ_UI_BUTTON_Right: {
729 tk 690
    if( depressed ) return 0; // ignore when button depressed
691
 
303 tk 692
    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 693
    if( next_step >= (SEQ_CC_Get(visible_track, SEQ_CC_LENGTH)+1) )
303 tk 694
      next_step = 0;
695
    ui_selected_step = next_step;
168 tk 696
    ui_selected_step_view = ui_selected_step / 16;
697
    return 1; // value always changed
303 tk 698
      } break;
167 tk 699
 
168 tk 700
      case SEQ_UI_BUTTON_Left:
729 tk 701
    if( depressed ) return 0; // ignore when button depressed
702
 
168 tk 703
    if( ui_selected_step == 0 )
306 tk 704
      ui_selected_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
1142 tk 705
    else
706
      --ui_selected_step;
707
 
168 tk 708
    ui_selected_step_view = ui_selected_step / 16;
709
    return 1; // value always changed
167 tk 710
 
168 tk 711
      case SEQ_UI_BUTTON_Up:
729 tk 712
    if( depressed ) return 0; // ignore when button depressed
168 tk 713
    return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
714
 
715
      case SEQ_UI_BUTTON_Down:
729 tk 716
    if( depressed ) return 0; // ignore when button depressed
168 tk 717
    return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
1350 tk 718
 
719
      // this button is currently only notified to EDIT page
720
      case SEQ_UI_BUTTON_Edit:
721
    if( !depressed )
722
      PassiveEditEnter();
1351 tk 723
    else {
1350 tk 724
      PassiveEditTakeOver();
1351 tk 725
      edit_passive_mode = 0;
726
    }
1350 tk 727
    return 1;
168 tk 728
    }
167 tk 729
  }
730
 
168 tk 731
  return -1; // invalid or unsupported button
167 tk 732
}
733
 
734
 
735
/////////////////////////////////////////////////////////////////////////////
240 tk 736
// Global Display Handler function
167 tk 737
// IN: <high_prio>: if set, a high-priority LCD update is requested
240 tk 738
//     <edit_page>: selects the normal, or copy/paste/move/scroll view
167 tk 739
/////////////////////////////////////////////////////////////////////////////
240 tk 740
s32 SEQ_UI_EDIT_LCD_Handler(u8 high_prio, seq_ui_edit_mode_t edit_mode)
167 tk 741
{
742
  if( high_prio )
743
    return 0; // there are no high-priority updates
744
 
2101 tk 745
  if( !edit_mode && !seq_ui_button_state.EDIT_PRESSED )
746
    CheckStoreFile(); // for Datawheel mode: stored on SD Card when edit has been depressed
326 tk 747
 
2101 tk 748
 
326 tk 749
  // layout common track:
750
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
751
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
752
  // G1T1 xxxxxxxxxxxxxxx  PC:Length TA:Gate Step  1   G#1_ Vel:127_Len: 75%    xxxxx
753
  // ....
754
 
755
  // layout drum track:
756
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
757
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
758
  // G1T1 xxxxxxxxxxxxxxx  PA:Vel.   TA:Gate Step  1   G#1_ Vel:127_Len: 75%    xxxxx
759
  // ....
760
 
1142 tk 761
  // layout edit config
762
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
2050 tk 763
  // Step Trg  Layer 303                Step Datawheel:  Record   Random    Euclid   
764
  // View View View View               Select Scroll     Config  Generator Generator 
1142 tk 765
 
766
  // layout trigger view
767
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
768
  // Step Gate Acc. Roll Glide Skip R.G  R.V Note Vel. Len. Roll Note Note Note Note 
769
  //   1    *    o    o    o    o    o    o  C-3  100   75% ---- E-3  G-3  ---- ---- 
770
 
771
  // layout layer view
772
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
773
  // Step Gate Note Vel. Len. Roll Note Note Note Note Note Note Note Note Note Note 
774
  //   1    *  C-3  100   75% ---- E-3  G-3  ---- ---- ---- ---- ---- ---- ---- ---- 
775
 
776
  // layout 303 view
777
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
778
  // Step Gate Acc. Glide Oct, Key Vel. Prob  CC   CC   CC   CC   CC   CC   CC   CC  
779
  //   1    *   o     o    3    C  100  100%  64   64   64   64   64   64   64   64  
780
 
729 tk 781
  // layout step selection:
782
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
783
  //        Select the steps which should be  controlled by the ALL function:        
784
  //   *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *  
326 tk 785
 
2553 tk 786
  u8 visible_track = SEQ_UI_VisibleTrackGet();
787
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
788
 
2048 tk 789
  if( !edit_mode && seq_ui_button_state.EDIT_PRESSED ) {
2101 tk 790
    const char seq_ui_edit_datawheel_mode_str[SEQ_UI_EDIT_DATAWHEEL_MODE_NUM][11] = {
1348 tk 791
      " Cursor   ",
792
      " StepView ",
793
      " Value    ",
794
      " ParLayer ",
795
      " TrgLayer ",
796
    };
797
 
1142 tk 798
    SEQ_LCD_CursorSet(0, 0);
2553 tk 799
    if( event_mode != SEQ_EVENT_MODE_Drum ) {
800
      SEQ_LCD_PrintString("Step Trg  Layer 303                ");
801
    } else {
802
      SEQ_LCD_PrintString("Step Trg  Layer Par                ");
803
    }
804
    SEQ_LCD_PrintString("Step Datawheel:  Record   Random    Euclid   ");
1142 tk 805
    SEQ_LCD_CursorSet(0, 1);
1483 tk 806
    SEQ_LCD_PrintString("View View View View               Select");
2101 tk 807
    SEQ_LCD_PrintString((char *)seq_ui_edit_datawheel_mode_str[seq_ui_edit_datawheel_mode]);
2050 tk 808
    SEQ_LCD_PrintString("  Config  Generator Generator ");
1142 tk 809
    return 0; // no error
810
  }
811
 
812
  if( !edit_mode && seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
729 tk 813
    int step;
814
 
815
    SEQ_LCD_CursorSet(0, 0);
816
    SEQ_LCD_PrintString("       Select the steps which should be  controlled by the ALL function:        ");
817
    SEQ_LCD_CursorSet(0, 1);
818
    for(step=0; step<16; ++step)
819
      SEQ_LCD_PrintFormattedString("  %c  ", (selected_steps & (1 << step)) ? '*' : 'o');
820
    return 0; // no error
821
  }
822
 
823
 
2553 tk 824
  if( event_mode != SEQ_EVENT_MODE_Drum && seq_ui_edit_view == SEQ_UI_EDIT_VIEW_303 ) {
167 tk 825
 
1142 tk 826
    // we want to show vertical bars
827
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
828
 
829
    u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
830
    // maximum 10 parameter layers
831
    if( num_p_layers >= 11 )
832
      num_p_layers = 11;
833
 
834
    ///////////////////////////////////////////////////////////////////////////
835
    SEQ_LCD_CursorSet(0, 0);
836
    SEQ_LCD_PrintString("Step Gate Acc. Glide Oct. Key ");
837
    int i;
2294 tk 838
    for(i=1; i<num_p_layers; ++i) {
839
      char str_buffer[6];
2551 tk 840
      SEQ_PAR_AssignedTypeStr(visible_track, i, ui_selected_instrument, str_buffer);
2294 tk 841
      SEQ_LCD_PrintString(str_buffer);
842
    }
1142 tk 843
 
844
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
845
 
846
    ///////////////////////////////////////////////////////////////////////////
847
    SEQ_LCD_CursorSet(0, 1);
2049 tk 848
    SEQ_LCD_PrintFormattedString((seq_record_state.ENABLED || midi_learn_mode == MIDI_LEARN_MODE_ON) ? "{%3d}" : " %3d ", ui_selected_step+1);
1142 tk 849
    SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? '*' : 'o');
850
    SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_AccentGet(visible_track, ui_selected_step, ui_selected_instrument) ? '*' : 'o');
851
    SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_GlideGet(visible_track, ui_selected_step, ui_selected_instrument) ? '*' : 'o');
852
 
1351 tk 853
    u8 note = SEQ_PAR_Get(visible_track, ui_selected_step, 0, ui_selected_instrument);
1142 tk 854
    u8 note_octave = note / 12;
855
    u8 note_key = note % 12;
856
 
857
    SEQ_LCD_PrintFormattedString(" %2d  ", (int)note_octave-2);
858
    const char note_tab[12][2] = { "C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B " };
859
    SEQ_LCD_PrintFormattedString("  %c%c ", note_tab[note_key][0], note_tab[note_key][1]);
860
 
861
    for(i=1; i<num_p_layers; ++i)
862
      if( i == ui_selected_par_layer && ui_cursor_flash )
863
    SEQ_LCD_PrintSpaces(5);
864
      else {
1351 tk 865
    int print_edit_value = PassiveEditValid() ? edit_passive_value : -1;
866
    SEQ_LCD_PrintLayerEvent(visible_track, ui_selected_step, i, ui_selected_instrument, 0, print_edit_value);
1142 tk 867
    SEQ_LCD_PrintChar(' ');
868
      }
869
 
870
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
2553 tk 871
 
1142 tk 872
    return 0;
873
  }
874
 
2553 tk 875
  if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_LAYERS || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
1142 tk 876
 
877
    // we want to show vertical bars
878
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
879
 
880
    u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
881
    u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
882
 
883
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
884
      // maximum 7 parameter layers due to "Step" item!
2553 tk 885
      // if drum: only 6 parameter layers due to additional "Drum" item!
886
      u8 max_t_layers = (event_mode == SEQ_EVENT_MODE_Drum) ? 6 : 7;
887
      if( num_t_layers >= max_t_layers )
888
    num_t_layers = max_t_layers;
1142 tk 889
 
890
      // maximum 8 parameter layers
891
      if( num_p_layers >= 8 )
892
    num_p_layers = 8;
893
    } else {
894
      // single trigger layer (gate)
895
      num_t_layers = 1;
896
 
897
      // maximum 14 parameter layers due to "Step" and "Gate" item!
2553 tk 898
      // drum mode: only 13 items
899
      u8 max_p_layers = (event_mode == SEQ_EVENT_MODE_Drum) ? 13 : 14;
900
      if( num_p_layers >= max_p_layers )
901
    num_p_layers = max_p_layers;
1142 tk 902
    }
903
 
904
    ///////////////////////////////////////////////////////////////////////////
905
    SEQ_LCD_CursorSet(0, 0);
2553 tk 906
 
907
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
908
      SEQ_LCD_PrintString("Drum ");
909
    }
910
 
1142 tk 911
    SEQ_LCD_PrintString("Step ");
912
    int i;
913
    for(i=0; i<num_t_layers; ++i)
2294 tk 914
      SEQ_LCD_PrintString(SEQ_TRG_AssignedTypeStr(visible_track, i));
1142 tk 915
 
2294 tk 916
    for(i=0; i<num_p_layers; ++i) {
917
      char str_buffer[6];
2551 tk 918
      SEQ_PAR_AssignedTypeStr(visible_track, i, ui_selected_instrument, str_buffer);
2294 tk 919
      SEQ_LCD_PrintString(str_buffer);
920
    }
921
 
1142 tk 922
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
923
 
924
    ///////////////////////////////////////////////////////////////////////////
925
    SEQ_LCD_CursorSet(0, 1);
2553 tk 926
 
927
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
928
      SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
929
    }
930
 
2049 tk 931
    SEQ_LCD_PrintFormattedString((seq_record_state.ENABLED || midi_learn_mode == MIDI_LEARN_MODE_ON) ? "{%3d}" : " %3d ", ui_selected_step+1);
1142 tk 932
    for(i=0; i<num_t_layers; ++i)
933
      SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_Get(visible_track, ui_selected_step, i, ui_selected_instrument) ? '*' : 'o');
934
    for(i=0; i<num_p_layers; ++i)
935
      if( i == ui_selected_par_layer && ui_cursor_flash )
936
    SEQ_LCD_PrintSpaces(5);
937
      else {
1351 tk 938
    int print_edit_value = PassiveEditValid() ? edit_passive_value : -1;
939
    SEQ_LCD_PrintLayerEvent(visible_track, ui_selected_step, i, ui_selected_instrument, 0, print_edit_value);
1142 tk 940
    SEQ_LCD_PrintChar(' ');
941
      }
942
 
943
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
944
 
945
    return 0;
946
  }
947
 
176 tk 948
  seq_layer_evnt_t layer_event;
336 tk 949
  SEQ_LAYER_GetEvntOfLayer(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
168 tk 950
 
333 tk 951
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
2538 tk 952
  seq_par_layer_type_t master_layer_type = SEQ_PAR_AssignmentGet(visible_track, 0); // 1st par layer is master (e.g. relevant for chords)
176 tk 953
 
167 tk 954
  ///////////////////////////////////////////////////////////////////////////
278 tk 955
  SEQ_LCD_CursorSet(0, 0);
167 tk 956
 
326 tk 957
  SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
958
  SEQ_LCD_PrintSpaces(1);
959
 
1349 tk 960
 
2166 tk 961
  u8 print_instrument = 0;
1350 tk 962
  if( ui_page == SEQ_UI_PAGE_EDIT && edit_passive_mode == 2 ) {
2166 tk 963
    if( !ui_cursor_flash ) {
1350 tk 964
      SEQ_LCD_PrintString("PASSIVE EDITING");
965
    }
2050 tk 966
  } else if( seq_record_state.ENABLED || edit_mode == SEQ_UI_EDIT_MODE_RECORD || midi_learn_mode == MIDI_LEARN_MODE_ON ) {
2166 tk 967
    if( !ui_cursor_flash ) {
2050 tk 968
      if( midi_learn_mode == MIDI_LEARN_MODE_ON ) {
969
    SEQ_LCD_PrintString("EDIT RECORDING ");
970
      } else if( seq_record_options.STEP_RECORD ) {
971
    SEQ_LCD_PrintString("STEP RECORDING ");
972
      } else {
973
    SEQ_LCD_PrintString("LIVE RECORDING ");
974
      }
1349 tk 975
    }
976
  } else {
977
    switch( edit_mode ) {
240 tk 978
    case SEQ_UI_EDIT_MODE_COPY: {
2166 tk 979
      if( !ui_cursor_flash ) {
240 tk 980
    char str_buffer[10];
981
    sprintf(str_buffer, "%d-%d", SEQ_UI_UTIL_CopyPasteBeginGet()+1, SEQ_UI_UTIL_CopyPasteEndGet()+1);
278 tk 982
    SEQ_LCD_PrintFormattedString("COPY S%-9s", str_buffer);
240 tk 983
      }
984
    } break;
167 tk 985
 
240 tk 986
    case SEQ_UI_EDIT_MODE_PASTE: {
2166 tk 987
      if( !ui_cursor_flash ) {
278 tk 988
    SEQ_LCD_PrintFormattedString("PASTE OFFS.%3d ", ui_selected_step+1);
240 tk 989
      }
990
    } break;
167 tk 991
 
240 tk 992
    case SEQ_UI_EDIT_MODE_MOVE: {
2166 tk 993
      if( !ui_cursor_flash ) {
278 tk 994
    SEQ_LCD_PrintString("MOVE STEPS     ");
240 tk 995
      }
996
    } break;
176 tk 997
 
240 tk 998
    case SEQ_UI_EDIT_MODE_SCROLL: {
2166 tk 999
      if( !ui_cursor_flash ) {
278 tk 1000
    SEQ_LCD_PrintString("SCROLL TRACK   ");
240 tk 1001
      }
1002
    } break;
176 tk 1003
 
240 tk 1004
    case SEQ_UI_EDIT_MODE_RANDOM: {
2166 tk 1005
      if( !ui_cursor_flash ) {
278 tk 1006
    SEQ_LCD_PrintString("RANDOMIZED     ");
240 tk 1007
      }
1008
    } break;
176 tk 1009
 
600 tk 1010
    case SEQ_UI_EDIT_MODE_MANUAL: {
2166 tk 1011
      if( !ui_cursor_flash ) {
600 tk 1012
    SEQ_LCD_PrintString("MANUAL TRIGGER ");
1013
      }
1014
    } break;
1015
 
240 tk 1016
    default: {
2533 tk 1017
      if( seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
1018
    if( edit_ramp ) {
1019
      SEQ_LCD_PrintString("VALUE RAMP     ");
1020
    } else {
1021
      SEQ_LCD_PrintString("ALL VALUES     ");
1022
    }
1023
      } else if( seq_ui_button_state.CHANGE_ALL_STEPS ) {
1024
    SEQ_LCD_PrintString("RELATIVE VALUES");
1025
      } else {
1026
    print_instrument = 1;
1027
      }
326 tk 1028
    }
1349 tk 1029
    }
326 tk 1030
  }
176 tk 1031
 
2166 tk 1032
  if( print_instrument || ui_cursor_flash ) {
1033
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1034
      SEQ_LCD_PrintChar(' ');
1035
      SEQ_LCD_PrintChar(' ');
1036
      SEQ_LCD_PrintMIDIOutPort(SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT));
1037
      SEQ_LCD_PrintChar(' ');
1038
      SEQ_LCD_PrintFormattedString("Chn.%2d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
1039
    } else {
1040
      SEQ_LCD_PrintTrackLabel(visible_track, (char *)seq_core_trk[visible_track].name);
1041
    }
1042
  }
1043
 
326 tk 1044
  SEQ_LCD_PrintSpaces(2);
176 tk 1045
 
326 tk 1046
  SEQ_LCD_PrintChar('P');
1047
  SEQ_LCD_PrintChar('A' + ui_selected_par_layer);
1048
  SEQ_LCD_PrintChar(':');
240 tk 1049
 
2294 tk 1050
  {
1051
    char str_buffer[6];
2551 tk 1052
    SEQ_PAR_AssignedTypeStr(visible_track, ui_selected_par_layer, ui_selected_instrument, str_buffer);
2294 tk 1053
    SEQ_LCD_PrintString(str_buffer);
333 tk 1054
    SEQ_LCD_PrintSpaces(2);
176 tk 1055
  }
167 tk 1056
 
328 tk 1057
  SEQ_LCD_PrintFormattedString("T%c:%s", 'A' + ui_selected_trg_layer, SEQ_TRG_AssignedTypeStr(visible_track, ui_selected_trg_layer));
327 tk 1058
 
1059
 
167 tk 1060
  ///////////////////////////////////////////////////////////////////////////
278 tk 1061
  SEQ_LCD_CursorSet(40, 0);
167 tk 1062
 
1316 tk 1063
  SEQ_LCD_PrintFormattedString("Step%3d ", ui_selected_step+1);
167 tk 1064
 
1316 tk 1065
  if( layer_event.midi_package.event == CC ) {
1066
    mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
1067
    u8 loopback = port == 0xf0;
741 tk 1068
 
1316 tk 1069
    if( loopback )
1070
      SEQ_LCD_PrintString((char *)SEQ_CC_LABELS_Get(port, layer_event.midi_package.cc_number));
1811 tk 1071
    else {
1072
      if( layer_event.midi_package.cc_number >= 0x80 ) {
1073
    SEQ_LCD_PrintFormattedString("  CC#off");
1074
      } else {
1075
    SEQ_LCD_PrintFormattedString("  CC#%3d", layer_event.midi_package.cc_number);
1076
      }
1077
    }
1351 tk 1078
    SEQ_LCD_PrintFormattedString(" %3d ", layer_event.midi_package.value);
1079
    SEQ_LCD_PrintVBar(layer_event.midi_package.value >> 4);
1316 tk 1080
  } else {
1081
    SEQ_LCD_PrintSpaces(2);
741 tk 1082
 
1316 tk 1083
    if( layer_event.midi_package.note && layer_event.midi_package.velocity && (layer_event.len >= 0) ) {
1084
      if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator ) {
1350 tk 1085
    u8 par_value = PassiveEditValid() ? edit_passive_value : layer_event.midi_package.note;
1086
    SEQ_LCD_PrintArp(par_value);
2538 tk 1087
      } else if( layer_type == SEQ_PAR_Type_Chord1 || layer_type == SEQ_PAR_Type_Chord2 || layer_type == SEQ_PAR_Type_Chord3 ||
1088
         (layer_type == SEQ_PAR_Type_Velocity && (master_layer_type == SEQ_PAR_Type_Chord1 || master_layer_type == SEQ_PAR_Type_Chord2 || master_layer_type == SEQ_PAR_Type_Chord3)) ) {
1089
    u8 par_value;
1090
    u8 chord_set;
1350 tk 1091
 
2538 tk 1092
    if( layer_type != SEQ_PAR_Type_Velocity ) {
1093
      par_value = PassiveEditValid()
1094
        ? edit_passive_value
1095
        : SEQ_PAR_Get(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument);
2505 tk 1096
 
2538 tk 1097
      chord_set = (layer_type == SEQ_PAR_Type_Chord2) ? 1 : ((layer_type == SEQ_PAR_Type_Chord3) ? 2 : 0);
1098
    } else {
1099
      par_value = PassiveEditValid()
1100
        ? edit_passive_value
1101
        : SEQ_PAR_Get(visible_track, ui_selected_step, 0, ui_selected_instrument);
1102
 
1103
      chord_set = (master_layer_type == SEQ_PAR_Type_Chord2) ? 1 : ((master_layer_type == SEQ_PAR_Type_Chord3) ? 2 : 0);
1104
    }
1105
 
2505 tk 1106
    if( layer_type == SEQ_PAR_Type_Chord3 ) {
1107
      SEQ_LCD_PrintString(SEQ_CHORD_NameGet(chord_set, par_value));
1108
      SEQ_LCD_PrintSpaces(2);
1109
    } else {
1110
      u8 chord_ix = par_value & 0x1f;
1111
      u8 chord_oct = par_value >> 5;
1112
      SEQ_LCD_PrintString(SEQ_CHORD_NameGet(chord_set, chord_ix));
1113
      SEQ_LCD_PrintFormattedString("/%d", chord_oct);
1114
    }
1316 tk 1115
      } else {
1350 tk 1116
    u8 par_value = PassiveEditValid() ? edit_passive_value : layer_event.midi_package.note;
1117
    SEQ_LCD_PrintNote(par_value);
288 tk 1118
      }
1351 tk 1119
      SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
176 tk 1120
    }
1316 tk 1121
    else {
1122
      SEQ_LCD_PrintString("....");
1123
    }
1124
    SEQ_LCD_PrintFormattedString(" Vel:%3d", layer_event.midi_package.velocity);
176 tk 1125
  }
167 tk 1126
 
1316 tk 1127
  SEQ_LCD_PrintString(" Len:");
1128
  SEQ_LCD_PrintGatelength(layer_event.len);
167 tk 1129
 
1316 tk 1130
 
740 tk 1131
  // print flashing *LOOPED* at right corner if loop mode activated to remind that steps will be played differntly
1132
  if( (ui_cursor_flash_overrun_ctr & 1) && seq_core_state.LOOP ) {
1133
    SEQ_LCD_PrintString(" *LOOPED*");
828 tk 1134
  } else if( (ui_cursor_flash_overrun_ctr & 1) && seq_core_trk[visible_track].play_section > 0 ) {
1135
    SEQ_LCD_PrintFormattedString(" *Sect.%c*", 'A'+seq_core_trk[visible_track].play_section);
326 tk 1136
  } else {
740 tk 1137
    SEQ_LCD_PrintSpaces(4);
1138
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1139
      SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
1140
    } else {
1141
      SEQ_LCD_PrintTrackCategory(visible_track, (char *)seq_core_trk[visible_track].name);
1142
    }
180 tk 1143
  }
167 tk 1144
 
1145
  ///////////////////////////////////////////////////////////////////////////
1211 tk 1146
  // Second Line
1147
  ///////////////////////////////////////////////////////////////////////////
167 tk 1148
 
2553 tk 1149
  u8 show_drum_triggers = (event_mode == SEQ_EVENT_MODE_Drum) && (seq_ui_edit_view != SEQ_UI_EDIT_VIEW_303);
2101 tk 1150
  if( show_drum_triggers && !(edit_mode || !ui_hold_msg_ctr) ) {
1151
    if( ui_hold_msg_ctr ) {
1152
      // e.g. during recording: show drum triggers for layers which can't be recorded
1153
      show_drum_triggers =
2106 tk 1154
    !ui_hold_msg_ctr_drum_edit &&
2101 tk 1155
    layer_type != SEQ_PAR_Type_Note &&
2274 tk 1156
    layer_type != SEQ_PAR_Type_Chord1 &&
1157
    layer_type != SEQ_PAR_Type_Chord2 &&
2505 tk 1158
    layer_type != SEQ_PAR_Type_Chord3 &&
2553 tk 1159
    layer_type != SEQ_PAR_Type_Velocity;
2101 tk 1160
    }
1161
  }
335 tk 1162
 
176 tk 1163
  // extra handling for gatelength (shows vertical bars)
335 tk 1164
  if( !show_drum_triggers && layer_type == SEQ_PAR_Type_Length ) {
167 tk 1165
 
176 tk 1166
    // we want to show horizontal bars
1167
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_HBars);
167 tk 1168
 
176 tk 1169
    // initial cursor position
278 tk 1170
    SEQ_LCD_CursorSet(0, 1);
167 tk 1171
 
176 tk 1172
    // determine length of previous step (depends on selected view and track length)
1173
    int previous_step = 16*ui_selected_step_view - 1;
1174
    if( previous_step < 0 )
1175
      previous_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
1176
 
1177
    seq_layer_evnt_t layer_event;
336 tk 1178
    SEQ_LAYER_GetEvntOfLayer(visible_track, previous_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
176 tk 1179
    u16 previous_length = layer_event.len;
330 tk 1180
 
1181
    // show length of 16 steps
336 tk 1182
    u16 step;
330 tk 1183
    for(step=0; step<16; ++step) {
336 tk 1184
      u16 visible_step = step + 16*ui_selected_step_view;
1185
      SEQ_LAYER_GetEvntOfLayer(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
330 tk 1186
 
1143 tk 1187
      u8 gate = SEQ_TRG_GateGet(visible_track, visible_step, ui_selected_instrument);
1188
 
338 tk 1189
      // muted step? if previous gatelength <= 96, print spaces
1143 tk 1190
      if( (!gate || !layer_event.midi_package.velocity) && previous_length < 96 ) {
338 tk 1191
    SEQ_LCD_PrintSpaces(5);
1192
      } else {
1193
    if( layer_event.len >= 96 )
1194
      SEQ_LCD_PrintHBar(15); // glide or stretched event
2159 tk 1195
    else {
1196
      //SEQ_LCD_PrintHBar(((layer_event.len-1)*16)/100);
1197
      SEQ_LCD_PrintHBar(((layer_event.len-1)*16)/110); // so that we see a difference if note not stretched
1198
    }
330 tk 1199
      }
1143 tk 1200
      previous_length = ((gate && layer_event.midi_package.velocity) || (previous_length >= 96 && layer_event.len >= 96)) ? layer_event.len : 0;
330 tk 1201
    }
1202
 
176 tk 1203
  } else {
1204
 
335 tk 1205
    if( show_drum_triggers ) {
323 tk 1206
      // we want to show triggers
325 tk 1207
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_DrumSymbolsBig);
323 tk 1208
    } else {
1209
      // we want to show vertical bars
1210
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
1211
    }
176 tk 1212
 
1213
    // initial cursor position
278 tk 1214
    SEQ_LCD_CursorSet(0, 1);
176 tk 1215
 
323 tk 1216
    int step_region_begin;
1217
    int step_region_end;
240 tk 1218
    switch( edit_mode ) {
1219
      case SEQ_UI_EDIT_MODE_COPY:
1220
    step_region_begin = SEQ_UI_UTIL_CopyPasteBeginGet();
1221
    step_region_end = SEQ_UI_UTIL_CopyPasteEndGet();
1222
    break;
1223
      case SEQ_UI_EDIT_MODE_PASTE:
1224
    step_region_begin = ui_selected_step;
1225
    step_region_end = ui_selected_step + SEQ_UI_UTIL_CopyPasteEndGet() - SEQ_UI_UTIL_CopyPasteBeginGet();
1226
    break;
1227
      case SEQ_UI_EDIT_MODE_SCROLL:
1228
    step_region_begin = ui_selected_step;
1229
    step_region_end = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
1230
    break;
1231
      default:
336 tk 1232
    step_region_begin = ui_selected_step;
1233
    step_region_end = ui_selected_step;
240 tk 1234
    }
1235
 
336 tk 1236
    u16 step;
176 tk 1237
    for(step=0; step<16; ++step) {
336 tk 1238
      u16 visible_step = step + 16*ui_selected_step_view;
240 tk 1239
 
1240
      if( ui_cursor_flash &&
1241
      edit_mode != SEQ_UI_EDIT_MODE_NORMAL &&
1242
      visible_step >= step_region_begin && visible_step <= step_region_end ) {
1243
    SEQ_LCD_PrintSpaces(5);
1244
    continue;
1245
      }
1246
 
335 tk 1247
      if( show_drum_triggers ) {
336 tk 1248
    u8 gate_accent = SEQ_TRG_Get(visible_track, visible_step, 0, ui_selected_instrument);
328 tk 1249
    if( SEQ_TRG_NumLayersGet(visible_track) >= 2 )
336 tk 1250
      gate_accent |= SEQ_TRG_Get(visible_track, visible_step, 1, ui_selected_instrument) << 1;
335 tk 1251
 
323 tk 1252
    SEQ_LCD_PrintChar(' ');
1253
    SEQ_LCD_PrintChar(' ');
327 tk 1254
    SEQ_LCD_PrintChar(gate_accent);
323 tk 1255
    SEQ_LCD_PrintChar(' ');
1256
      } else {
1351 tk 1257
    int print_edit_value = (visible_step == edit_passive_step && PassiveEditValid()) ? edit_passive_value : -1;
1258
    SEQ_LCD_PrintLayerEvent(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument, 1, print_edit_value);
176 tk 1259
      }
1260
 
2101 tk 1261
      {
2049 tk 1262
    u8 midi_learn = seq_record_state.ENABLED || midi_learn_mode == MIDI_LEARN_MODE_ON;
1263
    char lbr = midi_learn ? '}' : '<';
1264
    char rbr = midi_learn ? '{' : '>';
2047 tk 1265
 
1266
    SEQ_LCD_PrintChar((visible_step == step_region_end) ? lbr
1267
              : ((visible_step == (step_region_begin-1)) ? rbr : ' '));
323 tk 1268
      }
240 tk 1269
 
176 tk 1270
    }
167 tk 1271
  }
1272
 
1273
  return 0; // no error
1274
}
1275
 
1276
 
1277
/////////////////////////////////////////////////////////////////////////////
240 tk 1278
// Local Display Handler function
1279
// IN: <high_prio>: if set, a high-priority LCD update is requested
1280
/////////////////////////////////////////////////////////////////////////////
1281
static s32 LCD_Handler(u8 high_prio)
1282
{
1283
  return SEQ_UI_EDIT_LCD_Handler(high_prio, SEQ_UI_EDIT_MODE_NORMAL);
1284
}
1285
 
1286
 
1287
/////////////////////////////////////////////////////////////////////////////
2047 tk 1288
// MIDI IN
1289
/////////////////////////////////////////////////////////////////////////////
1290
static s32 MIDI_IN_Handler(mios32_midi_port_t port, mios32_midi_package_t p)
1291
{
1292
  if( midi_learn_mode == MIDI_LEARN_MODE_ON ) {
2048 tk 1293
    u8 visible_track = SEQ_UI_VisibleTrackGet();
1294
 
2047 tk 1295
    // quick & dirty for evaluation purposes
1296
    seq_record_options_t prev_seq_record_options = seq_record_options;
2168 tk 1297
    u8 reset_timestamps = p.type == NoteOn && p.velocity > 0;
2047 tk 1298
 
1299
    seq_record_options.ALL = 0;
1300
    seq_record_options.STEP_RECORD = 1;
1301
    seq_record_options.FWD_MIDI = prev_seq_record_options.FWD_MIDI;
1302
 
2168 tk 1303
    SEQ_RECORD_Enable(1, reset_timestamps);
2047 tk 1304
 
2048 tk 1305
    SEQ_RECORD_Receive(p, visible_track);
2047 tk 1306
 
2048 tk 1307
    if( seq_ui_button_state.CHANGE_ALL_STEPS ) {
1308
      // copy matching par layers into remaining steps
1309
      u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
1310
      u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1311
 
1312
      seq_cc_trk_t *tcc = &seq_cc_trk[visible_track];
1313
      seq_par_layer_type_t rec_layer_type = tcc->lay_const[ui_selected_par_layer];
1314
 
1315
      {
1316
    u8 p_layer;
1317
    for(p_layer=0; p_layer<num_p_layers; ++p_layer) {
1318
      seq_par_layer_type_t layer_type = tcc->lay_const[p_layer];
1319
 
1320
      if( layer_type == rec_layer_type ||
2505 tk 1321
          ((rec_layer_type == SEQ_PAR_Type_Note || rec_layer_type == SEQ_PAR_Type_Chord1 || rec_layer_type == SEQ_PAR_Type_Chord2 || rec_layer_type == SEQ_PAR_Type_Chord3) && (layer_type == SEQ_PAR_Type_Velocity || layer_type == SEQ_PAR_Type_Length)) ) {
2166 tk 1322
        u8 value = SEQ_PAR_Get(visible_track, ui_selected_step, p_layer, ui_selected_instrument);
2048 tk 1323
 
1324
        u16 step;
1325
        for(step=0; step<num_steps; ++step) {
2166 tk 1326
          if( step != ui_selected_step && (selected_steps & (1 << (step % 16))) ) {
2048 tk 1327
        SEQ_PAR_Set(visible_track, step, p_layer, ui_selected_instrument, value);
1328
          }
1329
        }
1330
      }
1331
    }
1332
      }
1333
    }
1334
 
2047 tk 1335
    seq_record_options.ALL = prev_seq_record_options.ALL;
2168 tk 1336
    SEQ_RECORD_Enable(0, 0);
2047 tk 1337
 
2106 tk 1338
    ui_hold_msg_ctr_drum_edit = 0;
1339
 
2047 tk 1340
    seq_ui_display_update_req = 1;
2166 tk 1341
 
1342
    return 1; // don't continue recording/live forwarding processing
2047 tk 1343
  }
1344
 
1345
  return 0;
1346
}
1347
 
1348
 
1349
/////////////////////////////////////////////////////////////////////////////
2101 tk 1350
// Stores config file if required
1351
/////////////////////////////////////////////////////////////////////////////
1352
static s32 CheckStoreFile(void)
1353
{
2102 tk 1354
  if( ui_store_file_required ) {
2101 tk 1355
    // write config file
1356
    MUTEX_SDCARD_TAKE;
1357
    s32 status;
1358
    if( (status=SEQ_FILE_GC_Write()) < 0 )
1359
      SEQ_UI_SDCardErrMsg(2000, status);
1360
    MUTEX_SDCARD_GIVE;
1361
 
2102 tk 1362
    ui_store_file_required = 0;
2101 tk 1363
  }
1364
 
1365
  return 0; // no error
1366
}
1367
 
1368
 
1369
/////////////////////////////////////////////////////////////////////////////
2050 tk 1370
// Exit
1371
/////////////////////////////////////////////////////////////////////////////
1372
static s32 EXIT_Handler(void)
1373
{
1374
  midi_learn_mode = MIDI_LEARN_MODE_OFF;
2101 tk 1375
 
1376
  CheckStoreFile();
1377
 
2050 tk 1378
  return 0;
1379
}
1380
 
1381
/////////////////////////////////////////////////////////////////////////////
167 tk 1382
// Initialisation
1383
/////////////////////////////////////////////////////////////////////////////
1384
s32 SEQ_UI_EDIT_Init(u32 mode)
1385
{
1386
  // install callback routines
758 tk 1387
  SEQ_UI_InstallButtonCallback(SEQ_UI_EDIT_Button_Handler);
168 tk 1388
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
240 tk 1389
  SEQ_UI_InstallLEDCallback(SEQ_UI_EDIT_LED_Handler);
168 tk 1390
  SEQ_UI_InstallLCDCallback(LCD_Handler);
2047 tk 1391
  SEQ_UI_InstallMIDIINCallback(MIDI_IN_Handler);
2050 tk 1392
  SEQ_UI_InstallExitCallback(EXIT_Handler);
167 tk 1393
 
2047 tk 1394
  // disable MIDI learn mode by default
1395
  midi_learn_mode = MIDI_LEARN_MODE_OFF;
1396
 
2106 tk 1397
  ui_hold_msg_ctr_drum_edit = 0;
1398
 
1350 tk 1399
  edit_passive_mode = 0;
2533 tk 1400
  edit_ramp = 0;
729 tk 1401
 
1142 tk 1402
  if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL )
1403
    seq_ui_edit_view = SEQ_UI_EDIT_VIEW_STEPS;
1404
 
167 tk 1405
  return 0; // no error
1406
}
178 tk 1407
 
1408
 
1409
 
1410
/////////////////////////////////////////////////////////////////////////////
1411
// help function to change/set a single encoder value
1412
// if forced_value >= 0: new value will be set to the given value
1413
// if forced_value < 0: new value will be changed via incrementer
1414
// returns >= 0 if new value has been set (value change)
1415
// returns < 0 if no change
1416
/////////////////////////////////////////////////////////////////////////////
1052 tk 1417
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 1418
{
333 tk 1419
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(track, ui_selected_par_layer);
335 tk 1420
  u8 visible_track = SEQ_UI_VisibleTrackGet();
178 tk 1421
 
828 tk 1422
#if 0
1423
  // disabled in MBSEQ V4.0beta15 due to issue reported by Gridracer:
1424
  // http://midibox.org/forums/index.php?/topic/13137-midibox-seq-v4-beta-release-feedback/page__st__100
1425
 
333 tk 1426
  // if note/chord/velocity parameter: only change gate if requested
2505 tk 1427
  if( (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord1 || layer_type == SEQ_PAR_Type_Chord2 || layer_type == SEQ_PAR_Type_Chord3 || layer_type == SEQ_PAR_Type_Velocity) &&
178 tk 1428
      !change_gate &&
652 tk 1429
      !SEQ_TRG_GateGet(track, trg_step, ui_selected_instrument) )
178 tk 1430
    return -1;
828 tk 1431
#endif
178 tk 1432
 
1052 tk 1433
  if( layer_type == SEQ_PAR_Type_Probability ) {
1434
    // due to another issue reported by Gridracer:
1435
    // invert incrementer so that clockwise move increases probability
1436
    incrementer = -incrementer;
1437
  }
1438
 
1439
 
335 tk 1440
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
652 tk 1441
  if( event_mode == SEQ_EVENT_MODE_Drum ) {
335 tk 1442
    ui_hold_msg_ctr = 1000; // show value for 1 second
2106 tk 1443
    ui_hold_msg_ctr_drum_edit = 1;
1444
  } else {
1445
    ui_hold_msg_ctr_drum_edit = 0;
652 tk 1446
  }
335 tk 1447
 
652 tk 1448
  s32 old_value = SEQ_PAR_Get(track, par_step, ui_selected_par_layer, ui_selected_instrument);
178 tk 1449
  s32 new_value = (forced_value >= 0) ? forced_value : (old_value + incrementer);
1450
  if( new_value < 0 )
1451
    new_value = 0;
2448 tk 1452
  else {
1453
    // limit depending on max value
2435 tk 1454
    seq_par_layer_type_t par_layer_type = SEQ_PAR_AssignmentGet(track, ui_selected_par_layer);
2448 tk 1455
    u8 max = SEQ_PAR_MaxValueGet(par_layer_type);
2435 tk 1456
 
2448 tk 1457
    if( new_value >= max ) {
1458
      new_value = max;
2435 tk 1459
    }
1460
  }
178 tk 1461
 
1143 tk 1462
  // extra for more comfortable editing of multi-note tracks:
1463
  // if assigned parameter layer is Note or Chord, and currently 0, re-start at C-3 resp. A/2
1464
  // when value is incremented
2505 tk 1465
  if( incrementer > 0 && forced_value < 0 && old_value == 0x00 && (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord1 || layer_type == SEQ_PAR_Type_Chord2 || layer_type == SEQ_PAR_Type_Chord3) )
1143 tk 1466
    new_value = (layer_type == SEQ_PAR_Type_Note && SEQ_CC_Get(track, SEQ_CC_MODE) != SEQ_CORE_TRKMODE_Arpeggiator) ? 0x3c : 0x40;
1467
 
1345 tk 1468
  if( !dont_change_gate ) {
1469
    u8 event_mode = SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
1470
 
1471
    // we do this always regardless if value has been changed or not (e.g. increment if value already 127)
1472
    if( event_mode == SEQ_EVENT_MODE_CC && layer_type == SEQ_PAR_Type_CC ) {
1473
      // in this mode gates are used to disable CC
1474
      // if a CC value has been changed, set gate
1475
      SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 1);
1476
    }
1477
  }
1478
 
178 tk 1479
  // take over if changed
1480
  if( new_value == old_value )
1481
    return -1;
1482
 
652 tk 1483
  SEQ_PAR_Set(track, par_step, ui_selected_par_layer, ui_selected_instrument, (u8)new_value);
178 tk 1484
 
747 tk 1485
  if( !dont_change_gate &&
2505 tk 1486
      (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord1 || layer_type == SEQ_PAR_Type_Chord2 || layer_type == SEQ_PAR_Type_Chord3 || layer_type == SEQ_PAR_Type_Velocity) ) {
178 tk 1487
    // (de)activate gate depending on value
1488
    if( new_value )
652 tk 1489
      SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 1);
1053 tk 1490
    else {
1491
      // due to another issue reported by Gridracer:
1492
      // if the track plays multiple notes, only clear gate if all notes are 0
1142 tk 1493
      u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1053 tk 1494
      u8 allNotesZero = 1;
1495
      int i;
1142 tk 1496
      for(i=0; i<num_p_layers; ++i) {
1053 tk 1497
    seq_par_layer_type_t localLayerType = SEQ_PAR_AssignmentGet(track, i);
2505 tk 1498
    if( (localLayerType == SEQ_PAR_Type_Note || localLayerType == SEQ_PAR_Type_Chord1 || localLayerType == SEQ_PAR_Type_Chord2 || localLayerType == SEQ_PAR_Type_Chord3) &&
1053 tk 1499
        SEQ_PAR_Get(track, par_step, i, ui_selected_instrument) > 0 ) {
1500
      allNotesZero = 0;
1501
      break;
1502
    }
1503
      }
1504
 
1505
      if( allNotesZero )
1506
    SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 0);
1507
    }
178 tk 1508
  }
1509
 
1510
  return new_value;
1511
}
1350 tk 1512
 
1513
 
1514
/////////////////////////////////////////////////////////////////////////////
1515
// help functions for "passive edit mode"
1516
/////////////////////////////////////////////////////////////////////////////
1517
static s32 PassiveEditEnter(void)
1518
{
1519
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1351 tk 1520
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
1350 tk 1521
 
1351 tk 1522
  // passive edit mode currently only supported for notes/chords
1350 tk 1523
 
2505 tk 1524
  if( layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord1 || layer_type == SEQ_PAR_Type_Chord2 || layer_type == SEQ_PAR_Type_Chord3 ) {
1351 tk 1525
    // enter passive edit mode and store track/step/layer/instrument for later checks
1526
    edit_passive_mode = 1;
1527
    edit_passive_track = visible_track;
1528
    edit_passive_step = ui_selected_step;
1529
    edit_passive_par_layer = ui_selected_par_layer;
1530
    edit_passive_instrument = ui_selected_instrument;
1531
    edit_passive_value = SEQ_PAR_Get(edit_passive_track, edit_passive_step, edit_passive_par_layer, edit_passive_instrument);
1532
  } else {
1533
    edit_passive_mode = 0;
1534
  }
1535
 
1350 tk 1536
  return 0; // no error
1537
}
1538
 
1539
static s32 PassiveEditValid(void)
1540
{
1541
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1542
 
1543
  return (edit_passive_mode == 2 && // if mode is 2, the value has been changed!
1544
      edit_passive_track == visible_track &&
1545
      edit_passive_step == ui_selected_step &&
1546
      edit_passive_par_layer == ui_selected_par_layer &&
1547
      edit_passive_instrument == ui_selected_instrument) ? 1 : 0;
1548
}
1549
 
1550
static s32 PassiveEditTakeOver(void)
1551
{
1552
 
1553
  // only take over changed value if track/step/layer/instrument still passing
1554
  if( PassiveEditValid() ) {
1555
    // take over change
1556
    // handle it like a single increment/decrement so that no code needs to be duplicated
1557
    int current_value = SEQ_PAR_Get(edit_passive_track, edit_passive_step, edit_passive_par_layer, edit_passive_instrument);
1558
    int incrementer = (int)edit_passive_value - current_value;
1559
 
2048 tk 1560
    seq_ui_button_state.EDIT_PRESSED = 0; // just to avoid any overlay...
1350 tk 1561
    edit_passive_mode = 0; // to avoid recursion in encoder handler
1562
    Encoder_Handler(edit_passive_step % 16, incrementer);
1563
  } else {
1564
    edit_passive_mode = 1;
1565
  }
1566
 
1567
  return 0; // no error
1568
}