Subversion Repositories svn.mios32

Rev

Rev 2048 | Rev 2050 | 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 2049 2014-09-07 14:48:38Z 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
 
256
      case SEQ_UI_ENCODER_GP13:
257
      case SEQ_UI_ENCODER_GP14:
258
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRKRND);
259
    break;
260
 
261
      case SEQ_UI_ENCODER_GP15:
262
      case SEQ_UI_ENCODER_GP16:
263
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRKEUCLID);
264
    break;
1348 tk 265
      }
266
 
2048 tk 267
      seq_ui_button_state.EDIT_PRESSED = 0; // switch back to view
1142 tk 268
      return 1; // value changed
269
    }
270
 
271
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
729 tk 272
      if( incrementer > 0 )
273
    selected_steps |= (1 << encoder);
274
      else
275
    selected_steps &= ~(1 << encoder);
276
      return 1; // value changed
277
    }
278
 
1142 tk 279
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
182 tk 280
 
1142 tk 281
    if( event_mode != SEQ_EVENT_MODE_Drum &&
282
    (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_303) ) {
283
      u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
284
 
285
      if( encoder == SEQ_UI_ENCODER_GP1 ) {
1348 tk 286
    if( SEQ_UI_Var8_Inc(&ui_selected_step, 0, num_steps-1, incrementer) >= 1 )
1142 tk 287
      return 1;
288
    else
289
      return 0;
290
      } else if( encoder == SEQ_UI_ENCODER_GP2 ) {
291
    SEQ_TRG_GateSet(visible_track, ui_selected_step, ui_selected_instrument, incrementer > 0 ? 1 : 0);
292
    return 1;
293
      } else if( encoder == SEQ_UI_ENCODER_GP3 ) {
294
    SEQ_TRG_AccentSet(visible_track, ui_selected_step, ui_selected_instrument, incrementer > 0 ? 1 : 0);
295
    return 1;
296
      } else if( encoder == SEQ_UI_ENCODER_GP4 ) {
297
    SEQ_TRG_GlideSet(visible_track, ui_selected_step, ui_selected_instrument, incrementer > 0 ? 1 : 0);
298
    return 1;
299
      } else if( encoder == SEQ_UI_ENCODER_GP5 ) {
300
    ui_selected_par_layer = 0;
301
    u8 note = SEQ_PAR_Get(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument);
302
    u8 note_octave = note / 12;
303
    u8 note_key = note % 12;
304
 
305
    if( SEQ_UI_Var8_Inc(&note_octave, 0, 9, incrementer) >= 1 ) {
306
      SEQ_PAR_Set(visible_track, ui_selected_step, 0, ui_selected_instrument, 12*note_octave + note_key);
307
      return 1;
308
    }
309
    return 0;
310
      } else if( encoder == SEQ_UI_ENCODER_GP6 ) {
311
    ui_selected_par_layer = 0;
312
    u8 note = SEQ_PAR_Get(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument);
313
    u8 note_octave = note / 12;
314
    u8 note_key = note % 12;
315
 
316
    if( SEQ_UI_Var8_Inc(&note_key, 0, 11, incrementer) >= 1 ) {
317
      SEQ_PAR_Set(visible_track, ui_selected_step, 0, ui_selected_instrument, 12*note_octave + note_key);
318
      return 1;
319
    }
320
    return 0;
321
      } else if( encoder <= SEQ_UI_ENCODER_GP16 ) {
322
    u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
323
    if( ((int)encoder-5) >= num_p_layers )
324
        return 0; // ignore
325
      ui_selected_par_layer = encoder-5;
326
      }
327
 
328
      if( !incrementer ) // button selection only...
329
    return 1;
330
    }
331
 
332
    if( event_mode != SEQ_EVENT_MODE_Drum &&
333
      (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_LAYERS || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG) ) {
334
      u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
335
 
336
      if( encoder == SEQ_UI_ENCODER_GP1 ) {
1348 tk 337
    if( SEQ_UI_Var8_Inc(&ui_selected_step, 0, num_steps-1, incrementer) >= 1 )
1142 tk 338
      return 1;
339
    else
340
      return 0;
341
      } else if( encoder == SEQ_UI_ENCODER_GP2 ||
342
         (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG && encoder <= SEQ_UI_ENCODER_GP8) ) {
343
    u8 sel = (u8)encoder-1;
344
    SEQ_TRG_Set(visible_track, ui_selected_step, sel, ui_selected_instrument, incrementer > 0 ? 1 : 0);
345
    return 1;
346
      } else if( encoder <= SEQ_UI_ENCODER_GP16 ) {
347
 
348
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
349
      if( encoder <= SEQ_UI_ENCODER_GP8 ) {
350
        u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
351
        if( ((int)encoder-2) >= num_t_layers )
352
          return 0; // ignore
353
        ui_selected_trg_layer = encoder-2;
354
      } else {
355
        u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
356
        if( ((int)encoder-8) >= num_p_layers )
357
          return 0; // ignore
358
        ui_selected_par_layer = encoder-8;
359
      }
360
    } else {
361
      u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
362
      if( ((int)encoder-2) >= num_p_layers )
363
        return 0; // ignore
364
      ui_selected_par_layer = encoder-2;
365
    }
366
 
367
    if( !incrementer ) // button selection only...
368
      return 1;
369
      }
