Subversion Repositories svn.mios32

Rev

Rev 2049 | Rev 2063 | 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 2050 2014-09-08 19:52:27Z 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
 
522
    // enable/disable MIDI Learn mode
523
    midi_learn_mode = depressed ? MIDI_LEARN_MODE_OFF : MIDI_LEARN_MODE_ON;
524
 
729 tk 525
    if( depressed ) return 0; // ignore when button depressed
526
 
2048 tk 527
    if( seq_ui_button_state.EDIT_PRESSED )
1142 tk 528
      return Encoder_Handler(button, 0);
529
 
2048 tk 530
#if 0
531
    // conflicts with new MIDI learn
1751 tk 532
    if( (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPS && seq_ui_button_state.CHANGE_ALL_STEPS) ||
533
    seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
729 tk 534
      selected_steps ^= (1 << button);
535
      return 1; // value changed
536
    }
2048 tk 537
#else
538
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
539
      selected_steps ^= (1 << button);
540
      return 1; // value changed
541
    }
542
#endif
729 tk 543
 
1142 tk 544
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
545
 
546
    if( event_mode != SEQ_EVENT_MODE_Drum &&
547
    (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_303) ) {
548
 
549
      if( button == SEQ_UI_BUTTON_GP1 ) {
550
    int next_step = ui_selected_step + 1; // (required, since ui_selected_step is only u8, but we could have up to 256 steps)
551
    if( next_step >= (SEQ_CC_Get(visible_track, SEQ_CC_LENGTH)+1) )
552
      next_step = 0;
553
    ui_selected_step = next_step;
554
    ui_selected_step_view = ui_selected_step / 16;
555
    return 1; // value always changed
556
      } else if( button == SEQ_UI_BUTTON_GP2 ) {
557
    u8 trg = SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument);
558
    return Encoder_Handler(button, trg ? -1 : 1);
559
      } else if( button == SEQ_UI_BUTTON_GP3 ) {
560
    u8 trg = SEQ_TRG_AccentGet(visible_track, ui_selected_step, ui_selected_instrument);
561
    return Encoder_Handler(button, trg ? -1 : 1);
562
      } else if( button == SEQ_UI_BUTTON_GP4 ) {
563
    u8 trg = SEQ_TRG_GlideGet(visible_track, ui_selected_step, ui_selected_instrument);
564
    return Encoder_Handler(button, trg ? -1 : 1);
565
      } else if( button <= SEQ_UI_BUTTON_GP16 ) {
566
    return Encoder_Handler(button, 0);
567
      }
568
    }
569
 
570
 
571
    if( event_mode != SEQ_EVENT_MODE_Drum &&
572
      (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_LAYERS || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG) ) {
573
 
574
      if( button == SEQ_UI_BUTTON_GP1 ) {
575
    int next_step = ui_selected_step + 1; // (required, since ui_selected_step is only u8, but we could have up to 256 steps)
576
    if( next_step >= (SEQ_CC_Get(visible_track, SEQ_CC_LENGTH)+1) )
577
      next_step = 0;
578
    ui_selected_step = next_step;
579
    ui_selected_step_view = ui_selected_step / 16;
580
    return 1; // value always changed
581
      } else if( button == SEQ_UI_BUTTON_GP2 ||
582
         (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG && button <= SEQ_UI_BUTTON_GP8) ) {
583
    u8 trg = SEQ_TRG_Get(visible_track, ui_selected_step, (u8)button-1, ui_selected_instrument);
584
    return Encoder_Handler(button, trg ? -1 : 1);
585
      } else if( button <= SEQ_UI_BUTTON_GP16 ) {
586
    return Encoder_Handler(button, 0);
587
      }
588
    }
589
 
180 tk 590
    ui_selected_step = button + ui_selected_step_view*16;
1142 tk 591
 
168 tk 592
    // toggle trigger layer
600 tk 593
    // if seq_hwcfg_button_beh.all_with_triggers set, we've three cases:
178 tk 594
    // a) ALL function active, but ALL button not pressed: invert complete trigger layer
595
    // b) ALL function active and ALL button pressed: toggle step, set remaining steps to same new value
596
    // c) ALL function not active: toggle step
600 tk 597
    if( seq_hwcfg_button_beh.all_with_triggers && seq_ui_button_state.CHANGE_ALL_STEPS ) {
178 tk 598
      if( seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
599
    // b) ALL function active and ALL button pressed: toggle step, set remaining steps to same new value
303 tk 600
    u16 step = ui_selected_step;
328 tk 601
    u8 new_value = SEQ_TRG_Get(visible_track, step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
1142 tk 602
 
178 tk 603
    u8 track;
604
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
318 tk 605
      if( SEQ_UI_IsSelectedTrack(track) ) {
606
        u16 num_steps = SEQ_TRG_NumStepsGet(track);
607
        for(step=0; step<num_steps; ++step)
328 tk 608
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, ui_selected_instrument, new_value);
318 tk 609
      }
178 tk 610
      } else {
611
    // a) ALL function active, but ALL button not pressed: invert complete trigger layer
303 tk 612
    u8 track;
613
    u16 step;
178 tk 614
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
615
      if( SEQ_UI_IsSelectedTrack(track) ) {
318 tk 616
        u16 num_steps = SEQ_TRG_NumStepsGet(track);
617
        for(step=0; step<num_steps; ++step) {
328 tk 618
          u8 new_value = SEQ_TRG_Get(track, step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
619
          SEQ_TRG_Set(track, step, ui_selected_trg_layer, ui_selected_instrument, new_value);
178 tk 620
        }
621
      }
622
    }
623
      }
624
    } else {
625
      // c) ALL function not active: toggle step
626
      u8 track;
1142 tk 627
 
484 tk 628
      u8 new_value = SEQ_TRG_Get(visible_track, ui_selected_step, ui_selected_trg_layer, ui_selected_instrument) ? 0 : 1;
178 tk 629
      for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
630
    if( SEQ_UI_IsSelectedTrack(track) ) {
328 tk 631
      SEQ_TRG_Set(track, ui_selected_step, ui_selected_trg_layer, ui_selected_instrument, new_value);
178 tk 632
    }
633
      }
