Subversion Repositories svn.mios32

Rev

Rev 2505 | Rev 2538 | 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 2533 2017-10-13 22:54:08Z 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
 
2533 tk 61
static u8 edit_ramp;
2101 tk 62
 
2533 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
 
2533 tk 102
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPS && (seq_ui_button_state.CHANGE_ALL_STEPS || seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE) && 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 ) {
2533 tk 184
    if( !seq_ui_button_state.CHANGE_ALL_STEPS && !seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
1753 tk 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
    }
2533 tk 380
 
381
    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
2533 tk 391
    if( !seq_ui_button_state.CHANGE_ALL_STEPS && !seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
1751 tk 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
2533 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) {
2533 tk 452
      if( !(seq_ui_button_state.CHANGE_ALL_STEPS || seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE) || (!edit_ramp && par_step == changed_step) || (selected_steps & (1 << (par_step % 16))) ) {
1751 tk 453
        change_gate = trg_step == changed_step;
454
        u8 dont_change_gate = par_step != changed_step;
2533 tk 455
        if( change_gate || seq_ui_button_state.CHANGE_ALL_STEPS || seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
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 &&
2533 tk 520
    ((seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPS && (seq_ui_button_state.CHANGE_ALL_STEPS || seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE)) ||
2063 tk 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
2533 tk 590
    if( seq_hwcfg_button_beh.all_with_triggers && (seq_ui_button_state.CHANGE_ALL_STEPS || seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE) ) {
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;
2294 tk 787
    for(i=1; i<num_p_layers; ++i) {
788
      char str_buffer[6];
789
      SEQ_PAR_AssignedTypeStr(visible_track, i, str_buffer);
790
      SEQ_LCD_PrintString(str_buffer);
791
    }
1142 tk 792
 
793
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
794
 
795
    ///////////////////////////////////////////////////////////////////////////
796
    SEQ_LCD_CursorSet(0, 1);
2049 tk 797
    SEQ_LCD_PrintFormattedString((seq_record_state.ENABLED || midi_learn_mode == MIDI_LEARN_MODE_ON) ? "{%3d}" : " %3d ", ui_selected_step+1);
1142 tk 798
    SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? '*' : 'o');
799
    SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_AccentGet(visible_track, ui_selected_step, ui_selected_instrument) ? '*' : 'o');
800
    SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_GlideGet(visible_track, ui_selected_step, ui_selected_instrument) ? '*' : 'o');
801
 
1351 tk 802
    u8 note = SEQ_PAR_Get(visible_track, ui_selected_step, 0, ui_selected_instrument);
1142 tk 803
    u8 note_octave = note / 12;
804
    u8 note_key = note % 12;
805
 
806
    SEQ_LCD_PrintFormattedString(" %2d  ", (int)note_octave-2);
807
    const char note_tab[12][2] = { "C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B " };
808
    SEQ_LCD_PrintFormattedString("  %c%c ", note_tab[note_key][0], note_tab[note_key][1]);
809
 
810
    for(i=1; i<num_p_layers; ++i)
811
      if( i == ui_selected_par_layer && ui_cursor_flash )
812
    SEQ_LCD_PrintSpaces(5);
813
      else {
1351 tk 814
    int print_edit_value = PassiveEditValid() ? edit_passive_value : -1;
815
    SEQ_LCD_PrintLayerEvent(visible_track, ui_selected_step, i, ui_selected_instrument, 0, print_edit_value);
1142 tk 816
    SEQ_LCD_PrintChar(' ');
817
      }
818
 
819
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
820
 
821
    return 0;
822
  }
823
 
1316 tk 824
  if( !edit_mode && event_mode != SEQ_EVENT_MODE_Drum &&
1142 tk 825
      (seq_ui_edit_view == SEQ_UI_EDIT_VIEW_LAYERS || seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG) ) {
826
 
827
    // we want to show vertical bars
828
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
829
 
830
    u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
831
    u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
832
 
833
    if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_TRG ) {
834
      // maximum 7 parameter layers due to "Step" item!
835
      if( num_t_layers >= 7 )
836
    num_t_layers = 7;
837
 
838
      // maximum 8 parameter layers
839
      if( num_p_layers >= 8 )
840
    num_p_layers = 8;
841
    } else {
842
      // single trigger layer (gate)
843
      num_t_layers = 1;
844
 
845
      // maximum 14 parameter layers due to "Step" and "Gate" item!
846
      if( num_p_layers >= 14 )
847
    num_p_layers = 14;
848
    }
849
 
850
    ///////////////////////////////////////////////////////////////////////////
851
    SEQ_LCD_CursorSet(0, 0);
852
    SEQ_LCD_PrintString("Step ");
853
    int i;
854
    for(i=0; i<num_t_layers; ++i)
2294 tk 855
      SEQ_LCD_PrintString(SEQ_TRG_AssignedTypeStr(visible_track, i));
1142 tk 856
 
2294 tk 857
    for(i=0; i<num_p_layers; ++i) {
858
      char str_buffer[6];
859
      SEQ_PAR_AssignedTypeStr(visible_track, i, str_buffer);
860
      SEQ_LCD_PrintString(str_buffer);
861
    }
862
 
1142 tk 863
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
864
 
865
    ///////////////////////////////////////////////////////////////////////////
866
    SEQ_LCD_CursorSet(0, 1);
2049 tk 867
    SEQ_LCD_PrintFormattedString((seq_record_state.ENABLED || midi_learn_mode == MIDI_LEARN_MODE_ON) ? "{%3d}" : " %3d ", ui_selected_step+1);
1142 tk 868
    for(i=0; i<num_t_layers; ++i)
869
      SEQ_LCD_PrintFormattedString("  %c  ", SEQ_TRG_Get(visible_track, ui_selected_step, i, ui_selected_instrument) ? '*' : 'o');
870
    for(i=0; i<num_p_layers; ++i)
871
      if( i == ui_selected_par_layer && ui_cursor_flash )
872
    SEQ_LCD_PrintSpaces(5);
873
      else {
1351 tk 874
    int print_edit_value = PassiveEditValid() ? edit_passive_value : -1;
875
    SEQ_LCD_PrintLayerEvent(visible_track, ui_selected_step, i, ui_selected_instrument, 0, print_edit_value);
1142 tk 876
    SEQ_LCD_PrintChar(' ');
877
      }
878
 
879
    SEQ_LCD_PrintSpaces(80 - (5*num_p_layers));
880
 
881
    return 0;
882
  }
883
 
176 tk 884
  seq_layer_evnt_t layer_event;
336 tk 885
  SEQ_LAYER_GetEvntOfLayer(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
168 tk 886
 
333 tk 887
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
176 tk 888
 
333 tk 889
  // TODO: tmp. solution to print chord velocity correctly
890
  if( layer_type == SEQ_PAR_Type_Velocity && (seq_cc_trk[visible_track].link_par_layer_chord == 0) )
2274 tk 891
    layer_type = SEQ_PAR_Type_Chord1;
326 tk 892
 
333 tk 893
 
167 tk 894
  ///////////////////////////////////////////////////////////////////////////
278 tk 895
  SEQ_LCD_CursorSet(0, 0);
167 tk 896
 
326 tk 897
  SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
898
  SEQ_LCD_PrintSpaces(1);
899
 
1349 tk 900
 
2166 tk 901
  u8 print_instrument = 0;
1350 tk 902
  if( ui_page == SEQ_UI_PAGE_EDIT && edit_passive_mode == 2 ) {
2166 tk 903
    if( !ui_cursor_flash ) {
1350 tk 904
      SEQ_LCD_PrintString("PASSIVE EDITING");
905
    }
2050 tk 906
  } else if( seq_record_state.ENABLED || edit_mode == SEQ_UI_EDIT_MODE_RECORD || midi_learn_mode == MIDI_LEARN_MODE_ON ) {
2166 tk 907
    if( !ui_cursor_flash ) {
2050 tk 908
      if( midi_learn_mode == MIDI_LEARN_MODE_ON ) {
909
    SEQ_LCD_PrintString("EDIT RECORDING ");
910
      } else if( seq_record_options.STEP_RECORD ) {
911
    SEQ_LCD_PrintString("STEP RECORDING ");
912
      } else {
913
    SEQ_LCD_PrintString("LIVE RECORDING ");
914
      }
1349 tk 915
    }
916
  } else {
917
    switch( edit_mode ) {
240 tk 918
    case SEQ_UI_EDIT_MODE_COPY: {
2166 tk 919
      if( !ui_cursor_flash ) {
240 tk 920
    char str_buffer[10];
921
    sprintf(str_buffer, "%d-%d", SEQ_UI_UTIL_CopyPasteBeginGet()+1, SEQ_UI_UTIL_CopyPasteEndGet()+1);
278 tk 922
    SEQ_LCD_PrintFormattedString("COPY S%-9s", str_buffer);
240 tk 923
      }
924
    } break;
167 tk 925
 
240 tk 926
    case SEQ_UI_EDIT_MODE_PASTE: {
2166 tk 927
      if( !ui_cursor_flash ) {
278 tk 928
    SEQ_LCD_PrintFormattedString("PASTE OFFS.%3d ", ui_selected_step+1);
240 tk 929
      }
930
    } break;
167 tk 931
 
240 tk 932
    case SEQ_UI_EDIT_MODE_MOVE: {
2166 tk 933
      if( !ui_cursor_flash ) {
278 tk 934
    SEQ_LCD_PrintString("MOVE STEPS     ");
240 tk 935
      }
936
    } break;
176 tk 937
 
240 tk 938
    case SEQ_UI_EDIT_MODE_SCROLL: {
2166 tk 939
      if( !ui_cursor_flash ) {
278 tk 940
    SEQ_LCD_PrintString("SCROLL TRACK   ");
240 tk 941
      }
942
    } break;
176 tk 943
 
240 tk 944
    case SEQ_UI_EDIT_MODE_RANDOM: {
2166 tk 945
      if( !ui_cursor_flash ) {
278 tk 946
    SEQ_LCD_PrintString("RANDOMIZED     ");
240 tk 947
      }
948
    } break;
176 tk 949
 
600 tk 950
    case SEQ_UI_EDIT_MODE_MANUAL: {
2166 tk 951
      if( !ui_cursor_flash ) {
600 tk 952
    SEQ_LCD_PrintString("MANUAL TRIGGER ");
953
      }
954
    } break;
955
 
240 tk 956
    default: {
2533 tk 957
      if( seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE ) {
958
    if( edit_ramp ) {
959
      SEQ_LCD_PrintString("VALUE RAMP     ");
960
    } else {
961
      SEQ_LCD_PrintString("ALL VALUES     ");
962
    }
963
      } else if( seq_ui_button_state.CHANGE_ALL_STEPS ) {
964
    SEQ_LCD_PrintString("RELATIVE VALUES");
965
      } else {
966
    print_instrument = 1;
967
      }
326 tk 968
    }
1349 tk 969
    }
326 tk 970
  }
176 tk 971
 
2166 tk 972
  if( print_instrument || ui_cursor_flash ) {
973
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
974
      SEQ_LCD_PrintChar(' ');
975
      SEQ_LCD_PrintChar(' ');
976
      SEQ_LCD_PrintMIDIOutPort(SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT));
977
      SEQ_LCD_PrintChar(' ');
978
      SEQ_LCD_PrintFormattedString("Chn.%2d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
979
    } else {
980
      SEQ_LCD_PrintTrackLabel(visible_track, (char *)seq_core_trk[visible_track].name);
981
    }
982
  }
983
 
326 tk 984
  SEQ_LCD_PrintSpaces(2);
176 tk 985
 
326 tk 986
  SEQ_LCD_PrintChar('P');
987
  SEQ_LCD_PrintChar('A' + ui_selected_par_layer);
988
  SEQ_LCD_PrintChar(':');
240 tk 989
 
2294 tk 990
  {
991
    char str_buffer[6];
992
    SEQ_PAR_AssignedTypeStr(visible_track, ui_selected_par_layer, str_buffer);
993
    SEQ_LCD_PrintString(str_buffer);
333 tk 994
    SEQ_LCD_PrintSpaces(2);
176 tk 995
  }
167 tk 996
 
328 tk 997
  SEQ_LCD_PrintFormattedString("T%c:%s", 'A' + ui_selected_trg_layer, SEQ_TRG_AssignedTypeStr(visible_track, ui_selected_trg_layer));
327 tk 998
 
999
 
167 tk 1000
  ///////////////////////////////////////////////////////////////////////////
278 tk 1001
  SEQ_LCD_CursorSet(40, 0);
167 tk 1002
 
1316 tk 1003
  SEQ_LCD_PrintFormattedString("Step%3d ", ui_selected_step+1);
167 tk 1004
 
1316 tk 1005
  if( layer_event.midi_package.event == CC ) {
1006
    mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
1007
    u8 loopback = port == 0xf0;
741 tk 1008
 
1316 tk 1009
    if( loopback )
1010
      SEQ_LCD_PrintString((char *)SEQ_CC_LABELS_Get(port, layer_event.midi_package.cc_number));
1811 tk 1011
    else {
1012
      if( layer_event.midi_package.cc_number >= 0x80 ) {
1013
    SEQ_LCD_PrintFormattedString("  CC#off");
1014
      } else {
1015
    SEQ_LCD_PrintFormattedString("  CC#%3d", layer_event.midi_package.cc_number);
1016
      }
1017
    }
1351 tk 1018
    SEQ_LCD_PrintFormattedString(" %3d ", layer_event.midi_package.value);
1019
    SEQ_LCD_PrintVBar(layer_event.midi_package.value >> 4);
1316 tk 1020
  } else {
1021
    SEQ_LCD_PrintSpaces(2);
741 tk 1022
 
1316 tk 1023
    if( layer_event.midi_package.note && layer_event.midi_package.velocity && (layer_event.len >= 0) ) {
1024
      if( SEQ_CC_Get(visible_track, SEQ_CC_MODE) == SEQ_CORE_TRKMODE_Arpeggiator ) {
1350 tk 1025
    u8 par_value = PassiveEditValid() ? edit_passive_value : layer_event.midi_package.note;
1026
    SEQ_LCD_PrintArp(par_value);
2505 tk 1027
      } else if( layer_type == SEQ_PAR_Type_Chord1 || layer_type == SEQ_PAR_Type_Chord2 || layer_type == SEQ_PAR_Type_Chord3 ) {
1350 tk 1028
    u8 par_value = PassiveEditValid()
1029
      ? edit_passive_value
2444 tk 1030
      : SEQ_PAR_Get(visible_track, ui_selected_step, ui_selected_par_layer, ui_selected_instrument);
1350 tk 1031
 
2505 tk 1032
    u8 chord_set = (layer_type == SEQ_PAR_Type_Chord2) ? 1 : ((layer_type == SEQ_PAR_Type_Chord3) ? 2 : 0);
1033
 
1034
    if( layer_type == SEQ_PAR_Type_Chord3 ) {
1035
      SEQ_LCD_PrintString(SEQ_CHORD_NameGet(chord_set, par_value));
1036
      SEQ_LCD_PrintSpaces(2);
1037
    } else {
1038
      u8 chord_ix = par_value & 0x1f;
1039
      u8 chord_oct = par_value >> 5;
1040
      SEQ_LCD_PrintString(SEQ_CHORD_NameGet(chord_set, chord_ix));
1041
      SEQ_LCD_PrintFormattedString("/%d", chord_oct);
1042
    }
1316 tk 1043
      } else {
1350 tk 1044
    u8 par_value = PassiveEditValid() ? edit_passive_value : layer_event.midi_package.note;
1045
    SEQ_LCD_PrintNote(par_value);
288 tk 1046
      }
1351 tk 1047
      SEQ_LCD_PrintVBar(layer_event.midi_package.velocity >> 4);
176 tk 1048
    }
1316 tk 1049
    else {
1050
      SEQ_LCD_PrintString("....");
1051
    }
1052
    SEQ_LCD_PrintFormattedString(" Vel:%3d", layer_event.midi_package.velocity);
176 tk 1053
  }
167 tk 1054
 
1316 tk 1055
  SEQ_LCD_PrintString(" Len:");
1056
  SEQ_LCD_PrintGatelength(layer_event.len);
167 tk 1057
 
1316 tk 1058
 
740 tk 1059
  // print flashing *LOOPED* at right corner if loop mode activated to remind that steps will be played differntly
1060
  if( (ui_cursor_flash_overrun_ctr & 1) && seq_core_state.LOOP ) {
1061
    SEQ_LCD_PrintString(" *LOOPED*");
828 tk 1062
  } else if( (ui_cursor_flash_overrun_ctr & 1) && seq_core_trk[visible_track].play_section > 0 ) {
1063
    SEQ_LCD_PrintFormattedString(" *Sect.%c*", 'A'+seq_core_trk[visible_track].play_section);
326 tk 1064
  } else {
740 tk 1065
    SEQ_LCD_PrintSpaces(4);
1066
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1067
      SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
1068
    } else {
1069
      SEQ_LCD_PrintTrackCategory(visible_track, (char *)seq_core_trk[visible_track].name);
1070
    }
180 tk 1071
  }