370
    }
371
 
1809 tk 372
    u8 changed_step;
373
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPS ) {
374
      changed_step = ((encoder == SEQ_UI_ENCODER_Datawheel) ? (ui_selected_step%16) : encoder) + ui_selected_step_view*16;
375
    } else {
376
      changed_step = ui_selected_step;
377
    }
378
 
1751 tk 379
    u8 edit_ramp = 0;
1350 tk 380
    if( event_mode == SEQ_EVENT_MODE_Drum || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPS ) {
1142 tk 381
 
1350 tk 382
      // in passive edit mode: take over the edit value if step has changed, thereafter switch to new step
1751 tk 383
      if( ui_selected_step != changed_step && edit_passive_mode ) {
1350 tk 384
    PassiveEditTakeOver();
1751 tk 385
    ui_selected_step = changed_step;
1350 tk 386
    PassiveEditEnter();
387
      } else {
1751 tk 388
    // take over new step if "ALL" button not pressed to support "ramp" editing
389
    if( !seq_ui_button_state.CHANGE_ALL_STEPS ) {
390
      ui_selected_step = changed_step;
391
    } else {
392
      if( ui_selected_step != changed_step )
393
        edit_ramp = 1;
394
    }
1350 tk 395
      }
396
 
397
    }
398
 
399
 
400
    // in passive edit mode: change value, but don't take over yet!
401
    if( edit_passive_mode ) {
402
      if( SEQ_UI_Var8_Inc(&edit_passive_value, 0, 127, incrementer) >= 1 ) {
403
    edit_passive_mode = 2; // value has been changed
404
    return 1;
405
      } else
406
    return 0;
407
    }
408
 
409
    // normal edit mode
178 tk 410
    s32 value_changed = 0;
411
    s32 forced_value = -1;
412
    u8  change_gate = 1;
168 tk 413
 
182 tk 414
    // due to historical reasons (from old times where MBSEQ CS was stuffed with pots): 
415
    // in arp mode, we increment in steps of 4
1143 tk 416
    u8 par_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
182 tk 417
    if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator &&
1143 tk 418
    par_type == SEQ_PAR_Type_Note )
182 tk 419
      incrementer *= 4;
420
 
178 tk 421
    // first change the selected value
1751 tk 422
    if( seq_ui_button_state.CHANGE_ALL_STEPS && (edit_ramp || seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE) ) {
652 tk 423
      u16 num_steps = SEQ_PAR_NumStepsGet(visible_track);
1751 tk 424
      u16 par_step = changed_step;
425
      u16 trg_step = changed_step;
652 tk 426
 
427
      // mirrored layer in drum mode?
428
      u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
429
      if( event_mode == SEQ_EVENT_MODE_Drum && par_step >= num_steps )
430
    par_step %= num_steps;
431
 
747 tk 432
      forced_value = ChangeSingleEncValue(visible_track, par_step, trg_step, incrementer, forced_value, change_gate, 0);
178 tk 433
      if( forced_value < 0 )
434
    return 0; // no change
435
      value_changed |= 1;
168 tk 436
    }
437
 
1751 tk 438
    int value_selected_step = SEQ_PAR_Get(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument);
439
    int value_changed_step = SEQ_PAR_Get(visible_track, changed_step, ui_selected_par_layer, ui_selected_instrument);
440
 
178 tk 441
    // change value of all selected steps
442
    u8 track;
443
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
444
      if( SEQ_UI_IsSelectedTrack(track) ) {
318 tk 445
    u16 num_steps = SEQ_PAR_NumStepsGet(track);
1751 tk 446
    u16 trg_step = (changed_step & ~(num_steps-1));
447
 
652 tk 448
    u16 par_step;
449
    for(par_step=0; par_step<num_steps; ++par_step, ++trg_step) {
1751 tk 450
      if( !seq_ui_button_state.CHANGE_ALL_STEPS || (!edit_ramp && par_step == changed_step) || (selected_steps & (1 << (par_step % 16))) ) {
451
        change_gate = trg_step == changed_step;
452
        u8 dont_change_gate = par_step != changed_step;
729 tk 453
        if( change_gate || seq_ui_button_state.CHANGE_ALL_STEPS ) {
1751 tk 454
          s32 local_forced_value = edit_ramp ? -1 : forced_value;
455
 
456
          s32 edit_ramp_num_steps = 0;
457
          if( edit_ramp ) {
458
        if( changed_step > ui_selected_step && par_step > ui_selected_step && par_step < changed_step ) {
459
          edit_ramp_num_steps = changed_step - ui_selected_step;
460
        } else if( changed_step < ui_selected_step && par_step < ui_selected_step && par_step > changed_step ) {
461
          edit_ramp_num_steps = ui_selected_step - changed_step;
462
        }
463
 
464
        if( edit_ramp_num_steps ) {
465
          if( par_step == changed_step ) {
466
            local_forced_value = value_changed_step;
467
          } else {
468
            int diff = value_changed_step - value_selected_step;
469
            if( diff == 0 ) {
470
              local_forced_value = value_changed_step;
471
            } else {
472
              if( changed_step > ui_selected_step ) {
473
            local_forced_value = value_selected_step + (((par_step - ui_selected_step) * diff) / edit_ramp_num_steps);
474
              } else {
475
            local_forced_value = value_selected_step + (((ui_selected_step - par_step) * diff) / edit_ramp_num_steps);
476
              }
477
            }
478
          }
479
        }
480
          }
481
 
482
          if( !edit_ramp || edit_ramp_num_steps ) {
483
        if( ChangeSingleEncValue(track, par_step, trg_step, incrementer, local_forced_value, change_gate, dont_change_gate) >= 0 )
484
          value_changed |= 1;
485
          }
729 tk 486
        }
178 tk 487
      }
488
    }
489
      }
