Subversion Repositories svn.mios32

Rev

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