167 tk 1072
 
1073
  ///////////////////////////////////////////////////////////////////////////
1211 tk 1074
  // Second Line
1075
  ///////////////////////////////////////////////////////////////////////////
167 tk 1076
 
2101 tk 1077
  u8 show_drum_triggers = event_mode == SEQ_EVENT_MODE_Drum;
1078
  if( show_drum_triggers && !(edit_mode || !ui_hold_msg_ctr) ) {
1079
    if( ui_hold_msg_ctr ) {
1080
      // e.g. during recording: show drum triggers for layers which can't be recorded
1081
      show_drum_triggers =
2106 tk 1082
    !ui_hold_msg_ctr_drum_edit &&
2101 tk 1083
    layer_type != SEQ_PAR_Type_Note &&
2274 tk 1084
    layer_type != SEQ_PAR_Type_Chord1 &&
1085
    layer_type != SEQ_PAR_Type_Chord2 &&
2505 tk 1086
    layer_type != SEQ_PAR_Type_Chord3 &&
2101 tk 1087
    layer_type != SEQ_PAR_Type_Velocity &&
1088
    layer_type != SEQ_PAR_Type_CC &&
1089
    layer_type != SEQ_PAR_Type_PitchBend &&
1090
    layer_type != SEQ_PAR_Type_ProgramChange;
1091
    }
1092
  }