176 tk 490
    }
1142 tk 491
 
178 tk 492
    return value_changed;
168 tk 493
  }
494
 
495
  return -1; // invalid or unsupported encoder
167 tk 496
}
497
 
498
 
499
/////////////////////////////////////////////////////////////////////////////
168 tk 500
// Local button callback function
501
// Should return:
502
//   1 if value has been changed
503
//   0 if value hasn't been changed
504
//  -1 if invalid or unsupported button
167 tk 505
/////////////////////////////////////////////////////////////////////////////
758 tk 506
s32 SEQ_UI_EDIT_Button_Handler(seq_ui_button_t button, s32 depressed)
167 tk 507
{
306 tk 508
  u8 visible_track = SEQ_UI_VisibleTrackGet();
509
 
168 tk 510
#if 0
511
  // leads to: comparison is always true due to limited range of data type
512
  if( button >= SEQ_UI_BUTTON_GP1 && button <= SEQ_UI_BUTTON_GP16 ) {
513
#else
514
  if( button <= SEQ_UI_BUTTON_GP16 ) {
515
#endif
2047 tk 516
 
517
    // enable/disable MIDI Learn mode
518
    midi_learn_mode = depressed ? MIDI_LEARN_MODE_OFF : MIDI_LEARN_MODE_ON;
519
 
729 tk 520
    if( depressed ) return 0; // ignore when button depressed
521
 
2048 tk 522
    if( seq_ui_button_state.EDIT_PRESSED )
1142 tk 523
      return Encoder_Handler(button, 0);
524
 
2048 tk 525
#if 0
526
    // conflicts with new MIDI learn
1751 tk 527
    if( (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPS && seq_ui_button_state.CHANGE_ALL_STEPS) ||
528
    seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
729 tk 529
      selected_steps ^= (1 << button);
530
      return 1; // value changed
531
    }
2048 tk 532
#else
533
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL ) {
534
      selected_steps ^= (1 << button);
535
      return 1; // value changed
536
    }
537
#endif
729 tk 538
 
1142 tk 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
1483 tk 712
  // Step Trg  Layer 303                Step Datawheel:           Random    Euclid   
713
  // View View View View               Select Scroll             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);
1483 tk 745
    SEQ_LCD_PrintString("Step Trg  Layer 303                Step Datawheel:           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]);
1483 tk 749
    SEQ_LCD_PrintString("          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
    }
896
  } else if( seq_record_state.ENABLED || edit_mode == SEQ_UI_EDIT_MODE_RECORD ) {
897
    if( ui_cursor_flash ) {
898
      SEQ_LCD_PrintSpaces(15);
899
    } else {
1349 tk 900
      SEQ_LCD_PrintString("RECORDING      ");
901
    }
902
  } else {
903
    switch( edit_mode ) {
240 tk 904
    case SEQ_UI_EDIT_MODE_COPY: {
905
      if( ui_cursor_flash ) {
906
    SEQ_LCD_PrintSpaces(15);
907
      } else {
908
    char str_buffer[10];
909
    sprintf(str_buffer, "%d-%d", SEQ_UI_UTIL_CopyPasteBeginGet()+1, SEQ_UI_UTIL_CopyPasteEndGet()+1);
278 tk 910
    SEQ_LCD_PrintFormattedString("COPY S%-9s", str_buffer);
240 tk 911
      }
912
    } break;
167 tk 913
 
240 tk 914
    case SEQ_UI_EDIT_MODE_PASTE: {
915
      if( ui_cursor_flash ) {
916
    SEQ_LCD_PrintSpaces(15);
917
      } else {
278 tk 918
    SEQ_LCD_PrintFormattedString("PASTE OFFS.%3d ", ui_selected_step+1);
240 tk 919
      }
920
    } break;
167 tk 921
 
240 tk 922
    case SEQ_UI_EDIT_MODE_MOVE: {
923
      if( ui_cursor_flash ) {
924
    SEQ_LCD_PrintSpaces(15);
925
      } else {
278 tk 926
    SEQ_LCD_PrintString("MOVE STEPS     ");
240 tk 927
      }
928
    } break;
176 tk 929
 
240 tk 930
    case SEQ_UI_EDIT_MODE_SCROLL: {
931
      if( ui_cursor_flash ) {
932
    SEQ_LCD_PrintSpaces(15);
933
      } else {
278 tk 934
    SEQ_LCD_PrintString("SCROLL TRACK   ");
240 tk 935
      }
936
    } break;
176 tk 937
 
240 tk 938
    case SEQ_UI_EDIT_MODE_RANDOM: {
939
      if( ui_cursor_flash ) {
940
    SEQ_LCD_PrintSpaces(15);
941
      } else {
278 tk 942
    SEQ_LCD_PrintString("RANDOMIZED     ");
240 tk 943
      }
944
    } break;
176 tk 945
 
600 tk 946
    case SEQ_UI_EDIT_MODE_MANUAL: {
947
      if( ui_cursor_flash ) {
948
    SEQ_LCD_PrintSpaces(15);
949
      } else {
950
    SEQ_LCD_PrintString("MANUAL TRIGGER ");
951
      }
952
    } break;
953
 
240 tk 954
    default: {
326 tk 955
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
956
    SEQ_LCD_PrintChar(' ');
957
    SEQ_LCD_PrintChar(' ');
958
    SEQ_LCD_PrintMIDIOutPort(SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT));
959
    SEQ_LCD_PrintChar(' ');
960
    SEQ_LCD_PrintFormattedString("Chn.%2d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
961
      } else {
962
    SEQ_LCD_PrintTrackLabel(visible_track, (char *)seq_core_trk[visible_track].name);
963
      }
964
    }
1349 tk 965
    }
326 tk 966
  }
176 tk 967
 
326 tk 968
  SEQ_LCD_PrintSpaces(2);
176 tk 969
 
326 tk 970
  SEQ_LCD_PrintChar('P');
971
  SEQ_LCD_PrintChar('A' + ui_selected_par_layer);
972
  SEQ_LCD_PrintChar(':');
240 tk 973
 
1316 tk 974
  if( layer_type == SEQ_PAR_Type_CC ) {
1811 tk 975
    if( layer_event.midi_package.cc_number >= 0x80 ) {
976
      SEQ_LCD_PrintFormattedString("CC#off ");
977
    } else {
978
      SEQ_LCD_PrintFormattedString("CC#%3d ", layer_event.midi_package.cc_number);
979
    }
333 tk 980
  } else {
981
    SEQ_LCD_PrintString(SEQ_PAR_AssignedTypeStr(visible_track, ui_selected_par_layer));
982
    SEQ_LCD_PrintSpaces(2);
176 tk 983
  }
167 tk 984
 
328 tk 985
  SEQ_LCD_PrintFormattedString("T%c:%s", 'A' + ui_selected_trg_layer, SEQ_TRG_AssignedTypeStr(visible_track, ui_selected_trg_layer));
327 tk 986
 
987
 
167 tk 988
  ///////////////////////////////////////////////////////////////////////////
278 tk 989
  SEQ_LCD_CursorSet(40, 0);
167 tk 990
 
1316 tk 991
  SEQ_LCD_PrintFormattedString("Step%3d ", ui_selected_step+1);
167 tk 992
 
1316 tk 993
  if( layer_event.midi_package.event == CC ) {
994
    mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
995
    u8 loopback = port == 0xf0;
741 tk 996
 
1316 tk 997
    if( loopback )
998
      SEQ_LCD_PrintString((char *)SEQ_CC_LABELS_Get(port, layer_event.midi_package.cc_number));
1811 tk 999
    else {
1000
      if( layer_event.midi_package.cc_number >= 0x80 ) {
1001
    SEQ_LCD_PrintFormattedString("  CC#off");
1002
      } else {
1003
    SEQ_LCD_PrintFormattedString("  CC#%3d", layer_event.midi_package.cc_number);
1004
      }
1005
    }
1351 tk 1006
    SEQ_LCD_PrintFormattedString(" %3d ", layer_event.midi_package.value);
1007
    SEQ_LCD_PrintVBar(layer_event.midi_package.value >> 4);
1316 tk 1008
  } else {
1009
    SEQ_LCD_PrintSpaces(2);
741 tk 1010
 
1316 tk 1011
    if( layer_event.midi_package.note && layer_event.midi_package.velocity && (layer_event.len >= 0) ) {
1012
      if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator ) {
1350 tk 1013
    u8 par_value = PassiveEditValid() ? edit_passive_value : layer_event.midi_package.note;
1014
    SEQ_LCD_PrintArp(par_value);
1316 tk 1015
      } else if( layer_type == SEQ_PAR_Type_Chord ) {
1350 tk 1016
    u8 par_value = PassiveEditValid()
1017
      ? edit_passive_value
1018
      : SEQ_PAR_Get(visible_track, ui_selected_step, 0, ui_selected_instrument);
1019
 
1316 tk 1020
    u8 chord_ix = par_value & 0x1f;
1021
    u8 chord_oct = par_value >> 5;
1022
    SEQ_LCD_PrintString(SEQ_CHORD_NameGet(chord_ix));
1023
    SEQ_LCD_PrintFormattedString("/%d", chord_oct);
1024
      } else {
1350 tk 1025
    u8 par_value = PassiveEditValid() ? edit_passive_value : layer_event.midi_package.note;
1026
    SEQ_LCD_PrintNote(par_value);
288 tk 1027
      }
1351 tk 1028
      SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
176 tk 1029
    }
1316 tk 1030
    else {
1031
      SEQ_LCD_PrintString("....");
1032
    }
1033
    SEQ_LCD_PrintFormattedString(" Vel:%3d", layer_event.midi_package.velocity);
176 tk 1034
  }
