Subversion Repositories svn.mios32

Rev

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