335 tk 1093
 
176 tk 1094
  // extra handling for gatelength (shows vertical bars)
335 tk 1095
  if( !show_drum_triggers && layer_type == SEQ_PAR_Type_Length ) {
167 tk 1096
 
176 tk 1097
    // we want to show horizontal bars
1098
    SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_HBars);
167 tk 1099
 
176 tk 1100
    // initial cursor position
278 tk 1101
    SEQ_LCD_CursorSet(0, 1);
167 tk 1102
 
176 tk 1103
    // determine length of previous step (depends on selected view and track length)
1104
    int previous_step = 16*ui_selected_step_view - 1;
1105
    if( previous_step < 0 )
1106
      previous_step = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
1107
 
1108
    seq_layer_evnt_t layer_event;
336 tk 1109
    SEQ_LAYER_GetEvntOfLayer(visible_track, previous_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
176 tk 1110
    u16 previous_length = layer_event.len;
330 tk 1111
 
1112
    // show length of 16 steps
336 tk 1113
    u16 step;
330 tk 1114
    for(step=0; step<16; ++step) {
336 tk 1115
      u16 visible_step = step + 16*ui_selected_step_view;
1116
      SEQ_LAYER_GetEvntOfLayer(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument, &layer_event);
330 tk 1117
 
1143 tk 1118
      u8 gate = SEQ_TRG_GateGet(visible_track, visible_step, ui_selected_instrument);
1119
 
338 tk 1120
      // muted step? if previous gatelength <= 96, print spaces
1143 tk 1121
      if( (!gate || !layer_event.midi_package.velocity) && previous_length < 96 ) {
338 tk 1122
    SEQ_LCD_PrintSpaces(5);
1123
      } else {
1124
    if( layer_event.len >= 96 )
1125
      SEQ_LCD_PrintHBar(15); // glide or stretched event
2159 tk 1126
    else {
1127
      //SEQ_LCD_PrintHBar(((layer_event.len-1)*16)/100);
1128
      SEQ_LCD_PrintHBar(((layer_event.len-1)*16)/110); // so that we see a difference if note not stretched
1129
    }
330 tk 1130
      }
1143 tk 1131
      previous_length = ((gate && layer_event.midi_package.velocity) || (previous_length >= 96 && layer_event.len >= 96)) ? layer_event.len : 0;
330 tk 1132
    }
1133
 
176 tk 1134
  } else {
1135
 
335 tk 1136
    if( show_drum_triggers ) {
323 tk 1137
      // we want to show triggers
325 tk 1138
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_DrumSymbolsBig);
323 tk 1139
    } else {
1140
      // we want to show vertical bars
1141
      SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_VBars);