167 tk 1035
 
1316 tk 1036
  SEQ_LCD_PrintString(" Len:");
1037
  SEQ_LCD_PrintGatelength(layer_event.len);
167 tk 1038
 
1316 tk 1039
 
740 tk 1040
  // print flashing *LOOPED* at right corner if loop mode activated to remind that steps will be played differntly
1041
  if( (ui_cursor_flash_overrun_ctr & 1) && seq_core_state.LOOP ) {
1042
    SEQ_LCD_PrintString(" *LOOPED*");
828 tk 1043
  } else if( (ui_cursor_flash_overrun_ctr & 1) && seq_core_trk[visible_track].play_section > 0 ) {
1044
    SEQ_LCD_PrintFormattedString(" *Sect.%c*", 'A'+seq_core_trk[visible_track].play_section);
326 tk 1045
  } else {
740 tk 1046
    SEQ_LCD_PrintSpaces(4);
1047
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1048
      SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
1049
    } else {
1050
      SEQ_LCD_PrintTrackCategory(visible_track, (char *)seq_core_trk[visible_track].name);
1051
    }
180 tk 1052
  }
167 tk 1053
 
1054
  ///////////////////////////////////////////////////////////////////////////
1211 tk 1055
  // Second Line
1056
  ///////////////////////////////////////////////////////////////////////////
