Subversion Repositories svn.mios32

Rev

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