634
    }
1142 tk 635
 
168 tk 636
    return 1; // value always changed
178 tk 637
 
168 tk 638
  } else {
639
    switch( button ) {
640
      case SEQ_UI_BUTTON_Select:
2048 tk 641
    // toggle MIDI learn
642
    if( !depressed )
643
      midi_learn_mode = (midi_learn_mode == MIDI_LEARN_MODE_ON) ? MIDI_LEARN_MODE_OFF : MIDI_LEARN_MODE_ON;
729 tk 644
    return 1; // value always changed
645
 
303 tk 646
      case SEQ_UI_BUTTON_Right: {
729 tk 647
    if( depressed ) return 0; // ignore when button depressed
648
 
303 tk 649
    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 650
    if( next_step >= (SEQ_CC_Get(visible_track, SEQ_CC_LENGTH)+1) )
303 tk 651
      next_step = 0;
652
    ui_selected_step = next_step;
168 tk 653
    ui_selected_step_view = ui_selected_step / 16;
654
    return 1; // value always changed
303 tk 655
      } break;
167 tk 656
 
168 tk 657
      case SEQ_UI_BUTTON_Left:
729 tk 658
    if( depressed ) return 0; // ignore when button depressed
659
 
168 tk 660
    if( ui_selected_step == 0 )
306 tk 661
      ui_selected_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
1142 tk 662
    else
663
      --ui_selected_step;
664
 
168 tk 665
    ui_selected_step_view = ui_selected_step / 16;
666
    return 1; // value always changed
167 tk 667
 
168 tk 668
      case SEQ_UI_BUTTON_Up:
729 tk 669
    if( depressed ) return 0; // ignore when button depressed
168 tk 670
    return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
671
 
672
      case SEQ_UI_BUTTON_Down:
729 tk 673
    if( depressed ) return 0; // ignore when button depressed
168 tk 674
    return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
1350 tk 675
 
676
      // this button is currently only notified to EDIT page
677
      case SEQ_UI_BUTTON_Edit:
678
    if( !depressed )
679
      PassiveEditEnter();
1351 tk 680
    else {
1350 tk 681
      PassiveEditTakeOver();
1351 tk 682
      edit_passive_mode = 0;
683
    }
1350 tk 684
    return 1;
168 tk 685
    }
167 tk 686
  }
687
 
168 tk 688
  return -1; // invalid or unsupported button
167 tk 689
}
690
 
691
 
692
/////////////////////////////////////////////////////////////////////////////
240 tk 693
// Global Display Handler function
167 tk 694
// IN: <high_prio>: if set, a high-priority LCD update is requested
240 tk 695
//     <edit_page>: selects the normal, or copy/paste/move/scroll view
167 tk 696
/////////////////////////////////////////////////////////////////////////////
240 tk 697
s32 SEQ_UI_EDIT_LCD_Handler(u8 high_prio, seq_ui_edit_mode_t edit_mode)
167 tk 698
{
699
  if( high_prio )
700
    return 0; // there are no high-priority updates
701
 
326 tk 702
 
703
  // layout common track:
704
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
705
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
706
  // G1T1 xxxxxxxxxxxxxxx  PC:Length TA:Gate Step  1   G#1_ Vel:127_Len: 75%    xxxxx
707
  // ....
708
 
709
  // layout drum track:
710
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
711
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
712
  // G1T1 xxxxxxxxxxxxxxx  PA:Vel.   TA:Gate Step  1   G#1_ Vel:127_Len: 75%    xxxxx
713
  // ....
714
 
1142 tk 715
  // layout edit config
716
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
2050 tk 717
  // Step Trg  Layer 303                Step Datawheel:  Record   Random    Euclid   
718
  // View View View View               Select Scroll     Config  Generator Generator 
1142 tk 719
 
720
  // layout trigger view
721
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
722
  // Step Gate Acc. Roll Glide Skip R.G  R.V Note Vel. Len. Roll Note Note Note Note 
723
  //   1    *    o    o    o    o    o    o  C-3  100   75% ---- E-3  G-3  ---- ---- 
724
 
725
  // layout layer view
726
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
727
  // Step Gate Note Vel. Len. Roll Note Note Note Note Note Note Note Note Note Note 
728
  //   1    *  C-3  100   75% ---- E-3  G-3  ---- ---- ---- ---- ---- ---- ---- ---- 
729
 
730
  // layout 303 view
731
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
732
  // Step Gate Acc. Glide Oct, Key Vel. Prob  CC   CC   CC   CC   CC   CC   CC   CC  
733
  //   1    *   o     o    3    C  100  100%  64   64   64   64   64   64   64   64  
734
 
729 tk 735
  // layout step selection:
736
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
737
  //        Select the steps which should be  controlled by the ALL function:        
738
  //   *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *  
326 tk 739
 
2048 tk 740
  if( !edit_mode && seq_ui_button_state.EDIT_PRESSED ) {
1348 tk 741
    const char datawheel_mode_str[DATAWHEEL_MODE_NUM][11] = {
742
      " Cursor   ",
743
      " StepView ",
744
      " Value    ",
745
      " ParLayer ",
746
      " TrgLayer ",
747
    };
748
 
1142 tk 749
    SEQ_LCD_CursorSet(0, 0);
2050 tk 750
    SEQ_LCD_PrintString("Step Trg  Layer 303                Step Datawheel:  Record   Random    Euclid   ");
1142 tk 751
    SEQ_LCD_CursorSet(0, 1);
1483 tk 752
    SEQ_LCD_PrintString("View View View View               Select");
1348 tk 753
    SEQ_LCD_PrintString((char *)datawheel_mode_str[datawheel_mode]);
2050 tk 754
    SEQ_LCD_PrintString("  Config  Generator Generator ");
1142 tk 755
    return 0; // no error
756
  }
757
 
758
  if( !edit_mode && seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
729 tk 759
    int step;
760
 
761
    SEQ_LCD_CursorSet(0, 0);
762
    SEQ_LCD_PrintString("       Select the steps which should be  controlled by the ALL function:        ");
763
    SEQ_LCD_CursorSet(0, 1);
764
    for(step=0; step<16; ++step)
765
      SEQ_LCD_PrintFormattedString("  %c  ", (selected_steps & (1 << step)) ? '*' : 'o');
766
    return 0; // no error
767
  }
768
 
769
 
167 tk 770
  u8 visible_track = SEQ_UI_VisibleTrackGet();
323 tk 771
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
167 tk 772
 
1142 tk 773
 
1316 tk 774
  if( !edit_mode && event_mode != SEQ_EVENT_MODE_Drum &&
1142 tk 775
      (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_303) ) {
776
    // we want to show vertical bars
777
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
778
 
779
    u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
780
    // maximum 10 parameter layers
781
    if( num_p_layers >= 11 )
782
      num_p_layers = 11;
783
 
784
    ///////////////////////////////////////////////////////////////////////////
785
    SEQ_LCD_CursorSet(0, 0);
786
    SEQ_LCD_PrintString("Step Gate Acc. Glide Oct. Key ");
787
    int i;
788
    for(i=1; i<num_p_layers; ++i)
789
    SEQ_LCD_PrintString((char *)SEQ_PAR_AssignedTypeStr(visible_track, i));
790
 
791
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
792
 
793
    ///////////////////////////////////////////////////////////////////////////
794
    SEQ_LCD_CursorSet(0, 1);
2049 tk 795
    SEQ_LCD_PrintFormattedString((seq_record_state.ENABLED || midi_learn_mode == MIDI_LEARN_MODE_ON) ? "{%3d}" : " %3d ", ui_selected_step+1);
1142 tk 796
    SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? '*' : 'o');
797
    SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_AccentGet(visible_track, ui_selected_step, ui_selected_instrument) ? '*' : 'o');
