Subversion Repositories svn.mios32

Rev

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