1142
    }
176 tk 1143
 
1144
    // initial cursor position
278 tk 1145
    SEQ_LCD_CursorSet(0, 1);
176 tk 1146
 
323 tk 1147
    int step_region_begin;
1148
    int step_region_end;
240 tk 1149
    switch( edit_mode ) {
1150
      case SEQ_UI_EDIT_MODE_COPY:
1151
    step_region_begin = SEQ_UI_UTIL_CopyPasteBeginGet();
1152
    step_region_end = SEQ_UI_UTIL_CopyPasteEndGet();
1153
    break;
1154
      case SEQ_UI_EDIT_MODE_PASTE:
1155
    step_region_begin = ui_selected_step;
1156
    step_region_end = ui_selected_step + SEQ_UI_UTIL_CopyPasteEndGet() - SEQ_UI_UTIL_CopyPasteBeginGet();
1157
    break;
1158
      case SEQ_UI_EDIT_MODE_SCROLL:
1159
    step_region_begin = ui_selected_step;
1160
    step_region_end = SEQ_CC_Get(visible_track, SEQ_CC_LENGTH);
1161
    break;
1162
      default:
336 tk 1163
    step_region_begin = ui_selected_step;
1164
    step_region_end = ui_selected_step;
240 tk 1165
    }
1166
 
