Subversion Repositories svn.mios32

Rev

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