Subversion Repositories svn.mios32

Rev

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