798
    SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_GlideGet(visible_track, ui_selected_step, ui_selected_instrument) ? '*' : 'o');
799
 
1351 tk 800
    u8 note = SEQ_PAR_Get(visible_track, ui_selected_step, 0, ui_selected_instrument);
1142 tk 801
    u8 note_octave = note / 12;
802
    u8 note_key = note % 12;
803
 
804
    SEQ_LCD_PrintFormattedString(" %2d  ", (int)note_octave-2);
805
    const char note_tab[12][2] = { "C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B " };
806
    SEQ_LCD_PrintFormattedString("  %c%c ", note_tab[note_key][0], note_tab[note_key][1]);
807
 
808
    for(i=1; i<num_p_layers; ++i)
809
      if( i == ui_selected_par_layer && ui_cursor_flash )
810
    SEQ_LCD_PrintSpaces(5);
811
      else {
1351 tk 812
    int print_edit_value = PassiveEditValid() ? edit_passive_value : -1;
813
    SEQ_LCD_PrintLayerEvent(visible_track, ui_selected_step, i, ui_selected_instrument, 0, print_edit_value);
1142 tk 814
    SEQ_LCD_PrintChar(' ');
815
      }
816
 
817
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
818
 
819
    return 0;
820
  }
821
 
1316 tk 822
  if( !edit_mode && event_mode != SEQ_EVENT_MODE_Drum &&
1142 tk 823
      (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_LAYERS || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG) ) {
824
 
825
    // we want to show vertical bars
826
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
827
 
828
    u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
829
    u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
830
 
831
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
832
      // maximum 7 parameter layers due to "Step" item!
833
      if( num_t_layers >= 7 )
834
    num_t_layers = 7;
835
 
836
      // maximum 8 parameter layers
837
      if( num_p_layers >= 8 )
838
    num_p_layers = 8;
839
    } else {
840
      // single trigger layer (gate)
841
      num_t_layers = 1;
842
 
843
      // maximum 14 parameter layers due to "Step" and "Gate" item!
844
      if( num_p_layers >= 14 )
845
    num_p_layers = 14;
846
    }
847
 
848
    ///////////////////////////////////////////////////////////////////////////
849
    SEQ_LCD_CursorSet(0, 0);
850
    SEQ_LCD_PrintString("Step ");
851
    int i;
852
    for(i=0; i<num_t_layers; ++i)
853
    SEQ_LCD_PrintString(SEQ_TRG_AssignedTypeStr(visible_track, i));
854
    for(i=0; i<num_p_layers; ++i)
855
    SEQ_LCD_PrintString((char *)SEQ_PAR_AssignedTypeStr(visible_track, i));
856
 
857
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
858
 
859
    ///////////////////////////////////////////////////////////////////////////
860
    SEQ_LCD_CursorSet(0, 1);
2049 tk 861
    SEQ_LCD_PrintFormattedString((seq_record_state.ENABLED || midi_learn_mode == MIDI_LEARN_MODE_ON) ? "{%3d}" : " %3d ", ui_selected_step+1);
1142 tk 862
    for(i=0; i<num_t_layers; ++i)
863
      SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_Get(visible_track, ui_selected_step, i, ui_selected_instrument) ? '*' : 'o');
864
    for(i=0; i<num_p_layers; ++i)
865
      if( i == ui_selected_par_layer && ui_cursor_flash )
866
    SEQ_LCD_PrintSpaces(5);
