Subversion Repositories svn.mios32

Rev

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