Subversion Repositories svn.mios32

Rev

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