167 tk 1057
 
336 tk 1058
  u8 show_drum_triggers = (event_mode == SEQ_EVENT_MODE_Drum && (edit_mode || !ui_hold_msg_ctr));
335 tk 1059
 
176 tk 1060
  // extra handling for gatelength (shows vertical bars)
335 tk 1061
  if( !show_drum_triggers && layer_type == SEQ_PAR_Type_Length ) {
167 tk 1062
 
176 tk 1063
    // we want to show horizontal bars
1064
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_HBars);
167 tk 1065
 
176 tk 1066
    // initial cursor position
278 tk 1067
    SEQ_LCD_CursorSet(0, 1);
167 tk 1068
 
176 tk 1069
    // determine length of previous step (depends on selected view and track length)
1070
    int previous_step = 16*ui_selected_step_view - 1;
1071
    if( previous_step < 0 )
1072
      previous_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
1073
 
1074
    seq_layer_evnt_t layer_event;
336 tk 1075
    SEQ_LAYER_GetEvntOfLayer(visible_track, previous_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
176 tk 1076
    u16 previous_length = layer_event.len;
330 tk 1077
 
1078
    // show length of 16 steps
336 tk 1079
    u16 step;
330 tk 1080
    for(step=0; step<16; ++step) {
336 tk 1081
      u16 visible_step = step + 16*ui_selected_step_view;
1082
      SEQ_LAYER_GetEvntOfLayer(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
330 tk 1083
 
1143 tk 1084
      u8 gate = SEQ_TRG_GateGet(visible_track, visible_step, ui_selected_instrument);
1085
 
338 tk 1086
      // muted step? if previous gatelength <= 96, print spaces
1143 tk 1087
      if( (!gate || !layer_event.midi_package.velocity) && previous_length < 96 ) {
338 tk 1088
    SEQ_LCD_PrintSpaces(5);
1089
      } else {
1090
    if( layer_event.len >= 96 )
1091
      SEQ_LCD_PrintHBar(15); // glide or stretched event
330 tk 1092
    else
338 tk 1093
      SEQ_LCD_PrintHBar(((layer_event.len-1)*16)/100);
330 tk 1094
      }
1143 tk 1095
      previous_length = ((gate && layer_event.midi_package.velocity) || (previous_length >= 96 && layer_event.len >= 96)) ? layer_event.len : 0;
330 tk 1096
    }
1097
 
176 tk 1098
  } else {
1099
 
335 tk 1100
    if( show_drum_triggers ) {
323 tk 1101
      // we want to show triggers
325 tk 1102
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_DrumSymbolsBig);
323 tk 1103
    } else {
1104
      // we want to show vertical bars
1105
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
1106
    }
176 tk 1107
 
1108
    // initial cursor position
278 tk 1109
    SEQ_LCD_CursorSet(0, 1);
176 tk 1110
 
323 tk 1111
    int step_region_begin;
1112
    int step_region_end;
240 tk 1113
    switch( edit_mode ) {
1114
      case SEQ_UI_EDIT_MODE_COPY:
1115
    step_region_begin = SEQ_UI_UTIL_CopyPasteBeginGet();
1116
    step_region_end = SEQ_UI_UTIL_CopyPasteEndGet();
1117
    break;
1118
      case SEQ_UI_EDIT_MODE_PASTE:
1119
    step_region_begin = ui_selected_step;
1120
    step_region_end = ui_selected_step + SEQ_UI_UTIL_CopyPasteEndGet() - SEQ_UI_UTIL_CopyPasteBeginGet();
1121
    break;
1122
      case SEQ_UI_EDIT_MODE_SCROLL:
1123
    step_region_begin = ui_selected_step;
1124
    step_region_end = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
1125
    break;
1126
      default:
336 tk 1127
    step_region_begin = ui_selected_step;
1128
    step_region_end = ui_selected_step;
240 tk 1129
    }
1130
 
336 tk 1131
    u16 step;
176 tk 1132
    for(step=0; step<16; ++step) {
336 tk 1133
      u16 visible_step = step + 16*ui_selected_step_view;
240 tk 1134
 
1135
      if( ui_cursor_flash &&
1136
      edit_mode != SEQ_UI_EDIT_MODE_NORMAL &&
1137
      visible_step >= step_region_begin && visible_step <= step_region_end ) {
1138
    SEQ_LCD_PrintSpaces(5);
1139
    continue;
1140
      }
1141
 
335 tk 1142
      if( show_drum_triggers ) {
336 tk 1143
    u8 gate_accent = SEQ_TRG_Get(visible_track, visible_step, 0, ui_selected_instrument);
328 tk 1144
    if( SEQ_TRG_NumLayersGet(visible_track) >= 2 )
336 tk 1145
      gate_accent |= SEQ_TRG_Get(visible_track, visible_step, 1, ui_selected_instrument) << 1;
335 tk 1146
 
323 tk 1147
    SEQ_LCD_PrintChar(' ');
1148
    SEQ_LCD_PrintChar(' ');
327 tk 1149
    SEQ_LCD_PrintChar(gate_accent);
323 tk 1150
    SEQ_LCD_PrintChar(' ');
1151
    SEQ_LCD_PrintChar(' ');
1152
      } else {
1351 tk 1153
    int print_edit_value = (visible_step == edit_passive_step && PassiveEditValid()) ? edit_passive_value : -1;
1154
    SEQ_LCD_PrintLayerEvent(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument, 1, print_edit_value);
176 tk 1155
      }
1156
 
336 tk 1157
      if( !show_drum_triggers ) {
2049 tk 1158
    u8 midi_learn = seq_record_state.ENABLED || midi_learn_mode == MIDI_LEARN_MODE_ON;
1159
    char lbr = midi_learn ? '}' : '<';
1160
    char rbr = midi_learn ? '{' : '>';
2047 tk 1161
 
1162
    SEQ_LCD_PrintChar((visible_step == step_region_end) ? lbr
1163
              : ((visible_step == (step_region_begin-1)) ? rbr : ' '));
323 tk 1164
      }
240 tk 1165
 
176 tk 1166
    }
167 tk 1167
  }
