Subversion Repositories svn.mios32

Rev

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