867
      else {
1351 tk 868
    int print_edit_value = PassiveEditValid() ? edit_passive_value : -1;
869
    SEQ_LCD_PrintLayerEvent(visible_track, ui_selected_step, i, ui_selected_instrument, 0, print_edit_value);
1142 tk 870
    SEQ_LCD_PrintChar(' ');
871
      }
872
 
873
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
874
 
875
    return 0;
876
  }
877
 
176 tk 878
  seq_layer_evnt_t layer_event;
336 tk 879
  SEQ_LAYER_GetEvntOfLayer(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
168 tk 880
 
333 tk 881
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
176 tk 882
 
333 tk 883
  // TODO: tmp. solution to print chord velocity correctly
884
  if( layer_type == SEQ_PAR_Type_Velocity && (seq_cc_trk[visible_track].link_par_layer_chord == 0) )
885
    layer_type = SEQ_PAR_Type_Chord;
326 tk 886
 
333 tk 887
 
167 tk 888
  ///////////////////////////////////////////////////////////////////////////
278 tk 889
  SEQ_LCD_CursorSet(0, 0);
167 tk 890
 
326 tk 891
  SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
892
  SEQ_LCD_PrintSpaces(1);
893
 
1349 tk 894
 
1350 tk 895
  if( ui_page == SEQ_UI_PAGE_EDIT && edit_passive_mode == 2 ) {
1349 tk 896
    if( ui_cursor_flash ) {
897
      SEQ_LCD_PrintSpaces(15);
898
    } else {
1350 tk 899
      SEQ_LCD_PrintString("PASSIVE EDITING");
900
    }
2050 tk 901
  } else if( seq_record_state.ENABLED || edit_mode == SEQ_UI_EDIT_MODE_RECORD || midi_learn_mode == MIDI_LEARN_MODE_ON ) {
1350 tk 902
    if( ui_cursor_flash ) {
903
      SEQ_LCD_PrintSpaces(15);
904
    } else {
2050 tk 905
      if( midi_learn_mode == MIDI_LEARN_MODE_ON ) {
906
    SEQ_LCD_PrintString("EDIT RECORDING ");
907
      } else if( seq_record_options.STEP_RECORD ) {
908
    SEQ_LCD_PrintString("STEP RECORDING ");
909
      } else {
910
    SEQ_LCD_PrintString("LIVE RECORDING ");
911
      }
1349 tk 912
    }
913
  } else {
914
    switch( edit_mode ) {
240 tk 915
    case SEQ_UI_EDIT_MODE_COPY: {
916
      if( ui_cursor_flash ) {
917
    SEQ_LCD_PrintSpaces(15);
918
      } else {
919
    char str_buffer[10];
920
    sprintf(str_buffer, "%d-%d", SEQ_UI_UTIL_CopyPasteBeginGet()+1, SEQ_UI_UTIL_CopyPasteEndGet()+1);
278 tk 921
    SEQ_LCD_PrintFormattedString("COPY S%-9s", str_buffer);
240 tk 922
      }
923
    } break;
167 tk 924
 
240 tk 925
    case SEQ_UI_EDIT_MODE_PASTE: {
926
      if( ui_cursor_flash ) {
927
    SEQ_LCD_PrintSpaces(15);
928
      } else {
278 tk 929
    SEQ_LCD_PrintFormattedString("PASTE OFFS.%3d ", ui_selected_step+1);
240 tk 930
      }
931
    } break;
167 tk 932
 
240 tk 933
    case SEQ_UI_EDIT_MODE_MOVE: {
934
      if( ui_cursor_flash ) {
935
    SEQ_LCD_PrintSpaces(15);
936
      } else {
278 tk 937
    SEQ_LCD_PrintString("MOVE STEPS     ");
240 tk 938
      }
939
    } break;
176 tk 940
 
240 tk 941
    case SEQ_UI_EDIT_MODE_SCROLL: {
942
      if( ui_cursor_flash ) {
943
    SEQ_LCD_PrintSpaces(15);
944
      } else {
278 tk 945
    SEQ_LCD_PrintString("SCROLL TRACK   ");
240 tk 946
      }
947
    } break;
176 tk 948
 
240 tk 949
    case SEQ_UI_EDIT_MODE_RANDOM: {
950
      if( ui_cursor_flash ) {
951
    SEQ_LCD_PrintSpaces(15);
952
      } else {
278 tk 953
    SEQ_LCD_PrintString("RANDOMIZED     ");
240 tk 954
      }
955
    } break;
176 tk 956
 
600 tk 957
    case SEQ_UI_EDIT_MODE_MANUAL: {
958
      if( ui_cursor_flash ) {
959
    SEQ_LCD_PrintSpaces(15);
960
      } else {
961
    SEQ_LCD_PrintString("MANUAL TRIGGER ");
962
      }
963
    } break;
964
 
240 tk 965
    default: {
326 tk 966
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
967
    SEQ_LCD_PrintChar(' ');
968
    SEQ_LCD_PrintChar(' ');
969
    SEQ_LCD_PrintMIDIOutPort(SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT));
970
    SEQ_LCD_PrintChar(' ');
971
    SEQ_LCD_PrintFormattedString("Chn.%2d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
972
      } else {
973
    SEQ_LCD_PrintTrackLabel(visible_track, (char *)seq_core_trk[visible_track].name);
974
      }
975
    }
1349 tk 976
    }
326 tk 977
  }
176 tk 978
 
326 tk 979
  SEQ_LCD_PrintSpaces(2);
176 tk 980
 
326 tk 981
  SEQ_LCD_PrintChar('P');
982
  SEQ_LCD_PrintChar('A' + ui_selected_par_layer);
983
  SEQ_LCD_PrintChar(':');
240 tk 984
 