336 tk 1167
    u16 step;
176 tk 1168
    for(step=0; step<16; ++step) {
336 tk 1169
      u16 visible_step = step + 16*ui_selected_step_view;
240 tk 1170
 
1171
      if( ui_cursor_flash &&
1172
      edit_mode != SEQ_UI_EDIT_MODE_NORMAL &&
1173
      visible_step >= step_region_begin && visible_step <= step_region_end ) {
1174
    SEQ_LCD_PrintSpaces(5);
1175
    continue;
1176
      }
1177
 
335 tk 1178
      if( show_drum_triggers ) {
336 tk 1179
    u8 gate_accent = SEQ_TRG_Get(visible_track, visible_step, 0, ui_selected_instrument);
328 tk 1180
    if( SEQ_TRG_NumLayersGet(visible_track) >= 2 )
336 tk 1181
      gate_accent |= SEQ_TRG_Get(visible_track, visible_step, 1, ui_selected_instrument) << 1;
335 tk 1182
 
323 tk 1183
    SEQ_LCD_PrintChar(' ');
1184
    SEQ_LCD_PrintChar(' ');
327 tk 1185
    SEQ_LCD_PrintChar(gate_accent);
323 tk 1186
    SEQ_LCD_PrintChar(' ');
1187
      } else {
1351 tk 1188
    int print_edit_value = (visible_step == edit_passive_step && PassiveEditValid()) ? edit_passive_value : -1;
1189
    SEQ_LCD_PrintLayerEvent(visible_track, visible_step, ui_selected_par_layer, ui_selected_instrument, 1, print_edit_value);
176 tk 1190
      }
1191
 
2101 tk 1192
      {
2049 tk 1193
    u8 midi_learn = seq_record_state.ENABLED || midi_learn_mode == MIDI_LEARN_MODE_ON;
1194
    char lbr = midi_learn ? '}' : '<';
1195
    char rbr = midi_learn ? '{' : '>';
2047 tk 1196
 
1197
    SEQ_LCD_PrintChar((visible_step == step_region_end) ? lbr
1198
              : ((visible_step == (step_region_begin-1)) ? rbr : ' '));
323 tk 1199
      }
240 tk 1200
 
176 tk 1201
    }
