Subversion Repositories svn.mios32

Rev

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