1316 tk 985
  if( layer_type == SEQ_PAR_Type_CC ) {
1811 tk 986
    if( layer_event.midi_package.cc_number >= 0x80 ) {
987
      SEQ_LCD_PrintFormattedString("CC#off ");
988
    } else {
989
      SEQ_LCD_PrintFormattedString("CC#%3d ", layer_event.midi_package.cc_number);
990
    }
333 tk 991
  } else {
992
    SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, ui_selected_par_layer));
993
    SEQ_LCD_PrintSpaces(2);
176 tk 994
  }
167 tk 995
 
328 tk 996
  SEQ_LCD_PrintFormattedString("T%c:%s", 'A' + ui_selected_trg_layer, SEQ_TRG_AssignedTypeStr(visible_track, ui_selected_trg_layer));
327 tk 997
 
998
 
167 tk 999
  ///////////////////////////////////////////////////////////////////////////
278 tk 1000
  SEQ_LCD_CursorSet(40, 0);
167 tk 1001
 
1316 tk 1002
  SEQ_LCD_PrintFormattedString("Step%3d ", ui_selected_step+1);
167 tk 1003
 
1316 tk 1004
  if( layer_event.midi_package.event == CC ) {
1005
    mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
1006
    u8 loopback = port == 0xf0;
741 tk 1007
 
1316 tk 1008
    if( loopback )
1009
      SEQ_LCD_PrintString((char *)SEQ_CC_LABELS_Get(port, layer_event.midi_package.cc_number));
1811 tk 1010
    else {
1011
      if( layer_event.midi_package.cc_number >= 0x80 ) {
1012
    SEQ_LCD_PrintFormattedString("  CC#off");
1013
      } else {
1014
    SEQ_LCD_PrintFormattedString("  CC#%3d", layer_event.midi_package.cc_number);
1015
      }
1016
    }
1351 tk 1017
    SEQ_LCD_PrintFormattedString(" %3d ", layer_event.midi_package.value);
1018
    SEQ_LCD_PrintVBar(layer_event.midi_package.value >> 4);
1316 tk 1019
  } else {
1020
    SEQ_LCD_PrintSpaces(2);
741 tk 1021
 
1316 tk 1022
    if( layer_event.midi_package.note && layer_event.midi_package.velocity && (layer_event.len >= 0) ) {
1023
      if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator ) {
1350 tk 1024
    u8 par_value = PassiveEditValid() ? edit_passive_value : layer_event.midi_package.note;
1025
    SEQ_LCD_PrintArp(par_value);
1316 tk 1026
      } else if( layer_type == SEQ_PAR_Type_Chord ) {
1350 tk 1027
    u8 par_value = PassiveEditValid()
1028
      ? edit_passive_value
1029
      : SEQ_PAR_Get(visible_track, ui_selected_step, 0, ui_selected_instrument);
1030
 
1316 tk 1031
    u8 chord_ix = par_value & 0x1f;
1032
    u8 chord_oct = par_value >> 5;
1033
    SEQ_LCD_PrintString(SEQ_CHORD_NameGet(chord_ix));
1034
    SEQ_LCD_PrintFormattedString("/%d", chord_oct);
1035
      } else {
1350 tk 1036
    u8 par_value = PassiveEditValid() ? edit_passive_value : layer_event.midi_package.note;
1037
    SEQ_LCD_PrintNote(par_value);
288 tk 1038
      }
1351 tk 1039
      SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
176 tk 1040
    }
1316 tk 1041
    else {
1042
      SEQ_LCD_PrintString("....");
1043
    }
1044
    SEQ_LCD_PrintFormattedString(" Vel:%3d", layer_event.midi_package.velocity);
176 tk 1045
  }
167 tk 1046
 
1316 tk 1047
  SEQ_LCD_PrintString(" Len:");
1048
  SEQ_LCD_PrintGatelength(layer_event.len);
167 tk 1049
 
1316 tk 1050
 
740 tk 1051
  // print flashing *LOOPED* at right corner if loop mode activated to remind that steps will be played differntly
1052
  if( (ui_cursor_flash_overrun_ctr & 1) && seq_core_state.LOOP ) {
1053
    SEQ_LCD_PrintString(" *LOOPED*");
828 tk 1054
  } else if( (ui_cursor_flash_overrun_ctr & 1) && seq_core_trk[visible_track].play_section > 0 ) {
1055
    SEQ_LCD_PrintFormattedString(" *Sect.%c*", 'A'+seq_core_trk[visible_track].play_section);
326 tk 1056
  } else {
740 tk 1057
    SEQ_LCD_PrintSpaces(4);
1058
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1059
      SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
1060
    } else {
1061
      SEQ_LCD_PrintTrackCategory(visible_track, (char *)seq_core_trk[visible_track].name);
1062
    }
180 tk 1063
  }
167 tk 1064
 
1065
  ///////////////////////////////////////////////////////////////////////////
1211 tk 1066
  // Second Line
1067
  ///////////////////////////////////////////////////////////////////////////
167 tk 1068
 
336 tk 1069
  u8 show_drum_triggers = (event_mode == SEQ_EVENT_MODE_Drum && (edit_mode || !ui_hold_msg_ctr));
335 tk 1070
 
176 tk 1071
  // extra handling for gatelength (shows vertical bars)
335 tk 1072
  if( !show_drum_triggers && layer_type == SEQ_PAR_Type_Length ) {
167 tk 1073
 
176 tk 1074
    // we want to show horizontal bars
1075
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_HBars);
167 tk 1076
 
176 tk 1077
    // initial cursor position
278 tk 1078
    SEQ_LCD_CursorSet(0, 1);
167 tk 1079
 
176 tk 1080
    // determine length of previous step (depends on selected view and track length)
1081
    int previous_step = 16*ui_selected_step_view - 1;
1082
    if( previous_step < 0 )
1083
      previous_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