167 tk 1202
  }
1203
 
1204
  return 0; // no error
1205
}
1206
 
1207
 
1208
/////////////////////////////////////////////////////////////////////////////
240 tk 1209
// Local Display Handler function
1210
// IN: <high_prio>: if set, a high-priority LCD update is requested
1211
/////////////////////////////////////////////////////////////////////////////
1212
static s32 LCD_Handler(u8 high_prio)
1213
{
1214
  return SEQ_UI_EDIT_LCD_Handler(high_prio, SEQ_UI_EDIT_MODE_NORMAL);
1215
}
1216
 
1217
 
1218
/////////////////////////////////////////////////////////////////////////////
2047 tk 1219
// MIDI IN
1220
/////////////////////////////////////////////////////////////////////////////
1221
static s32 MIDI_IN_Handler(mios32_midi_port_t port, mios32_midi_package_t p)
1222
{
1223
  if( midi_learn_mode == MIDI_LEARN_MODE_ON ) {
2048 tk 1224
    u8 visible_track = SEQ_UI_VisibleTrackGet();
1225
 
2047 tk 1226
    // quick & dirty for evaluation purposes
1227
    seq_record_options_t prev_seq_record_options = seq_record_options;
2168 tk 1228
    u8 reset_timestamps = p.type == NoteOn && p.velocity > 0;
2047 tk 1229
 
1230
    seq_record_options.ALL = 0;
1231
    seq_record_options.STEP_RECORD = 1;
1232
    seq_record_options.FWD_MIDI = prev_seq_record_options.FWD_MIDI;
1233
 
2168 tk 1234
    SEQ_RECORD_Enable(1, reset_timestamps);
2047 tk 1235
 
2048 tk 1236
    SEQ_RECORD_Receive(p, visible_track);
2047 tk 1237
 
2048 tk 1238
    if( seq_ui_button_state.CHANGE_ALL_STEPS ) {
1239
      // copy matching par layers into remaining steps
1240
      u16 num_steps = SEQ_TRG_NumStepsGet(visible_track);
1241
      u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1242
 
1243
      seq_cc_trk_t *tcc = &seq_cc_trk[visible_track];
1244
      seq_par_layer_type_t rec_layer_type = tcc->lay_const[ui_selected_par_layer];
1245
 
1246
      {
1247
    u8 p_layer;
1248
    for(p_layer=0; p_layer<num_p_layers; ++p_layer) {
1249
      seq_par_layer_type_t layer_type = tcc->lay_const[p_layer];
1250
 
1251
      if( layer_type == rec_layer_type ||
2505 tk 1252
          ((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 1253
        u8 value = SEQ_PAR_Get(visible_track, ui_selected_step, p_layer, ui_selected_instrument);
2048 tk 1254
 
1255
        u16 step;
1256
        for(step=0; step<num_steps; ++step) {
2166 tk 1257
          if( step != ui_selected_step && (selected_steps & (1 << (step % 16))) ) {
2048 tk 1258
        SEQ_PAR_Set(visible_track, step, p_layer, ui_selected_instrument, value);
1259
          }
1260
        }
1261
      }
1262
    }
1263
      }
1264
    }
1265
 
2047 tk 1266
    seq_record_options.ALL = prev_seq_record_options.ALL;
2168 tk 1267
    SEQ_RECORD_Enable(0, 0);
2047 tk 1268
 
2106 tk 1269
    ui_hold_msg_ctr_drum_edit = 0;
1270
 
2047 tk 1271
    seq_ui_display_update_req = 1;
2166 tk 1272
 
1273
    return 1; // don't continue recording/live forwarding processing
2047 tk 1274
  }
1275
 
1276
  return 0;
1277
}
1278
 
1279
 
1280
/////////////////////////////////////////////////////////////////////////////
2101 tk 1281
// Stores config file if required
1282
/////////////////////////////////////////////////////////////////////////////
1283
static s32 CheckStoreFile(void)
1284
{
2102 tk 1285
  if( ui_store_file_required ) {
2101 tk 1286
    // write config file
1287
    MUTEX_SDCARD_TAKE;
1288
    s32 status;
1289
    if( (status=SEQ_FILE_GC_Write()) < 0 )
1290
      SEQ_UI_SDCardErrMsg(2000, status);
1291
    MUTEX_SDCARD_GIVE;
1292
 
2102 tk 1293
    ui_store_file_required = 0;
2101 tk 1294
  }
1295
 
1296
  return 0; // no error
1297
}
1298
 
1299
 
1300
/////////////////////////////////////////////////////////////////////////////
2050 tk 1301
// Exit
1302
/////////////////////////////////////////////////////////////////////////////
1303
static s32 EXIT_Handler(void)
1304
{
1305
  midi_learn_mode = MIDI_LEARN_MODE_OFF;
2101 tk 1306
 
1307
  CheckStoreFile();
1308
 
2050 tk 1309
  return 0;
1310
}
1311
 
1312
/////////////////////////////////////////////////////////////////////////////
167 tk 1313
// Initialisation
1314
/////////////////////////////////////////////////////////////////////////////
1315
s32 SEQ_UI_EDIT_Init(u32 mode)
1316
{
1317
  // install callback routines
758 tk 1318
  SEQ_UI_InstallButtonCallback(SEQ_UI_EDIT_Button_Handler);
168 tk 1319
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
240 tk 1320
  SEQ_UI_InstallLEDCallback(SEQ_UI_EDIT_LED_Handler);
168 tk 1321
  SEQ_UI_InstallLCDCallback(LCD_Handler);
2047 tk 1322
  SEQ_UI_InstallMIDIINCallback(MIDI_IN_Handler);
2050 tk 1323
  SEQ_UI_InstallExitCallback(EXIT_Handler);
167 tk 1324
 
2047 tk 1325
  // disable MIDI learn mode by default
1326
  midi_learn_mode = MIDI_LEARN_MODE_OFF;
1327
 
2106 tk 1328
  ui_hold_msg_ctr_drum_edit = 0;
1329
 
1350 tk 1330
  edit_passive_mode = 0;
2533 tk 1331
  edit_ramp = 0;
729 tk 1332
 
1142 tk 1333
  if( seq_ui_edit_view == SEQ_UI_EDIT_VIEW_STEPSEL )
1334
    seq_ui_edit_view = SEQ_UI_EDIT_VIEW_STEPS;
1335
 
167 tk 1336
  return 0; // no error
1337
}
178 tk 1338
 
1339
 
1340
 
1341
/////////////////////////////////////////////////////////////////////////////
1342
// help function to change/set a single encoder value
1343
// if forced_value >= 0: new value will be set to the given value
1344
// if forced_value < 0: new value will be changed via incrementer
1345
// returns >= 0 if new value has been set (value change)
1346
// returns < 0 if no change
1347
/////////////////////////////////////////////////////////////////////////////
1052 tk 1348
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 1349
{
333 tk 1350
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(track, ui_selected_par_layer);
335 tk 1351
  u8 visible_track = SEQ_UI_VisibleTrackGet();
178 tk 1352
 
828 tk 1353
#if 0
1354
  // disabled in MBSEQ V4.0beta15 due to issue reported by Gridracer:
1355
  // http://midibox.org/forums/index.php?/topic/13137-midibox-seq-v4-beta-release-feedback/page__st__100
1356
 
333 tk 1357
  // if note/chord/velocity parameter: only change gate if requested
2505 tk 1358
  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 1359
      !change_gate &&
652 tk 1360
      !SEQ_TRG_GateGet(track, trg_step, ui_selected_instrument) )
178 tk 1361
    return -1;
828 tk 1362
#endif
178 tk 1363
 
1052 tk 1364
  if( layer_type == SEQ_PAR_Type_Probability ) {
1365
    // due to another issue reported by Gridracer:
1366
    // invert incrementer so that clockwise move increases probability
1367
    incrementer = -incrementer;
1368
  }
1369
 
1370
 
335 tk 1371
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
652 tk 1372
  if( event_mode == SEQ_EVENT_MODE_Drum ) {
335 tk 1373
    ui_hold_msg_ctr = 1000; // show value for 1 second
2106 tk 1374
    ui_hold_msg_ctr_drum_edit = 1;
1375
  } else {
1376
    ui_hold_msg_ctr_drum_edit = 0;
652 tk 1377
  }
335 tk 1378
 
652 tk 1379
  s32 old_value = SEQ_PAR_Get(track, par_step, ui_selected_par_layer, ui_selected_instrument);
178 tk 1380
  s32 new_value = (forced_value >= 0) ? forced_value : (old_value + incrementer);
1381
  if( new_value < 0 )
1382
    new_value = 0;
2448 tk 1383
  else {
1384
    // limit depending on max value
2435 tk 1385
    seq_par_layer_type_t par_layer_type = SEQ_PAR_AssignmentGet(track, ui_selected_par_layer);
2448 tk 1386
    u8 max = SEQ_PAR_MaxValueGet(par_layer_type);
2435 tk 1387
 
2448 tk 1388
    if( new_value >= max ) {
1389
      new_value = max;
2435 tk 1390
    }
1391
  }
178 tk 1392
 
1143 tk 1393
  // extra for more comfortable editing of multi-note tracks:
1394
  // if assigned parameter layer is Note or Chord, and currently 0, re-start at C-3 resp. A/2
1395
  // when value is incremented
2505 tk 1396
  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 1397
    new_value = (layer_type == SEQ_PAR_Type_Note && SEQ_CC_Get(track, SEQ_CC_MODE) != SEQ_CORE_TRKMODE_Arpeggiator) ? 0x3c : 0x40;
1398
 
1345 tk 1399
  if( !dont_change_gate ) {
1400
    u8 event_mode = SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
1401
 
1402
    // we do this always regardless if value has been changed or not (e.g. increment if value already 127)
1403
    if( event_mode == SEQ_EVENT_MODE_CC && layer_type == SEQ_PAR_Type_CC ) {
1404
      // in this mode gates are used to disable CC
1405
      // if a CC value has been changed, set gate
1406
      SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 1);
1407
    }
1408
  }
1409
 
178 tk 1410
  // take over if changed
1411
  if( new_value == old_value )
1412
    return -1;
1413
 
652 tk 1414
  SEQ_PAR_Set(track, par_step, ui_selected_par_layer, ui_selected_instrument, (u8)new_value);
178 tk 1415
 
747 tk 1416
  if( !dont_change_gate &&
2505 tk 1417
      (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 1418
    // (de)activate gate depending on value
1419
    if( new_value )
652 tk 1420
      SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 1);
1053 tk 1421
    else {
1422
      // due to another issue reported by Gridracer:
1423
      // if the track plays multiple notes, only clear gate if all notes are 0
1142 tk 1424
      u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1053 tk 1425
      u8 allNotesZero = 1;
1426
      int i;
1142 tk 1427
      for(i=0; i<num_p_layers; ++i) {
1053 tk 1428
    seq_par_layer_type_t localLayerType = SEQ_PAR_AssignmentGet(track, i);
2505 tk 1429
    if( (localLayerType == SEQ_PAR_Type_Note || localLayerType == SEQ_PAR_Type_Chord1 || localLayerType == SEQ_PAR_Type_Chord2 || localLayerType == SEQ_PAR_Type_Chord3) &&
1053 tk 1430
        SEQ_PAR_Get(track, par_step, i, ui_selected_instrument) > 0 ) {
1431
      allNotesZero = 0;
1432
      break;
1433
    }
1434
      }
1435
 
1436
      if( allNotesZero )
1437
    SEQ_TRG_GateSet(track, trg_step, ui_selected_instrument, 0);
1438
    }
178 tk 1439
  }
1440
 
1441
  return new_value;
1442
}
1350 tk 1443
 