1168
 
1169
  return 0; // no error
1170
}
1171
 
1172
 
1173
/////////////////////////////////////////////////////////////////////////////
240 tk 1174
// Local Display Handler function
1175
// IN: <high_prio>: if set, a high-priority LCD update is requested
1176
/////////////////////////////////////////////////////////////////////////////
1177
static s32 LCD_Handler(u8 high_prio)
1178
{
1179
  return SEQ_UI_EDIT_LCD_Handler(high_prio, SEQ_UI_EDIT_MODE_NORMAL);
1180
}
1181
 
1182
 
1183
/////////////////////////////////////////////////////////////////////////////
2047 tk 1184
// MIDI IN
1185
/////////////////////////////////////////////////////////////////////////////
1186
static s32 MIDI_IN_Handler(mios32_midi_port_t port, mios32_midi_package_t p)
1187
{
1188
  if( midi_learn_mode == MIDI_LEARN_MODE_ON ) {
2048 tk 1189
    u8 visible_track = SEQ_UI_VisibleTrackGet();
1190
 
2047 tk 1191
    // quick & dirty for evaluation purposes
1192
    seq_record_options_t prev_seq_record_options = seq_record_options;
1193
 
1194
    seq_record_options.ALL = 0;
1195
    seq_record_options.STEP_RECORD = 1;
1196
    seq_record_options.FWD_MIDI = prev_seq_record_options.FWD_MIDI;
1197
 
1198
    seq_record_state.ENABLED = 1;
1199
    seq_record_step = ui_selected_step;
1200
 
2048 tk 1201
    SEQ_RECORD_Receive(p, visible_track);
2047 tk 1202
 
2048 tk 1203
    if( seq_ui_button_state.CHANGE_ALL_STEPS ) {
1204
      // copy matching par layers into remaining steps
1205
      u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
1206
      u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1207
 
1208
      seq_cc_trk_t *tcc = &seq_cc_trk[visible_track];
1209
      seq_par_layer_type_t rec_layer_type = tcc->lay_const[ui_selected_par_layer];
1210
 
1211
      {
1212
    u8 p_layer;
1213
    for(p_layer=0; p_layer<num_p_layers; ++p_layer) {
1214
      seq_par_layer_type_t layer_type = tcc->lay_const[p_layer];
1215
 
1216
      if( layer_type == rec_layer_type ||
1217
          ((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)) ) {
1218
        u8 value = SEQ_PAR_Get(visible_track, seq_record_step, p_layer, ui_selected_instrument);
1219
 
1220
        u16 step;
1221
        for(step=0; step<num_steps; ++step) {
1222
          if( step != seq_record_step && (selected_steps & (1 << (step % 16))) ) {
1223
        SEQ_PAR_Set(visible_track, step, p_layer, ui_selected_instrument, value);
1224
          }
1225
        }
1226
      }
1227
    }
1228
      }
1229
    }
1230
 
2047 tk 1231
    seq_record_options.ALL = prev_seq_record_options.ALL;
1232
    seq_record_state.ENABLED = 0;
1233
 
1234
    seq_ui_display_update_req = 1;
1235
  }
1236
 
1237
  return 0;
1238
}
1239
 