1084
 
1085
    seq_layer_evnt_t layer_event;
336 tk 1086
    SEQ_LAYER_GetEvntOfLayer(visible_track, previous_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
176 tk 1087
    u16 previous_length = layer_event.len;
330 tk 1088
 
1089
    // show length of 16 steps
336 tk 1090
    u16 step;
330 tk 1091
    for(step=0; step<16; ++step) {
336 tk 1092
      u16 visible_step = step + 16*ui_selected_step_view;
1093
      SEQ_LAYER_GetEvntOfLayer(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
330 tk 1094
 
1143 tk 1095
      u8 gate = SEQ_TRG_GateGet(visible_track, visible_step, ui_selected_instrument);
1096
 
338 tk 1097
      // muted step? if previous gatelength <= 96, print spaces
1143 tk 1098
      if( (!gate || !layer_event.midi_package.velocity) && previous_length < 96 ) {
338 tk 1099
    SEQ_LCD_PrintSpaces(5);
1100
      } else {
1101
    if( layer_event.len >= 96 )
1102
      SEQ_LCD_PrintHBar(15); // glide or stretched event
330 tk 1103
    else
338 tk 1104
      SEQ_LCD_PrintHBar(((layer_event.len-1)*16)/100);
330 tk 1105
      }
1143 tk 1106
      previous_length = ((gate && layer_event.midi_package.velocity) || (previous_length >= 96 && layer_event.len >= 96)) ? layer_event.len : 0;
330 tk 1107
    }
1108
 
176 tk 1109
  } else {
1110
 
335 tk 1111
    if( show_drum_triggers ) {
323 tk 1112
      // we want to show triggers
325 tk 1113
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_DrumSymbolsBig);
323 tk 1114
    } else {
1115
      // we want to show vertical bars
1116
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
1117
    }
176 tk 1118
 
1119
    // initial cursor position
278 tk 1120
    SEQ_LCD_CursorSet(0, 1);
176 tk 1121
 
323 tk 1122
    int step_region_begin;
1123
    int step_region_end;
240 tk 1124
    switch( edit_mode ) {
1125
      case SEQ_UI_EDIT_MODE_COPY:
1126
    step_region_begin = SEQ_UI_UTIL_CopyPasteBeginGet();
1127
    step_region_end = SEQ_UI_UTIL_CopyPasteEndGet();
1128
    break;
1129
      case SEQ_UI_EDIT_MODE_PASTE:
1130
    step_region_begin = ui_selected_step;
1131
    step_region_end = ui_selected_step + SEQ_UI_UTIL_CopyPasteEndGet() - SEQ_UI_UTIL_CopyPasteBeginGet();
1132
    break;
1133
      case SEQ_UI_EDIT_MODE_SCROLL:
1134
    step_region_begin = ui_selected_step;
1135
    step_region_end = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
1136
    break;
1137
      default:
336 tk 1138
    step_region_begin = ui_selected_step;
1139
    step_region_end = ui_selected_step;
240 tk 1140
    }
1141
 
336 tk 1142
    u16 step;
176 tk 1143
    for(step=0; step<16; ++step) {
336 tk 1144
      u16 visible_step = step + 16*ui_selected_step_view;
240 tk 1145
 
1146
      if( ui_cursor_flash &&
1147
      edit_mode != SEQ_UI_EDIT_MODE_NORMAL &&
1148
      visible_step >= step_region_begin && visible_step <= step_region_end ) {
1149
    SEQ_LCD_PrintSpaces(5);
1150
    continue;
1151
      }
1152
 
335 tk 1153
      if( show_drum_triggers ) {
336 tk 1154
    u8 gate_accent = SEQ_TRG_Get(visible_track, visible_step, 0, ui_selected_instrument);
328 tk 1155
    if( SEQ_TRG_NumLayersGet(visible_track) >= 2 )
336 tk 1156
      gate_accent |= SEQ_TRG_Get(visible_track, visible_step, 1, ui_selected_instrument) << 1;
335 tk 1157
 
323 tk 1158
    SEQ_LCD_PrintChar(' ');
1159
    SEQ_LCD_PrintChar(' ');
327 tk 1160
    SEQ_LCD_PrintChar(gate_accent);
323 tk 1161
    SEQ_LCD_PrintChar(' ');
1162
    SEQ_LCD_PrintChar(' ');
1163
      } else {
1351 tk 1164
    int print_edit_value = (visible_step == edit_passive_step && PassiveEditValid()) ? edit_passive_value : -1;
1165
    SEQ_LCD_PrintLayerEvent(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument, 1, print_edit_value);
176 tk 1166
      }
1167
 
336 tk 1168
      if( !show_drum_triggers ) {
2049 tk 1169
    u8 midi_learn = seq_record_state.ENABLED || midi_learn_mode == MIDI_LEARN_MODE_ON;
1170
    char lbr = midi_learn ? '}' : '<';
1171
    char rbr = midi_learn ? '{' : '>';
2047 tk 1172
 
1173
    SEQ_LCD_PrintChar((visible_step == step_region_end) ? lbr
1174
              : ((visible_step == (step_region_begin-1)) ? rbr : ' '));
323 tk 1175
      }
240 tk 1176
 
176 tk 1177
    }
167 tk 1178
  }
1179
 
1180
  return 0; // no error
1181
}
1182
 
1183
 
1184
/////////////////////////////////////////////////////////////////////////////
240 tk 1185
// Local Display Handler function
1186
// IN: <high_prio>: if set, a high-priority LCD update is requested
1187
/////////////////////////////////////////////////////////////////////////////
1188
static s32 LCD_Handler(u8 high_prio)
1189
{
1190
  return SEQ_UI_EDIT_LCD_Handler(high_prio, SEQ_UI_EDIT_MODE_NORMAL);
1191
}
1192
 