1444
 
1445
/////////////////////////////////////////////////////////////////////////////
1446
// help functions for "passive edit mode"
1447
/////////////////////////////////////////////////////////////////////////////
1448
static s32 PassiveEditEnter(void)
1449
{
1450
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1351 tk 1451
  seq_par_layer_type_t layer_type = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
1350 tk 1452
 
1351 tk 1453
  // passive edit mode currently only supported for notes/chords
1350 tk 1454
 
2505 tk 1455
  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 1456
    // enter passive edit mode and store track/step/layer/instrument for later checks
1457
    edit_passive_mode = 1;
1458
    edit_passive_track = visible_track;
1459
    edit_passive_step = ui_selected_step;
1460
    edit_passive_par_layer = ui_selected_par_layer;
1461
    edit_passive_instrument = ui_selected_instrument;
1462
    edit_passive_value = SEQ_PAR_Get(edit_passive_track, edit_passive_step, edit_passive_par_layer, edit_passive_instrument);
1463
  } else {
1464
    edit_passive_mode = 0;
1465
  }
1466
 
1350 tk 1467
  return 0; // no error
1468
}
1469
 
1470
static s32 PassiveEditValid(void)
1471
{
1472
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1473
 
1474
  return (edit_passive_mode == 2 && // if mode is 2, the value has been changed!
1475
      edit_passive_track == visible_track &&
1476
      edit_passive_step == ui_selected_step &&
1477
      edit_passive_par_layer == ui_selected_par_layer &&
1478
      edit_passive_instrument == ui_selected_instrument) ? 1 : 0;
1479
}
1480
 
1481
static s32 PassiveEditTakeOver(void)
1482
{
1483
 
1484
  // only take over changed value if track/step/layer/instrument still passing
1485
  if( PassiveEditValid() ) {
1486
    // take over change
1487
    // handle it like a single increment/decrement so that no code needs to be duplicated
1488
    int current_value = SEQ_PAR_Get(edit_passive_track, edit_passive_step, edit_passive_par_layer, edit_passive_instrument);
1489
    int incrementer = (int)edit_passive_value - current_value;
1490
 
2048 tk 1491
    seq_ui_button_state.EDIT_PRESSED = 0; // just to avoid any overlay...
1350 tk 1492
    edit_passive_mode = 0; // to avoid recursion in encoder handler
1493
    Encoder_Handler(edit_passive_step % 16, incrementer);
1494
  } else {
1495
    edit_passive_mode = 1;
1496
  }
1497
 
1498
  return 0; // no error
1499
}