1240
 
1241
/////////////////////////////////////////////////////////////////////////////
167 tk 1242
// Initialisation
1243
/////////////////////////////////////////////////////////////////////////////
1244
s32 SEQ_UI_EDIT_Init(u32 mode)
1245
{
1246
  // install callback routines
758 tk 1247
  SEQ_UI_InstallButtonCallback(SEQ_UI_EDIT_Button_Handler);
168 tk 1248
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
240 tk 1249
  SEQ_UI_InstallLEDCallback(SEQ_UI_EDIT_LED_Handler);
168 tk 1250
  SEQ_UI_InstallLCDCallback(LCD_Handler);
2047 tk 1251
  SEQ_UI_InstallMIDIINCallback(MIDI_IN_Handler);
167 tk 1252
 
2047 tk 1253
  // disable MIDI learn mode by default
1254
  midi_learn_mode = MIDI_LEARN_MODE_OFF;
1255
 
1350 tk 1256
  edit_passive_mode = 0;
729 tk 1257
 
1142 tk 1258
  if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL )
1259
    seq_ui_edit_view = SEQ_UI_EDIT_VIEW_STEPS;
1260
 
167 tk 1261
  return 0; // no error
1262
}
178 tk 1263
 
1264
 
1265
 
1266
/////////////////////////////////////////////////////////////////////////////
1267
// help function to change/set a single encoder value
1268
// if forced_value >= 0: new value will be set to the given value
1269
// if forced_value < 0: new value will be changed via incrementer
1270
// returns >= 0 if new value has been set (value change)
1271
// returns < 0 if no change
1272
/////////////////////////////////////////////////////////////////////////////
1052 tk 1273
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 1274
{
333 tk 1275
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(track, ui_selected_par_layer);
335 tk 1276
  u8 visible_track = SEQ_UI_VisibleTrackGet();
178 tk 1277
 
828 tk 1278
#if 0
1279
  // disabled in MBSEQ V4.0beta15 due to issue reported by Gridracer:
1280
  // http://midibox.org/forums/index.php?/topic/13137-midibox-seq-v4-beta-release-feedback/page__st__100
1281
 
333 tk 1282
  // if note/chord/velocity parameter: only change gate if requested
1283
  if( (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord || layer_type == SEQ_PAR_Type_Velocity) &&
178 tk 1284
      !change_gate &&
652 tk 1285
      !SEQ_TRG_GateGet(track, trg_step, ui_selected_instrument) )
178 tk 1286
    return -1;
828 tk 1287
#endif
178 tk 1288
 
1052 tk 1289
  if( layer_type == SEQ_PAR_Type_Probability ) {
1290
    // due to another issue reported by Gridracer:
1291
    // invert incrementer so that clockwise move increases probability
1292
    incrementer = -incrementer;
1293
  }
1294
 
1295
 
335 tk 1296
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
652 tk 1297
  if( event_mode == SEQ_EVENT_MODE_Drum ) {
335 tk 1298
    ui_hold_msg_ctr = 1000; // show value for 1 second
652 tk 1299
  }
335 tk 1300
 
652 tk 1301
  s32 old_value = SEQ_PAR_Get(track, par_step, ui_selected_par_layer, ui_selected_instrument);
178 tk 1302
  s32 new_value = (forced_value >= 0) ? forced_value : (old_value + incrementer);
1303
  if( new_value < 0 )
1304
    new_value = 0;
1305
  else if( new_value >= 128 )
1306
    new_value = 127;
1307
 
1143 tk 1308
  // extra for more comfortable editing of multi-note tracks:
1309
  // if assigned parameter layer is Note or Chord, and currently 0, re-start at C-3 resp. A/2
1310
  // when value is incremented
1311
  if( incrementer > 0 && forced_value < 0 && old_value == 0x00 && (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord) )
1312
    new_value = (layer_type == SEQ_PAR_Type_Note && SEQ_CC_Get(track, SEQ_CC_MODE) != SEQ_CORE_TRKMODE_Arpeggiator) ? 0x3c : 0x40;
1313
 
1345 tk 1314
  if( !dont_change_gate ) {
1315
    u8 event_mode = SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
1316
 
1317
    // we do this always regardless if value has been changed or not (e.g. increment if value already 127)
1318
    if( event_mode == SEQ_EVENT_MODE_CC && layer_type == SEQ_PAR_Type_CC ) {
1319
      // in this mode gates are used to disable CC
1320
      // if a CC value has been changed, set gate
1321
      SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 1);
1322
    }
1323
  }