1193
 
1194
/////////////////////////////////////////////////////////////////////////////
2047 tk 1195
// MIDI IN
1196
/////////////////////////////////////////////////////////////////////////////
1197
static s32 MIDI_IN_Handler(mios32_midi_port_t port, mios32_midi_package_t p)
1198
{
1199
  if( midi_learn_mode == MIDI_LEARN_MODE_ON ) {
2048 tk 1200
    u8 visible_track = SEQ_UI_VisibleTrackGet();
1201
 
2047 tk 1202
    // quick & dirty for evaluation purposes
1203
    seq_record_options_t prev_seq_record_options = seq_record_options;
1204
 
1205
    seq_record_options.ALL = 0;
1206
    seq_record_options.STEP_RECORD = 1;
1207
    seq_record_options.FWD_MIDI = prev_seq_record_options.FWD_MIDI;
1208
 
1209
    seq_record_state.ENABLED = 1;
1210
    seq_record_step = ui_selected_step;
1211
 
2048 tk 1212
    SEQ_RECORD_Receive(p, visible_track);
2047 tk 1213
 
2048 tk 1214
    if( seq_ui_button_state.CHANGE_ALL_STEPS ) {
1215
      // copy matching par layers into remaining steps
1216
      u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
1217
      u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1218
 
1219
      seq_cc_trk_t *tcc = &seq_cc_trk[visible_track];
1220
      seq_par_layer_type_t rec_layer_type = tcc->lay_const[ui_selected_par_layer];
1221
 
1222
      {
1223
    u8 p_layer;
1224
    for(p_layer=0; p_layer<num_p_layers; ++p_layer) {
1225
      seq_par_layer_type_t layer_type = tcc->lay_const[p_layer];
1226
 
1227
      if( layer_type == rec_layer_type ||
1228
          ((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)) ) {
1229
        u8 value = SEQ_PAR_Get(visible_track, seq_record_step, p_layer, ui_selected_instrument);
1230
 
1231
        u16 step;
1232
        for(step=0; step<num_steps; ++step) {
1233
          if( step != seq_record_step && (selected_steps & (1 << (step % 16))) ) {
1234
        SEQ_PAR_Set(visible_track, step, p_layer, ui_selected_instrument, value);
1235
          }
1236
        }
1237
      }
1238
    }
1239
      }
1240
    }
1241
 
2047 tk 1242
    seq_record_options.ALL = prev_seq_record_options.ALL;
1243
    seq_record_state.ENABLED = 0;
1244
 
1245
    seq_ui_display_update_req = 1;
1246
  }
1247
 
1248
  return 0;
1249
}
1250
 
1251
 
1252
/////////////////////////////////////////////////////////////////////////////
2050 tk 1253
// Exit
1254
/////////////////////////////////////////////////////////////////////////////
1255
static s32 EXIT_Handler(void)
1256
{
1257
  midi_learn_mode = MIDI_LEARN_MODE_OFF;
1258
  return 0;
1259
}
1260
 
1261
/////////////////////////////////////////////////////////////////////////////
167 tk 1262
// Initialisation
1263
/////////////////////////////////////////////////////////////////////////////
1264
s32 SEQ_UI_EDIT_Init(u32 mode)
1265
{
1266
  // install callback routines
758 tk 1267
  SEQ_UI_InstallButtonCallback(SEQ_UI_EDIT_Button_Handler);
168 tk 1268
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
240 tk 1269
  SEQ_UI_InstallLEDCallback(SEQ_UI_EDIT_LED_Handler);
168 tk 1270
  SEQ_UI_InstallLCDCallback(LCD_Handler);
2047 tk 1271
  SEQ_UI_InstallMIDIINCallback(MIDI_IN_Handler);
2050 tk 1272
  SEQ_UI_InstallExitCallback(EXIT_Handler);
167 tk 1273
 
2047 tk 1274
  // disable MIDI learn mode by default
1275
  midi_learn_mode = MIDI_LEARN_MODE_OFF;
1276
 
1350 tk 1277
  edit_passive_mode = 0;
729 tk 1278
 
1142 tk 1279
  if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL )
1280
    seq_ui_edit_view = SEQ_UI_EDIT_VIEW_STEPS;
1281
 
167 tk 1282
  return 0; // no error
1283
}
178 tk 1284
 
1285
 
1286
 
1287
/////////////////////////////////////////////////////////////////////////////
1288
// help function to change/set a single encoder value
1289
// if forced_value >= 0: new value will be set to the given value
1290
// if forced_value < 0: new value will be changed via incrementer
1291
// returns >= 0 if new value has been set (value change)
1292
// returns < 0 if no change
1293
/////////////////////////////////////////////////////////////////////////////
1052 tk 1294
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 1295
{
333 tk 1296
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(track, ui_selected_par_layer);
335 tk 1297
  u8 visible_track = SEQ_UI_VisibleTrackGet();
178 tk 1298
 
828 tk 1299
#if 0
1300
  // disabled in MBSEQ V4.0beta15 due to issue reported by Gridracer:
1301
  // http://midibox.org/forums/index.php?/topic/13137-midibox-seq-v4-beta-release-feedback/page__st__100
1302
 
333 tk 1303
  // if note/chord/velocity parameter: only change gate if requested
1304
  if( (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord || layer_type == SEQ_PAR_Type_Velocity) &&
178 tk 1305
      !change_gate &&
652 tk 1306
      !SEQ_TRG_GateGet(track, trg_step, ui_selected_instrument) )
178 tk 1307
    return -1;
828 tk 1308
#endif
178 tk 1309
 
1052 tk 1310
  if( layer_type == SEQ_PAR_Type_Probability ) {
1311
    // due to another issue reported by Gridracer:
1312
    // invert incrementer so that clockwise move increases probability
1313
    incrementer = -incrementer;
1314
  }
1315
 
1316
 
335 tk 1317
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
652 tk 1318
  if( event_mode == SEQ_EVENT_MODE_Drum ) {
335 tk 1319
    ui_hold_msg_ctr = 1000; // show value for 1 second
652 tk 1320
  }
335 tk 1321
 
652 tk 1322
  s32 old_value = SEQ_PAR_Get(track, par_step, ui_selected_par_layer, ui_selected_instrument);
178 tk 1323
  s32 new_value = (forced_value >= 0) ? forced_value : (old_value + incrementer);
1324
  if( new_value < 0 )
1325
    new_value = 0;
1326
  else if( new_value >= 128 )
1327
    new_value = 127;
1328
 
1143 tk 1329
  // extra for more comfortable editing of multi-note tracks:
1330
  // if assigned parameter layer is Note or Chord, and currently 0, re-start at C-3 resp. A/2
1331
  // when value is incremented
1332
  if( incrementer > 0 && forced_value < 0 && old_value == 0x00 && (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord) )
1333
    new_value = (layer_type == SEQ_PAR_Type_Note && SEQ_CC_Get(track, SEQ_CC_MODE) != SEQ_CORE_TRKMODE_Arpeggiator) ? 0x3c : 0x40;
1334
 
1345 tk 1335
  if( !dont_change_gate ) {
1336
    u8 event_mode = SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
1337
 
1338
    // we do this always regardless if value has been changed or not (e.g. increment if value already 127)
1339
    if( event_mode == SEQ_EVENT_MODE_CC && layer_type == SEQ_PAR_Type_CC ) {
1340
      // in this mode gates are used to disable CC
1341
      // if a CC value has been changed, set gate
1342
      SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 1);
1343
    }
1344
  }
1345
 
178 tk 1346
  // take over if changed
1347
  if( new_value == old_value )
1348
    return -1;
1349
 
652 tk 1350
  SEQ_PAR_Set(track, par_step, ui_selected_par_layer, ui_selected_instrument, (u8)new_value);
178 tk 1351
 
747 tk 1352
  if( !dont_change_gate &&
1353
      (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord || layer_type == SEQ_PAR_Type_Velocity) ) {
178 tk 1354
    // (de)activate gate depending on value
1355
    if( new_value )
652 tk 1356
      SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 1);
1053 tk 1357
    else {
1358
      // due to another issue reported by Gridracer:
1359
      // if the track plays multiple notes, only clear gate if all notes are 0
1142 tk 1360
      u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1053 tk 1361
      u8 allNotesZero = 1;
1362
      int i;
1142 tk 1363
      for(i=0; i<num_p_layers; ++i) {
1053 tk 1364
    seq_par_layer_type_t localLayerType = SEQ_PAR_AssignmentGet(track, i);
1365
    if( (localLayerType == SEQ_PAR_Type_Note || localLayerType == SEQ_PAR_Type_Chord) &&
1366
        SEQ_PAR_Get(track, par_step, i, ui_selected_instrument) > 0 ) {
1367
      allNotesZero = 0;
1368
      break;
1369
    }
1370
      }
1371
 
1372
      if( allNotesZero )
1373
    SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 0);
1374
    }
178 tk 1375
  }
1376
 
1377
  return new_value;
1378
}
1350 tk 1379
 
1380
 
1381
/////////////////////////////////////////////////////////////////////////////
1382
// help functions for "passive edit mode"
1383
/////////////////////////////////////////////////////////////////////////////
1384
static s32 PassiveEditEnter(void)
1385
{
1386
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1351 tk 1387
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
1350 tk 1388
 
1351 tk 1389
  // passive edit mode currently only supported for notes/chords
1350 tk 1390
 
1351 tk 1391
  if( layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord ) {
1392
    // enter passive edit mode and store track/step/layer/instrument for later checks
1393
    edit_passive_mode = 1;
1394
    edit_passive_track = visible_track;
1395
    edit_passive_step = ui_selected_step;
1396
    edit_passive_par_layer = ui_selected_par_layer;
1397
    edit_passive_instrument = ui_selected_instrument;
1398
    edit_passive_value = SEQ_PAR_Get(edit_passive_track, edit_passive_step, edit_passive_par_layer, edit_passive_instrument);
1399
  } else {
1400
    edit_passive_mode = 0;
1401
  }
1402
 
1350 tk 1403
  return 0; // no error
1404
}
1405
 
1406
static s32 PassiveEditValid(void)
1407
{
1408
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1409
 
1410
  return (edit_passive_mode == 2 && // if mode is 2, the value has been changed!
1411
      edit_passive_track == visible_track &&
1412
      edit_passive_step == ui_selected_step &&
1413
      edit_passive_par_layer == ui_selected_par_layer &&
1414
      edit_passive_instrument == ui_selected_instrument) ? 1 : 0;
1415
}
1416
 
1417
static s32 PassiveEditTakeOver(void)
1418
{
1419
 
1420
  // only take over changed value if track/step/layer/instrument still passing
1421
  if( PassiveEditValid() ) {
1422
    // take over change
1423
    // handle it like a single increment/decrement so that no code needs to be duplicated
1424
    int current_value = SEQ_PAR_Get(edit_passive_track, edit_passive_step, edit_passive_par_layer, edit_passive_instrument);
1425
    int incrementer = (int)edit_passive_value - current_value;
1426
 
2048 tk 1427
    seq_ui_button_state.EDIT_PRESSED = 0; // just to avoid any overlay...
1350 tk 1428
    edit_passive_mode = 0; // to avoid recursion in encoder handler
1429
    Encoder_Handler(edit_passive_step % 16, incrementer);
1430
  } else {
1431
    edit_passive_mode = 1;
1432
  }
1433
 
1434
  return 0; // no error
1435
}