1324
 
178 tk 1325
  // take over if changed
1326
  if( new_value == old_value )
1327
    return -1;
1328
 
652 tk 1329
  SEQ_PAR_Set(track, par_step, ui_selected_par_layer, ui_selected_instrument, (u8)new_value);
178 tk 1330
 
747 tk 1331
  if( !dont_change_gate &&
1332
      (layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord || layer_type == SEQ_PAR_Type_Velocity) ) {
178 tk 1333
    // (de)activate gate depending on value
1334
    if( new_value )
652 tk 1335
      SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 1);
1053 tk 1336
    else {
1337
      // due to another issue reported by Gridracer:
1338
      // if the track plays multiple notes, only clear gate if all notes are 0
1142 tk 1339
      u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1053 tk 1340
      u8 allNotesZero = 1;
1341
      int i;
1142 tk 1342
      for(i=0; i<num_p_layers; ++i) {
1053 tk 1343
    seq_par_layer_type_t localLayerType = SEQ_PAR_AssignmentGet(track, i);
1344
    if( (localLayerType == SEQ_PAR_Type_Note || localLayerType == SEQ_PAR_Type_Chord) &&
1345
        SEQ_PAR_Get(track, par_step, i, ui_selected_instrument) > 0 ) {
1346
      allNotesZero = 0;
1347
      break;
1348
    }
1349
      }
1350
 
1351
      if( allNotesZero )
1352
    SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 0);
1353
    }
178 tk 1354
  }
1355
 
1356
  return new_value;
1357
}
1350 tk 1358
 
1359
 
1360
/////////////////////////////////////////////////////////////////////////////
1361
// help functions for "passive edit mode"
1362
/////////////////////////////////////////////////////////////////////////////
1363
static s32 PassiveEditEnter(void)
1364
{
1365
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1351 tk 1366
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
1350 tk 1367
 
1351 tk 1368
  // passive edit mode currently only supported for notes/chords
1350 tk 1369
 
1351 tk 1370
  if( layer_type == SEQ_PAR_Type_Note || layer_type == SEQ_PAR_Type_Chord ) {
1371
    // enter passive edit mode and store track/step/layer/instrument for later checks
1372
    edit_passive_mode = 1;
1373
    edit_passive_track = visible_track;
1374
    edit_passive_step = ui_selected_step;
1375
    edit_passive_par_layer = ui_selected_par_layer;
1376
    edit_passive_instrument = ui_selected_instrument;
1377
    edit_passive_value = SEQ_PAR_Get(edit_passive_track, edit_passive_step, edit_passive_par_layer, edit_passive_instrument);
1378
  } else {
1379
    edit_passive_mode = 0;
1380
  }
1381
 
1350 tk 1382
  return 0; // no error
1383
}
1384
 
1385
static s32 PassiveEditValid(void)
1386
{
1387
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1388
 
1389
  return (edit_passive_mode == 2 && // if mode is 2, the value has been changed!
1390
      edit_passive_track == visible_track &&
1391
      edit_passive_step == ui_selected_step &&
1392
      edit_passive_par_layer == ui_selected_par_layer &&
1393
      edit_passive_instrument == ui_selected_instrument) ? 1 : 0;
1394
}
1395
 
1396
static s32 PassiveEditTakeOver(void)
1397
{
1398
 
1399
  // only take over changed value if track/step/layer/instrument still passing
1400
  if( PassiveEditValid() ) {
1401
    // take over change
1402
    // handle it like a single increment/decrement so that no code needs to be duplicated
1403
    int current_value = SEQ_PAR_Get(edit_passive_track, edit_passive_step, edit_passive_par_layer, edit_passive_instrument);
1404
    int incrementer = (int)edit_passive_value - current_value;
1405
 
2048 tk 1406
    seq_ui_button_state.EDIT_PRESSED = 0; // just to avoid any overlay...
1350 tk 1407
    edit_passive_mode = 0; // to avoid recursion in encoder handler
1408
    Encoder_Handler(edit_passive_step % 16, incrementer);
1409
  } else {
1410
    edit_passive_mode = 1;
1411
  }
1412
 
1413
  return 0; // no error
1414
}