Subversion Repositories svn.mios32

Rev

Rev 596 | Rev 600 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
134 tk 1
// $Id: seq_ui.c 599 2009-06-12 17:33:51Z tk $
2
/*
3
 * User Interface Routines
4
 *
336 tk 5
 * TODO: allow to loop the selected view while editing a track
6
 * TODO: add loop fx page for setting loop point interactively
7
 * TODO: scroll function should use this loop point
8
 * TODO: utility page in drum mode: allow to handle only selected instrument
9
 *
134 tk 10
 * ==========================================================================
11
 *
12
 *  Copyright (C) 2008 Thorsten Klose (tk@midibox.org)
13
 *  Licensed for personal non-commercial use only.
14
 *  All other rights reserved.
15
 *
16
 * ==========================================================================
17
 */
18
 
19
/////////////////////////////////////////////////////////////////////////////
20
// Include files
21
/////////////////////////////////////////////////////////////////////////////
22
 
272 tk 23
// with this switch, seq_ui.h/seq_ui_pages.inc will create local variables
24
#define SEQ_UI_PAGES_INC_LOCAL_VARS 1
25
 
134 tk 26
#include <mios32.h>
299 tk 27
#include <string.h>
464 tk 28
#include <blm_x.h>
190 tk 29
#include <seq_midi_out.h>
30
#include <seq_bpm.h>
134 tk 31
 
290 tk 32
#include "tasks.h"
134 tk 33
#include "seq_ui.h"
492 tk 34
#include "seq_hwcfg.h"
134 tk 35
#include "seq_lcd.h"
36
#include "seq_led.h"
186 tk 37
#include "seq_midply.h"
134 tk 38
#include "seq_core.h"
399 tk 39
#include "seq_song.h"
333 tk 40
#include "seq_par.h"
178 tk 41
#include "seq_layer.h"
184 tk 42
#include "seq_cc.h"
299 tk 43
#include "seq_file.h"
134 tk 44
 
45
 
46
/////////////////////////////////////////////////////////////////////////////
47
// Global variables
48
/////////////////////////////////////////////////////////////////////////////
49
 
159 tk 50
u8 seq_ui_display_update_req;
51
u8 seq_ui_display_init_req;
134 tk 52
 
167 tk 53
seq_ui_button_state_t seq_ui_button_state;
54
 
134 tk 55
u8 ui_selected_group;
484 tk 56
u16 ui_selected_tracks;
134 tk 57
u8 ui_selected_par_layer;
58
u8 ui_selected_trg_layer;
328 tk 59
u8 ui_selected_instrument;
134 tk 60
u8 ui_selected_step_view;
61
u8 ui_selected_step;
168 tk 62
u8 ui_selected_item;
134 tk 63
 
168 tk 64
u8 ui_selected_item;
134 tk 65
 
240 tk 66
u16 ui_hold_msg_ctr;
67
 
206 tk 68
seq_ui_page_t ui_page;
272 tk 69
seq_ui_page_t ui_selected_page;
206 tk 70
 
173 tk 71
volatile u8 ui_cursor_flash;
72
u16 ui_cursor_flash_ctr;
134 tk 73
 
316 tk 74
u8 ui_edit_name_cursor;
75
u8 ui_edit_preset_num_category;
76
u8 ui_edit_preset_num_label;
77
 
193 tk 78
u8 ui_seq_pause;
79
 
80
 
134 tk 81
/////////////////////////////////////////////////////////////////////////////
82
// Local variables
83
/////////////////////////////////////////////////////////////////////////////
84
 
168 tk 85
static s32 (*ui_button_callback)(seq_ui_button_t button, s32 depressed);
86
static s32 (*ui_encoder_callback)(seq_ui_encoder_t encoder, s32 incrementer);
173 tk 87
static s32 (*ui_led_callback)(u16 *gp_leds);
167 tk 88
static s32 (*ui_lcd_callback)(u8 high_prio);
352 tk 89
static s32 (*ui_exit_callback)(void);
167 tk 90
 
168 tk 91
static u16 ui_gp_leds;
167 tk 92
 
524 tk 93
#define NUM_BLM_LED_SRS (2*4)
94
static u8 ui_blm_leds[NUM_BLM_LED_SRS];
95
 
596 tk 96
#define UI_MSG_MAX_CHAR 21
97
static char ui_msg[2][UI_MSG_MAX_CHAR];
98
static u16 ui_msg_ctr;
99
static seq_ui_msg_type_t ui_msg_type;
299 tk 100
 
101
 
134 tk 102
/////////////////////////////////////////////////////////////////////////////
103
// Initialisation
104
/////////////////////////////////////////////////////////////////////////////
105
s32 SEQ_UI_Init(u32 mode)
106
{
107
  // init selection variables
108
  ui_selected_group = 0;
109
  ui_selected_tracks = (1 << 0);
110
  ui_selected_par_layer = 0;
111
  ui_selected_trg_layer = 0;
328 tk 112
  ui_selected_instrument = 0;
134 tk 113
  ui_selected_step_view = 0;
114
  ui_selected_step = 0;
168 tk 115
  ui_selected_item = 0;
134 tk 116
 
240 tk 117
  ui_hold_msg_ctr = 0;
596 tk 118
  ui_msg_ctr = 0;
240 tk 119
 
168 tk 120
  ui_cursor_flash_ctr = 0;
173 tk 121
  ui_cursor_flash = 0;
168 tk 122
 
167 tk 123
  seq_ui_button_state.ALL = 0;
124
 
193 tk 125
  ui_seq_pause = 0;
126
 
134 tk 127
  // visible GP pattern
128
  ui_gp_leds = 0x0000;
129
 
167 tk 130
  // change to edit page
131
  ui_page = SEQ_UI_PAGE_NONE;
132
  SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
134 tk 133
 
596 tk 134
 
134 tk 135
  return 0; // no error
136
}
137
 
138
 
139
/////////////////////////////////////////////////////////////////////////////
178 tk 140
// Inits the speed mode of all encoders
141
// Auto mode should be used whenever:
142
//    - the edit screen is entered
143
//    - the group is changed
144
//    - a track is changed
145
//    - a layer is changed
146
/////////////////////////////////////////////////////////////////////////////
147
s32 SEQ_UI_InitEncSpeed(u32 auto_config)
148
{
149
  mios32_enc_config_t enc_config;
150
 
151
  if( auto_config ) {
513 tk 152
 
153
    if( !seq_hwcfg_enc.auto_fast )
154
      return 0; // auto mode not enabled - ignore auto reconfiguration request
155
 
333 tk 156
    switch( SEQ_PAR_AssignmentGet(SEQ_UI_VisibleTrackGet(), ui_selected_par_layer) ) {
157
      case SEQ_PAR_Type_Velocity:
158
      case SEQ_PAR_Type_Length:
159
      case SEQ_PAR_Type_CC:
160
      case SEQ_PAR_Type_PitchBend:
161
      case SEQ_PAR_Type_Probability:
162
      case SEQ_PAR_Type_Delay:
163
      case SEQ_PAR_Type_Loopback:
178 tk 164
    seq_ui_button_state.FAST_ENCODERS = 1;
165
    break;
166
 
167
      default:
168
    seq_ui_button_state.FAST_ENCODERS = 0;
169
    }
170
  }
171
 
172
  // change for datawheel and GP encoders
173
  int enc;
174
  for(enc=0; enc<17; ++enc) {
175
    enc_config = MIOS32_ENC_ConfigGet(enc);
176
    enc_config.cfg.speed = seq_ui_button_state.FAST_ENCODERS ? FAST : NORMAL;
513 tk 177
    enc_config.cfg.speed_par = (enc == 0) ? seq_hwcfg_enc.datawheel_fast_speed : seq_hwcfg_enc.gp_fast_speed;
178 tk 178
    MIOS32_ENC_ConfigSet(enc, enc_config);
179
  }
180
 
181
  return 0; // no error
182
}
183
 
184
 
185
/////////////////////////////////////////////////////////////////////////////
167 tk 186
// Various installation routines for menu page LCD handlers
187
/////////////////////////////////////////////////////////////////////////////
168 tk 188
s32 SEQ_UI_InstallButtonCallback(void *callback)
167 tk 189
{
168 tk 190
  ui_button_callback = callback;
167 tk 191
  return 0; // no error
192
}
193
 
168 tk 194
s32 SEQ_UI_InstallEncoderCallback(void *callback)
167 tk 195
{
168 tk 196
  ui_encoder_callback = callback;
167 tk 197
  return 0; // no error
198
}
199
 
168 tk 200
s32 SEQ_UI_InstallLEDCallback(void *callback)
167 tk 201
{
168 tk 202
  ui_led_callback = callback;
167 tk 203
  return 0; // no error
204
}
205
 
168 tk 206
s32 SEQ_UI_InstallLCDCallback(void *callback)
167 tk 207
{
208
  ui_lcd_callback = callback;
209
  return 0; // no error
210
}
211
 
352 tk 212
s32 SEQ_UI_InstallExitCallback(void *callback)
213
{
214
  ui_exit_callback = callback;
215
  return 0; // no error
216
}
167 tk 217
 
352 tk 218
 
167 tk 219
/////////////////////////////////////////////////////////////////////////////
220
// Change the menu page
221
/////////////////////////////////////////////////////////////////////////////
222
s32 SEQ_UI_PageSet(seq_ui_page_t page)
223
{
224
  if( page != ui_page ) {
352 tk 225
 
226
    // call page exit callback
227
    if( ui_exit_callback != NULL )
228
      ui_exit_callback();
229
 
167 tk 230
    // disable hooks of previous page and request re-initialisation
318 tk 231
    portENTER_CRITICAL();
167 tk 232
    ui_page = page;
168 tk 233
    ui_button_callback = NULL;
234
    ui_encoder_callback = NULL;
235
    ui_led_callback = NULL;
167 tk 236
    ui_lcd_callback = NULL;
352 tk 237
    ui_exit_callback = NULL;
318 tk 238
    portEXIT_CRITICAL();
167 tk 239
 
513 tk 240
    if( seq_hwcfg_button_beh.menu )
241
      seq_ui_button_state.MENU_PRESSED = 0; // MENU page selection finished
167 tk 242
 
243
    // request display initialisation
244
    seq_ui_display_init_req = 1;
245
  }
173 tk 246
 
306 tk 247
  // for MENU button:
248
  // first page has been selected - display new screen
249
  seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 1;
250
 
272 tk 251
  // for SEQ_UI_MENU which is accessible with EXIT button
252
  // remember the current selectable page
253
  if( ui_page >= SEQ_UI_FIRST_MENU_SELECTION_PAGE )
254
    ui_selected_page = ui_page;
255
 
184 tk 256
  return 0; // no error
167 tk 257
}
258
 
259
 
260
/////////////////////////////////////////////////////////////////////////////
272 tk 261
// Returns name of menu page (18 characters)
262
/////////////////////////////////////////////////////////////////////////////
263
char *SEQ_UI_PageNameGet(seq_ui_page_t page)
264
{
265
  return ui_menu_pages[page].name;
266
}
267
 
268
 
269
/////////////////////////////////////////////////////////////////////////////
134 tk 270
// Dedicated button functions
271
// Mapped to physical buttons in SEQ_UI_Button_Handler()
272
// Will also be mapped to MIDI keys later (for MIDI remote function)
273
/////////////////////////////////////////////////////////////////////////////
274
static s32 SEQ_UI_Button_GP(s32 depressed, u32 gp)
275
{
306 tk 276
  // in MENU page: overrule GP buttons so long MENU button is pressed/active
277
  if( seq_ui_button_state.MENU_PRESSED ) {
278
    if( depressed ) return -1;
279
    SEQ_UI_PageSet(ui_shortcut_menu_pages[gp]);
280
  } else {
281
    // forward to menu page
282
    if( ui_button_callback != NULL )
283
      ui_button_callback(gp, depressed);
284
    ui_cursor_flash_ctr = 0;
285
  }
134 tk 286
 
287
  return 0; // no error
288
}
289
 
290
static s32 SEQ_UI_Button_Left(s32 depressed)
291
{
168 tk 292
  // forward to menu page
306 tk 293
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 294
    ui_button_callback(SEQ_UI_BUTTON_Left, depressed);
173 tk 295
  ui_cursor_flash_ctr = 0;
134 tk 296
 
297
  return 0; // no error
298
}
299
 
300
static s32 SEQ_UI_Button_Right(s32 depressed)
301
{
168 tk 302
  // forward to menu page
306 tk 303
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 304
    ui_button_callback(SEQ_UI_BUTTON_Right, depressed);
173 tk 305
  ui_cursor_flash_ctr = 0;
134 tk 306
 
307
  return 0; // no error
308
}
309
 
168 tk 310
static s32 SEQ_UI_Button_Down(s32 depressed)
311
{
240 tk 312
  seq_ui_button_state.DOWN = depressed ? 0 : 1;
313
 
168 tk 314
  // forward to menu page
306 tk 315
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 316
    ui_button_callback(SEQ_UI_BUTTON_Down, depressed);
173 tk 317
  ui_cursor_flash_ctr = 0;
168 tk 318
 
319
  return 0; // no error
320
}
321
 
322
static s32 SEQ_UI_Button_Up(s32 depressed)
323
{
240 tk 324
  seq_ui_button_state.UP = depressed ? 0 : 1;
325
 
168 tk 326
  // forward to menu page
306 tk 327
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 328
    ui_button_callback(SEQ_UI_BUTTON_Up, depressed);
173 tk 329
  ui_cursor_flash_ctr = 0;
168 tk 330
 
331
  return 0; // no error
332
}
333
 
134 tk 334
static s32 SEQ_UI_Button_Stop(s32 depressed)
335
{
336
  if( depressed ) return -1; // ignore when button depressed
337
 
159 tk 338
  // if sequencer running: stop it
339
  // if sequencer already stopped: reset song position
186 tk 340
#if MID_PLAYER_TEST
193 tk 341
  if( SEQ_BPM_IsRunning() )
342
    SEQ_BPM_Stop();
186 tk 343
  else
344
    SEQ_MIDPLY_Reset();
345
#else
193 tk 346
  if( SEQ_BPM_IsRunning() )
347
    SEQ_BPM_Stop();
159 tk 348
  else
349
    SEQ_CORE_Reset();
186 tk 350
#endif
159 tk 351
 
134 tk 352
  return 0; // no error
353
}
354
 
355
static s32 SEQ_UI_Button_Pause(s32 depressed)
356
{
357
  if( depressed ) return -1; // ignore when button depressed
358
 
193 tk 359
  // if in auto mode and BPM generator is clocked in slave mode:
360
  // change to master mode
361
  SEQ_BPM_CheckAutoMaster();
159 tk 362
 
193 tk 363
  // toggle pause mode
364
  ui_seq_pause ^= 1;
365
 
366
  // execute stop/continue depending on new mode
367
  if( ui_seq_pause )
368
    SEQ_BPM_Stop();
369
  else
370
    SEQ_BPM_Cont();
371
 
134 tk 372
  return 0; // no error
373
}
374
 
375
static s32 SEQ_UI_Button_Play(s32 depressed)
376
{
377
  if( depressed ) return -1; // ignore when button depressed
378
 
186 tk 379
  // if in auto mode and BPM generator is clocked in slave mode:
380
  // change to master mode
381
  SEQ_BPM_CheckAutoMaster();
382
 
193 tk 383
#if 0
384
  // if sequencer running: restart it
385
  // if sequencer stopped: continue at last song position
386
  if( SEQ_BPM_IsRunning() )
387
    SEQ_BPM_Start();
388
  else
389
    SEQ_BPM_Cont();
186 tk 390
#else
193 tk 391
  // always restart sequencer
392
  SEQ_BPM_Start();
186 tk 393
#endif
159 tk 394
 
134 tk 395
  return 0; // no error
396
}
397
 
398
static s32 SEQ_UI_Button_Rew(s32 depressed)
399
{
240 tk 400
  seq_ui_button_state.REW = depressed ? 0 : 1;
401
 
134 tk 402
  if( depressed ) return -1; // ignore when button depressed
403
 
404
  return 0; // no error
405
}
406
 
407
static s32 SEQ_UI_Button_Fwd(s32 depressed)
408
{
240 tk 409
  seq_ui_button_state.FWD = depressed ? 0 : 1;
410
 
134 tk 411
  if( depressed ) return -1; // ignore when button depressed
412
 
413
  return 0; // no error
414
}
415
 
596 tk 416
static s32 SEQ_UI_Button_Loop(s32 depressed)
417
{
418
  if( seq_hwcfg_button_beh.loop ) {
419
    // toggle mode
420
    if( depressed ) return -1; // ignore when button depressed
421
    // should be atomic
422
    portENTER_CRITICAL();
423
    seq_core_state.LOOP ^= 1;
424
  } else {
425
    // should be atomic
426
    portENTER_CRITICAL();
427
    // set mode
428
    seq_core_state.LOOP = depressed ? 0 : 1;
429
  }
430
  portEXIT_CRITICAL();
431
 
432
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Loop Mode", seq_core_state.LOOP ? "    on" : "   off");
433
 
434
  return 0; // no error
435
}
436
 
437
static s32 SEQ_UI_Button_Scrub(s32 depressed)
438
{
439
  // double function: -> Loop if menu button pressed
440
  if( seq_ui_button_state.MENU_PRESSED )
441
    return SEQ_UI_Button_Loop(depressed);
442
 
443
  if( seq_hwcfg_button_beh.scrub ) {
444
    // toggle mode
445
    if( depressed ) return -1; // ignore when button depressed
446
    seq_ui_button_state.SCRUB ^= 1;
447
  } else {
448
    // set mode
449
    seq_ui_button_state.SCRUB = depressed ? 0 : 1;
450
  }
451
 
452
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Scrub Mode", seq_ui_button_state.SCRUB ? "    on" : "   off");
453
 
454
  return 0; // no error
455
}
456
 
513 tk 457
static s32 SEQ_UI_Button_TempoPreset(s32 depressed)
134 tk 458
{
513 tk 459
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
240 tk 460
 
513 tk 461
  if( seq_hwcfg_button_beh.tempo_preset ) {
462
    if( depressed ) return -1; // ignore when button depressed
463
    seq_ui_button_state.TEMPO_PRESET ^= 1; // toggle TEMPO_PRESET pressed (will also be released once GP button has been pressed)
464
  } else {
465
    // set mode
466
    seq_ui_button_state.TEMPO_PRESET = depressed ? 0 : 1;
467
  }
134 tk 468
 
513 tk 469
  if( seq_ui_button_state.TEMPO_PRESET ) {
470
    prev_page = ui_page;
471
    SEQ_UI_PageSet(SEQ_UI_PAGE_BPM_PRESETS);
472
  } else {
524 tk 473
    if( ui_page == SEQ_UI_PAGE_BPM_PRESETS )
474
      SEQ_UI_PageSet(prev_page);
513 tk 475
  }
240 tk 476
 
134 tk 477
  return 0; // no error
478
}
479
 
513 tk 480
static s32 SEQ_UI_Button_TapTempo(s32 depressed)
134 tk 481
{
513 tk 482
  seq_ui_button_state.TAP_TEMPO = depressed ? 0 : 1;
240 tk 483
 
134 tk 484
  if( depressed ) return -1; // ignore when button depressed
485
 
486
  return 0; // no error
487
}
488
 
524 tk 489
static s32 SEQ_UI_Button_ExtRestart(s32 depressed)
134 tk 490
{
491
  if( depressed ) return -1; // ignore when button depressed
492
 
596 tk 493
  // should be atomic
524 tk 494
  portENTER_CRITICAL();
495
  seq_core_state.EXT_RESTART_REQ = 1;
496
  portEXIT_CRITICAL();
497
 
596 tk 498
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "External Restart", "requested");
499
 
134 tk 500
  return 0; // no error
501
}
502
 
596 tk 503
static s32 SEQ_UI_Button_Metronome(s32 depressed)
504
{
505
  // double function: -> ExtRestart if menu button pressed
506
  if( seq_ui_button_state.MENU_PRESSED )
507
    return SEQ_UI_Button_ExtRestart(depressed);
508
 
509
  if( seq_hwcfg_button_beh.metronome ) {
510
    // toggle mode
511
    if( depressed ) return -1; // ignore when button depressed
512
    // should be atomic
513
    portENTER_CRITICAL();
514
    seq_core_state.METRONOME ^= 1;
515
  } else {
516
    // should be atomic
517
    portENTER_CRITICAL();
518
    // set mode
519
    seq_core_state.METRONOME = depressed ? 0 : 1;
520
  }
521
  portEXIT_CRITICAL();
522
 
523
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Metronome", seq_core_state.METRONOME ? "    on" : "   off");
524
 
599 tk 525
#if 0
526
  // metronome button can be used to trigger pattern file fixes
527
  if( !depressed )
528
    SEQ_PATTERN_FixAll();
529
#endif
530
 
596 tk 531
  return 0; // no error
532
}
533
 
134 tk 534
static s32 SEQ_UI_Button_Utility(s32 depressed)
535
{
536
  if( depressed ) return -1; // ignore when button depressed
537
 
240 tk 538
  // change to utility page
539
  SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
540
 
134 tk 541
  return 0; // no error
542
}
543
 
544
static s32 SEQ_UI_Button_Copy(s32 depressed)
545
{
240 tk 546
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 547
 
240 tk 548
  seq_ui_button_state.COPY = depressed ? 0 : 1;
549
 
280 tk 550
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
551
    if( depressed ) return -1;
552
    SEQ_UI_MIXER_Copy();
553
    return 1;
554
  } else {
555
    if( !depressed ) {
556
      prev_page = ui_page;
557
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
558
    }
240 tk 559
 
280 tk 560
    s32 status = SEQ_UI_UTIL_CopyButton(depressed);
240 tk 561
 
596 tk 562
    if( depressed ) {
563
      if( prev_page != SEQ_UI_PAGE_UTIL )
564
    SEQ_UI_PageSet(prev_page);
240 tk 565
 
596 tk 566
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "copied");
567
    }
568
 
280 tk 569
    return status;
570
  }
134 tk 571
}
572
 
573
static s32 SEQ_UI_Button_Paste(s32 depressed)
574
{
240 tk 575
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 576
 
240 tk 577
  seq_ui_button_state.PASTE = depressed ? 0 : 1;
578
 
280 tk 579
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
580
    if( depressed ) return -1;
581
    SEQ_UI_MIXER_Paste();
582
    return 1;
583
  } else {
584
    if( !depressed ) {
585
      prev_page = ui_page;
586
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
587
    }
240 tk 588
 
280 tk 589
    s32 status = SEQ_UI_UTIL_PasteButton(depressed);
240 tk 590
 
596 tk 591
    if( depressed ) {
592
      if( prev_page != SEQ_UI_PAGE_UTIL )
593
    SEQ_UI_PageSet(prev_page);
240 tk 594
 
596 tk 595
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "pasted");
596
    }
597
 
280 tk 598
    return status;
599
  }
134 tk 600
}
601
 
602
static s32 SEQ_UI_Button_Clear(s32 depressed)
603
{
240 tk 604
  seq_ui_button_state.CLEAR = depressed ? 0 : 1;
280 tk 605
 
606
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
607
    if( depressed ) return -1;
608
    SEQ_UI_MIXER_Clear();
596 tk 609
 
610
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "cleared");
611
 
280 tk 612
    return 1;
613
  } else {
614
    return SEQ_UI_UTIL_ClearButton(depressed);
615
  }
134 tk 616
}
617
 
618
static s32 SEQ_UI_Button_Menu(s32 depressed)
619
{
513 tk 620
  if( seq_hwcfg_button_beh.menu ) {
621
    // toggle mode
622
    if( depressed ) return -1; // ignore when button depressed
623
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
624
    seq_ui_button_state.MENU_PRESSED ^= 1; // toggle MENU pressed (will also be released once GP button has been pressed)
625
  } else {
626
    // set mode
627
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
628
    seq_ui_button_state.MENU_PRESSED = depressed ? 0 : 1;
629
  }
134 tk 630
 
631
  return 0; // no error
632
}
633
 
634
static s32 SEQ_UI_Button_Select(s32 depressed)
635
{
168 tk 636
  // forward to menu page
591 tk 637
  if( !seq_ui_button_state.MENU_PRESSED ) {
638
    seq_ui_button_state.SELECT_PRESSED = depressed ? 0 : 1;
639
    if( ui_button_callback != NULL )
640
      ui_button_callback(SEQ_UI_BUTTON_Select, depressed);
641
  }
173 tk 642
  ui_cursor_flash_ctr = 0;
134 tk 643
 
644
  return 0; // no error
645
}
646
 
647
static s32 SEQ_UI_Button_Exit(s32 depressed)
648
{
272 tk 649
  if( depressed ) return -1; // ignore when button depressed
650
 
651
  u8 prev_ui_page = ui_page;
652
 
591 tk 653
  seq_ui_button_state.EXIT_PRESSED = depressed ? 0 : 1;
654
 
168 tk 655
  // forward to menu page
306 tk 656
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 657
    ui_button_callback(SEQ_UI_BUTTON_Exit, depressed);
173 tk 658
  ui_cursor_flash_ctr = 0;
134 tk 659
 
167 tk 660
  // release all button states
661
  seq_ui_button_state.ALL = 0;
662
 
272 tk 663
  // enter menu page if we were not there before
664
  if( prev_ui_page != SEQ_UI_PAGE_MENU )
665
    SEQ_UI_PageSet(SEQ_UI_PAGE_MENU);
666
 
134 tk 667
  return 0; // no error
668
}
669
 
670
static s32 SEQ_UI_Button_Edit(s32 depressed)
671
{
591 tk 672
  seq_ui_button_state.EXIT_PRESSED = depressed ? 0 : 1;
673
 
134 tk 674
  if( depressed ) return -1; // ignore when button depressed
675
 
167 tk 676
  // change to edit page
677
  SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
678
 
178 tk 679
  // set/clear encoder fast function if required
680
  SEQ_UI_InitEncSpeed(1); // auto config
681
 
134 tk 682
  return 0; // no error
683
}
684
 
685
static s32 SEQ_UI_Button_Mute(s32 depressed)
686
{
591 tk 687
  seq_ui_button_state.MUTE_PRESSED = depressed ? 0 : 1;
688
 
134 tk 689
  if( depressed ) return -1; // ignore when button depressed
690
 
184 tk 691
  SEQ_UI_PageSet(SEQ_UI_PAGE_MUTE);
692
 
134 tk 693
  return 0; // no error
694
}
695
 
696
static s32 SEQ_UI_Button_Pattern(s32 depressed)
697
{
591 tk 698
  seq_ui_button_state.PATTERN_PRESSED = depressed ? 0 : 1;
699
 
134 tk 700
  if( depressed ) return -1; // ignore when button depressed
701
 
184 tk 702
  SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN);
703
 
134 tk 704
  return 0; // no error
705
}
706
 
707
static s32 SEQ_UI_Button_Song(s32 depressed)
708
{
591 tk 709
  seq_ui_button_state.SONG_PRESSED = depressed ? 0 : 1;
710
 
134 tk 711
  if( depressed ) return -1; // ignore when button depressed
712
 
399 tk 713
  // toggle active mode if already in song page
714
  if( ui_page == SEQ_UI_PAGE_SONG ) {
715
    SEQ_SONG_ActiveSet(SEQ_SONG_ActiveGet() ? 0 : 1);
716
  }
717
 
718
  SEQ_UI_PageSet(SEQ_UI_PAGE_SONG);
719
 
134 tk 720
  return 0; // no error
721
}
722
 
723
static s32 SEQ_UI_Button_Solo(s32 depressed)
724
{
513 tk 725
  if( seq_hwcfg_button_beh.solo ) {
726
    // toggle mode
727
    if( depressed ) return -1; // ignore when button depressed
728
    seq_ui_button_state.SOLO ^= 1;
729
  } else {
730
    // set mode
731
    seq_ui_button_state.SOLO = depressed ? 0 : 1;
732
  }
134 tk 733
 
734
  return 0; // no error
735
}
736
 
737
static s32 SEQ_UI_Button_Fast(s32 depressed)
738
{
513 tk 739
  if( seq_hwcfg_button_beh.fast ) {
740
    // toggle mode
741
    if( depressed ) return -1; // ignore when button depressed
742
    seq_ui_button_state.FAST_ENCODERS ^= 1;
743
  } else {
744
    // set mode
745
    seq_ui_button_state.FAST_ENCODERS = depressed ? 0 : 1;
746
  }
134 tk 747
 
178 tk 748
  SEQ_UI_InitEncSpeed(0); // no auto config
749
 
134 tk 750
  return 0; // no error
751
}
752
 
753
static s32 SEQ_UI_Button_All(s32 depressed)
754
{
178 tk 755
  seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE = depressed ? 0 : 1;
134 tk 756
 
513 tk 757
  if( seq_hwcfg_button_beh.all ) {
758
    // toggle mode
759
    if( depressed ) return -1;
760
    seq_ui_button_state.CHANGE_ALL_STEPS ^= 1;
761
  } else {
762
    // set mode
763
    seq_ui_button_state.CHANGE_ALL_STEPS = depressed ? 0 : 1;
764
  }
178 tk 765
 
134 tk 766
  return 0; // no error
767
}
768
 
769
static s32 SEQ_UI_Button_StepView(s32 depressed)
770
{
513 tk 771
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
326 tk 772
 
513 tk 773
  if( seq_hwcfg_button_beh.step_view ) {
774
    if( depressed ) return -1; // ignore when button depressed
775
    seq_ui_button_state.STEP_VIEW ^= 1; // toggle STEP_VIEW pressed (will also be released once GP button has been pressed)
776
  } else {
777
    // set mode
778
    seq_ui_button_state.STEP_VIEW = depressed ? 0 : 1;
779
  }
134 tk 780
 
513 tk 781
  if( seq_ui_button_state.STEP_VIEW ) {
782
    prev_page = ui_page;
303 tk 783
    SEQ_UI_PageSet(SEQ_UI_PAGE_STEPSEL);
784
  } else {
524 tk 785
    if( ui_page == SEQ_UI_PAGE_STEPSEL )
786
      SEQ_UI_PageSet(prev_page);
303 tk 787
  }
134 tk 788
 
789
  return 0; // no error
790
}
791
 
513 tk 792
static s32 SEQ_UI_Button_TrackSel(s32 depressed)
134 tk 793
{
513 tk 794
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 795
 
513 tk 796
  if( seq_hwcfg_button_beh.track_sel ) {
797
    if( depressed ) return -1; // ignore when button depressed
798
    seq_ui_button_state.TRACK_SEL ^= 1; // toggle TRACKSEL status (will also be released once GP button has been pressed)
799
  } else {
800
    seq_ui_button_state.TRACK_SEL = depressed ? 0 : 1;
801
  }
802
 
803
  if( seq_ui_button_state.TRACK_SEL ) {
804
    prev_page = ui_page;
805
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRACKSEL);
806
  } else {
524 tk 807
    if( ui_page == SEQ_UI_PAGE_TRACKSEL )
808
      SEQ_UI_PageSet(prev_page);
513 tk 809
  }
810
 
134 tk 811
  return 0; // no error
812
}
813
 
484 tk 814
static s32 SEQ_UI_Button_Track(s32 depressed, u32 track_button)
134 tk 815
{
484 tk 816
  static u8 button_state = 0x0f; // all 4 buttons depressed
134 tk 817
 
484 tk 818
  if( track_button >= 4 ) return -2; // max. 4 track buttons
134 tk 819
 
484 tk 820
  if( depressed ) {
821
    button_state |= (1 << track_button);
822
    return 0; // no error
823
  }
134 tk 824
 
484 tk 825
  button_state &= ~(1 << track_button);
826
 
827
  if( button_state == (~(1 << track_button) & 0xf) ) {
828
    // if only one select button pressed: radio-button function (1 of 4)
829
    ui_selected_tracks = 1 << (track_button + 4*ui_selected_group);
830
  } else {
831
    // if more than one select button pressed: toggle function (4 of 4)
832
    ui_selected_tracks ^= 1 << (track_button + 4*ui_selected_group);
833
  }
834
 
178 tk 835
  // set/clear encoder fast function if required
836
  SEQ_UI_InitEncSpeed(1); // auto config
837
 
134 tk 838
  return 0; // no error
839
}
840
 
841
static s32 SEQ_UI_Button_Group(s32 depressed, u32 group)
842
{
843
  if( depressed ) return -1; // ignore when button depressed
844
 
845
  if( group >= 4 ) return -2; // max. 4 group buttons
846
 
484 tk 847
  // if group has changed:
848
  if( group != ui_selected_group ) {
849
    // get current track selection
850
    u16 old_tracks = ui_selected_tracks >> (4*ui_selected_group);
134 tk 851
 
484 tk 852
    // select new group
853
    ui_selected_group = group;
854
 
855
    // take over old track selection
856
    ui_selected_tracks = old_tracks << (4*ui_selected_group);
857
  }
858
 
178 tk 859
  // set/clear encoder fast function if required
860
  SEQ_UI_InitEncSpeed(1); // auto config
861
 
134 tk 862
  return 0; // no error
863
}
864
 
513 tk 865
static s32 SEQ_UI_Button_ParLayerSel(s32 depressed)
866
{
867
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
868
 
869
  if( seq_hwcfg_button_beh.par_layer ) {
870
    if( depressed ) return -1; // ignore when button depressed
871
    seq_ui_button_state.PAR_LAYER_SEL ^= 1; // toggle PARSEL status (will also be released once GP button has been pressed)
872
  } else {
873
    seq_ui_button_state.PAR_LAYER_SEL = depressed ? 0 : 1;
874
  }
875
 
876
  if( seq_ui_button_state.PAR_LAYER_SEL ) {
877
    prev_page = ui_page;
878
    SEQ_UI_PageSet(SEQ_UI_PAGE_PARSEL);
879
  } else {
524 tk 880
    if( ui_page == SEQ_UI_PAGE_PARSEL )
881
      SEQ_UI_PageSet(prev_page);
513 tk 882
  }
883
 
884
  // set/clear encoder fast function if required
885
  SEQ_UI_InitEncSpeed(1); // auto config
886
 
887
  return 0; // no error
888
}
889
 
134 tk 890
static s32 SEQ_UI_Button_ParLayer(s32 depressed, u32 par_layer)
891
{
892
  if( par_layer >= 3 ) return -2; // max. 3 parlayer buttons
893
 
333 tk 894
  u8 visible_track = SEQ_UI_VisibleTrackGet();
895
  u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
134 tk 896
 
333 tk 897
  if( num_p_layers <= 3 ) {
898
    // 3 layers: direct selection with LayerA/B/C button
899
    if( depressed ) return -1; // ignore when button depressed
596 tk 900
    if( par_layer >= num_p_layers ) {
901
      char str1[21];
902
      sprintf(str1, "Parameter Layer %c", 'A'+par_layer);
903
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
904
    } else {
905
      seq_ui_button_state.PAR_LAYER_SEL = 0;
906
      ui_selected_par_layer = par_layer;
907
    }
333 tk 908
  } else if( num_p_layers <= 4 ) {
909
    // 4 layers: LayerC Button toggles between C and D
910
    if( depressed ) return -1; // ignore when button depressed
911
    seq_ui_button_state.PAR_LAYER_SEL = 0;
336 tk 912
    if( par_layer == 2 )
913
      ui_selected_par_layer = (ui_selected_par_layer == 2) ? 3 : 2;
333 tk 914
    else
915
      ui_selected_par_layer = par_layer;
916
  } else {
917
    // >4 layers: LayerA/B button selects directly, Layer C button enters layer selection page
918
    if( par_layer <= 1 ) {
919
      if( depressed ) return -1; // ignore when button depressed
920
      seq_ui_button_state.PAR_LAYER_SEL = 0;
921
      ui_selected_par_layer = par_layer;
922
    } else {
513 tk 923
      return SEQ_UI_Button_ParLayerSel(depressed);
333 tk 924
    }
925
  }
926
 
178 tk 927
  // set/clear encoder fast function if required
928
  SEQ_UI_InitEncSpeed(1); // auto config
929
 
134 tk 930
  return 0; // no error
931
}
932
 
513 tk 933
static s32 SEQ_UI_Button_TrgLayerSel(s32 depressed)
934
{
935
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
936
 
937
  if( seq_hwcfg_button_beh.trg_layer ) {
938
    if( depressed ) return -1; // ignore when button depressed
939
    seq_ui_button_state.TRG_LAYER_SEL ^= 1; // toggle TRGSEL status (will also be released once GP button has been pressed)
940
  } else {
941
    seq_ui_button_state.TRG_LAYER_SEL = depressed ? 0 : 1;
942
  }
943
 
944
  if( seq_ui_button_state.TRG_LAYER_SEL ) {
945
    prev_page = ui_page;
946
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRGSEL);
947
  } else {
524 tk 948
    if( ui_page == SEQ_UI_PAGE_TRGSEL )
949
      SEQ_UI_PageSet(prev_page);
513 tk 950
  }
951
 
952
  return 0; // no error
953
}
954
 
134 tk 955
static s32 SEQ_UI_Button_TrgLayer(s32 depressed, u32 trg_layer)
956
{
957
  if( trg_layer >= 3 ) return -2; // max. 3 trglayer buttons
958
 
326 tk 959
  u8 visible_track = SEQ_UI_VisibleTrackGet();
960
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
961
  u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
134 tk 962
 
328 tk 963
  if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 3 ) {
326 tk 964
    // 3 layers: direct selection with LayerA/B/C button
965
    if( depressed ) return -1; // ignore when button depressed
596 tk 966
    if( trg_layer >= num_t_layers ) {
967
      char str1[21];
968
      sprintf(str1, "Trigger Layer %c", 'A'+trg_layer);
969
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
970
    } else {
971
      seq_ui_button_state.TRG_LAYER_SEL = 0;
972
      ui_selected_trg_layer = trg_layer;
973
    }
328 tk 974
  } else if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 4 ) {
326 tk 975
    // 4 layers: LayerC Button toggles between C and D
976
    if( depressed ) return -1; // ignore when button depressed
977
    seq_ui_button_state.TRG_LAYER_SEL = 0;
336 tk 978
    if( trg_layer == 2 )
979
      ui_selected_trg_layer = (ui_selected_trg_layer == 2) ? 3 : 2;
326 tk 980
    else
981
      ui_selected_trg_layer = trg_layer;
982
  } else {
333 tk 983
    // >4 layers or drum mode: LayerA/B button selects directly, Layer C button enters trigger selection page
326 tk 984
    // also used for drum tracks
985
    if( trg_layer <= 1 ) {
986
      if( depressed ) return -1; // ignore when button depressed
328 tk 987
      seq_ui_button_state.TRG_LAYER_SEL = 0;
988
      ui_selected_trg_layer = trg_layer;
326 tk 989
    } else {
513 tk 990
      return SEQ_UI_Button_TrgLayerSel(depressed);
326 tk 991
    }
992
  }
993
 
134 tk 994
  return 0; // no error
995
}
996
 
997
 
544 tk 998
static s32 SEQ_UI_Button_Morph(s32 depressed)
999
{
1000
  if( depressed ) return -1; // ignore when button depressed
134 tk 1001
 
544 tk 1002
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMORPH);
1003
 
1004
  return 0; // no error
1005
}
1006
 
1007
static s32 SEQ_UI_Button_Mixer(s32 depressed)
1008
{
1009
  if( depressed ) return -1; // ignore when button depressed
1010
 
1011
  SEQ_UI_PageSet(SEQ_UI_PAGE_MIXER);
1012
 
1013
  return 0; // no error
1014
}
1015
 
1016
static s32 SEQ_UI_Button_Transpose(s32 depressed)
1017
{
1018
  if( depressed ) return -1; // ignore when button depressed
1019
 
1020
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKTRAN);
1021
 
1022
  return 0; // no error
1023
}
1024
 
1025
 
1026
 
1027
 
134 tk 1028
/////////////////////////////////////////////////////////////////////////////
1029
// Button handler
1030
/////////////////////////////////////////////////////////////////////////////
1031
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
1032
{
492 tk 1033
  int i;
1034
 
496 tk 1035
  // ignore so long hardware config hasn't been read
1036
  if( !SEQ_FILE_HW_ConfigLocked() )
1037
    return -1;
1038
 
328 tk 1039
  // ensure that selections are matching with track constraints
1040
  SEQ_UI_CheckSelections();
1041
 
492 tk 1042
  // request display update
1043
  seq_ui_display_update_req = 1;
134 tk 1044
 
596 tk 1045
  // stop current message if (new) button has been pressed
1046
  if( pin_value == 0 )
1047
    SEQ_UI_MsgStop();
134 tk 1048
 
596 tk 1049
 
492 tk 1050
  // MEMO: we could also use a jump table with references to the functions
1051
  // here, but this "spagetthi code" simplifies the configuration and
1052
  // the resulting ASM doesn't look that bad!
168 tk 1053
 
492 tk 1054
  for(i=0; i<SEQ_HWCFG_NUM_GP; ++i)
1055
    if( pin == seq_hwcfg_button.gp[i] )
1056
      return SEQ_UI_Button_GP(pin_value, i);
134 tk 1057
 
492 tk 1058
  for(i=0; i<SEQ_HWCFG_NUM_TRACK; ++i)
1059
    if( pin == seq_hwcfg_button.track[i] )
1060
      return SEQ_UI_Button_Track(pin_value, i);
513 tk 1061
  if( pin == seq_hwcfg_button.track_sel )
1062
    return SEQ_UI_Button_TrackSel(pin_value);
134 tk 1063
 
492 tk 1064
  for(i=0; i<SEQ_HWCFG_NUM_GROUP; ++i)
1065
    if( pin == seq_hwcfg_button.group[i] )
1066
      return SEQ_UI_Button_Group(pin_value, i);
134 tk 1067
 
492 tk 1068
  for(i=0; i<SEQ_HWCFG_NUM_PAR_LAYER; ++i)
1069
    if( pin == seq_hwcfg_button.par_layer[i] )
1070
      return SEQ_UI_Button_ParLayer(pin_value, i);
513 tk 1071
  if( pin == seq_hwcfg_button.par_layer_sel )
1072
    return SEQ_UI_Button_ParLayerSel(pin_value);
134 tk 1073
 
492 tk 1074
  for(i=0; i<SEQ_HWCFG_NUM_TRG_LAYER; ++i)
1075
    if( pin == seq_hwcfg_button.trg_layer[i] )
1076
      return SEQ_UI_Button_TrgLayer(pin_value, i);
513 tk 1077
  if( pin == seq_hwcfg_button.trg_layer_sel )
1078
    return SEQ_UI_Button_TrgLayerSel(pin_value);
134 tk 1079
 
492 tk 1080
  if( pin == seq_hwcfg_button.left )
1081
    return SEQ_UI_Button_Left(pin_value);
1082
  if( pin == seq_hwcfg_button.right )
1083
    return SEQ_UI_Button_Right(pin_value);
1084
  if( pin == seq_hwcfg_button.down )
1085
    return SEQ_UI_Button_Down(pin_value);
1086
  if( pin == seq_hwcfg_button.up )
1087
    return SEQ_UI_Button_Up(pin_value);
134 tk 1088
 
492 tk 1089
  if( pin == seq_hwcfg_button.scrub )
1090
    return SEQ_UI_Button_Scrub(pin_value);
1091
  if( pin == seq_hwcfg_button.metronome )
1092
    return SEQ_UI_Button_Metronome(pin_value);
134 tk 1093
 
492 tk 1094
  if( pin == seq_hwcfg_button.stop )
1095
    return SEQ_UI_Button_Stop(pin_value);
1096
  if( pin == seq_hwcfg_button.pause )
1097
    return SEQ_UI_Button_Pause(pin_value);
1098
  if( pin == seq_hwcfg_button.play )
1099
    return SEQ_UI_Button_Play(pin_value);
1100
  if( pin == seq_hwcfg_button.rew )
1101
    return SEQ_UI_Button_Rew(pin_value);
1102
  if( pin == seq_hwcfg_button.fwd )
1103
    return SEQ_UI_Button_Fwd(pin_value);
596 tk 1104
  if( pin == seq_hwcfg_button.loop )
1105
    return SEQ_UI_Button_Loop(pin_value);
134 tk 1106
 
492 tk 1107
  if( pin == seq_hwcfg_button.utility )
1108
    return SEQ_UI_Button_Utility(pin_value);
1109
  if( pin == seq_hwcfg_button.copy )
1110
    return SEQ_UI_Button_Copy(pin_value);
1111
  if( pin == seq_hwcfg_button.paste )
1112
    return SEQ_UI_Button_Paste(pin_value);
1113
  if( pin == seq_hwcfg_button.clear )
1114
    return SEQ_UI_Button_Clear(pin_value);
134 tk 1115
 
492 tk 1116
  if( pin == seq_hwcfg_button.menu )
1117
    return SEQ_UI_Button_Menu(pin_value);
1118
  if( pin == seq_hwcfg_button.select )
1119
    return SEQ_UI_Button_Select(pin_value);
1120
  if( pin == seq_hwcfg_button.exit )
1121
    return SEQ_UI_Button_Exit(pin_value);
134 tk 1122
 
513 tk 1123
  if( pin == seq_hwcfg_button.tap_tempo )
1124
    return SEQ_UI_Button_TapTempo(pin_value);
1125
  if( pin == seq_hwcfg_button.tempo_preset )
1126
    return SEQ_UI_Button_TempoPreset(pin_value);
524 tk 1127
  if( pin == seq_hwcfg_button.ext_restart )
1128
    return SEQ_UI_Button_ExtRestart(pin_value);
134 tk 1129
 
492 tk 1130
  if( pin == seq_hwcfg_button.edit )
1131
    return SEQ_UI_Button_Edit(pin_value);
1132
  if( pin == seq_hwcfg_button.mute )
1133
    return SEQ_UI_Button_Mute(pin_value);
1134
  if( pin == seq_hwcfg_button.pattern )
1135
    return SEQ_UI_Button_Pattern(pin_value);
1136
  if( pin == seq_hwcfg_button.song )
1137
    return SEQ_UI_Button_Song(pin_value);
134 tk 1138
 
492 tk 1139
  if( pin == seq_hwcfg_button.solo )
1140
    return SEQ_UI_Button_Solo(pin_value);
1141
  if( pin == seq_hwcfg_button.fast )
1142
    return SEQ_UI_Button_Fast(pin_value);
1143
  if( pin == seq_hwcfg_button.all )
1144
    return SEQ_UI_Button_All(pin_value);
134 tk 1145
 
492 tk 1146
  if( pin == seq_hwcfg_button.step_view )
1147
    return SEQ_UI_Button_StepView(pin_value);
1148
  if( pin == seq_hwcfg_button.tap_tempo )
1149
    return SEQ_UI_Button_TapTempo(pin_value);
134 tk 1150
 
544 tk 1151
  if( pin == seq_hwcfg_button.morph )
1152
    return SEQ_UI_Button_Morph(pin_value);
1153
  if( pin == seq_hwcfg_button.mixer )
1154
    return SEQ_UI_Button_Mixer(pin_value);
1155
  if( pin == seq_hwcfg_button.transpose )
1156
    return SEQ_UI_Button_Transpose(pin_value);
1157
 
492 tk 1158
  return -1; // button not mapped
134 tk 1159
}
1160
 
1161
 
1162
/////////////////////////////////////////////////////////////////////////////
524 tk 1163
// BLM Button handler
1164
/////////////////////////////////////////////////////////////////////////////
1165
s32 SEQ_UI_BLM_Button_Handler(u32 row, u32 pin, u32 pin_value)
1166
{
1167
  // ignore so long hardware config hasn't been read
1168
  if( !SEQ_FILE_HW_ConfigLocked() )
1169
    return -1;
1170
 
1171
  if( row >= SEQ_CORE_NUM_TRACKS_PER_GROUP )
1172
    return -1; // more than 4 tracks not supported (yet) - could be done in this function w/o much effort
1173
 
1174
  if( pin >= 16 )
1175
    return -1; // more than 16 step buttons not supported (yet) - could be done by selecting the step view
1176
 
1177
  // select track depending on row
1178
  ui_selected_tracks = 1 << (row + 4*ui_selected_group);
1179
 
1180
  // ensure that selections are matching with track constraints
1181
  SEQ_UI_CheckSelections();
1182
 
1183
  // request display update
1184
  seq_ui_display_update_req = 1;
1185
 
1186
  // emulate general purpose button
1187
  return SEQ_UI_Button_GP(pin_value, pin);
1188
}
1189
 
1190
 
1191
/////////////////////////////////////////////////////////////////////////////
134 tk 1192
// Encoder handler
1193
/////////////////////////////////////////////////////////////////////////////
1194
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
1195
{
496 tk 1196
  // ignore so long hardware config hasn't been read
1197
  if( !SEQ_FILE_HW_ConfigLocked() )
1198
    return -1;
1199
 
134 tk 1200
  if( encoder > 16 )
1201
    return -1; // encoder doesn't exist
1202
 
328 tk 1203
  // ensure that selections are matching with track constraints
1204
  SEQ_UI_CheckSelections();
1205
 
596 tk 1206
  // stop current message
1207
  SEQ_UI_MsgStop();
1208
 
134 tk 1209
  // limit incrementer
1210
  if( incrementer > 3 )
1211
    incrementer = 3;
1212
  else if( incrementer < -3 )
1213
    incrementer = -3;
1214
 
306 tk 1215
  if( !seq_ui_button_state.MENU_PRESSED && ui_encoder_callback != NULL ) {
173 tk 1216
    ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
1217
    ui_cursor_flash_ctr = 0; // ensure that value is visible when it has been changed
134 tk 1218
  }
1219
 
1220
  // request display update
159 tk 1221
  seq_ui_display_update_req = 1;
134 tk 1222
 
1223
  return 0; // no error
1224
}
1225
 
1226
 
353 tk 1227
 
134 tk 1228
/////////////////////////////////////////////////////////////////////////////
1229
// Update LCD messages
1230
// Usually called from background task
1231
/////////////////////////////////////////////////////////////////////////////
1232
s32 SEQ_UI_LCD_Handler(void)
1233
{
159 tk 1234
  if( seq_ui_display_init_req ) {
1235
    seq_ui_display_init_req = 0; // clear request
134 tk 1236
 
278 tk 1237
    // clear force update of LCD
1238
    SEQ_LCD_Clear();
1239
    SEQ_LCD_Update(1);
134 tk 1240
 
168 tk 1241
    // select first menu item
1242
    ui_selected_item = 0;
1243
 
167 tk 1244
    // call init function of current page
272 tk 1245
    if( ui_menu_pages[ui_page].init_callback != NULL )
1246
      ui_menu_pages[ui_page].init_callback(0); // mode
134 tk 1247
 
1248
    // request display update
159 tk 1249
    seq_ui_display_update_req = 1;
134 tk 1250
  }
1251
 
496 tk 1252
  // print boot screen so long hardware config hasn't been read
1253
  if( !SEQ_FILE_HW_ConfigLocked() ) {
1254
    SEQ_LCD_Clear();
306 tk 1255
    SEQ_LCD_CursorSet(0, 0);
496 tk 1256
    //                   <-------------------------------------->
1257
    //                   0123456789012345678901234567890123456789
1258
    SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE1);
1259
    SEQ_LCD_CursorSet(40, 0);
1260
    SEQ_LCD_PrintString("Searching for SD Card...");
1261
    SEQ_LCD_CursorSet(0, 1);
1262
    SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE2);
1263
    // TODO: print nice animation
1264
  } else if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
1265
    SEQ_LCD_CursorSet(0, 0);
1266
    //                   <-------------------------------------->
1267
    //                   0123456789012345678901234567890123456789
306 tk 1268
    SEQ_LCD_PrintString("Menu Shortcuts:");
1269
    SEQ_LCD_PrintSpaces(25 + 40);
1270
    SEQ_LCD_CursorSet(0, 1);
1271
    SEQ_LCD_PrintString(UI_SHORTCUT_STR); // defined in seq_ui_pages.inc
1272
  } else {
1273
    // perform high priority LCD update request
1274
    if( ui_lcd_callback != NULL )
1275
      ui_lcd_callback(1); // high_prio
167 tk 1276
 
306 tk 1277
    // perform low priority LCD update request if requested
1278
    if( seq_ui_display_update_req ) {
1279
      seq_ui_display_update_req = 0; // clear request
328 tk 1280
 
1281
      // ensure that selections are matching with track constraints
1282
      SEQ_UI_CheckSelections();
1283
 
306 tk 1284
      if( ui_lcd_callback != NULL )
1285
    ui_lcd_callback(0); // no high_prio
1286
    }
134 tk 1287
  }
1288
 
353 tk 1289
  // transfer all changed characters to LCD
1290
  SEQ_UI_LCD_Update();
1291
 
1292
  return 0; // no error
1293
}
1294
 
1295
 
1296
/////////////////////////////////////////////////////////////////////////////
1297
// Called from SEQ_UI_LCD_Handler(), but optionally also from other tasks
1298
// to update the LCD screen immediately
1299
/////////////////////////////////////////////////////////////////////////////
1300
s32 SEQ_UI_LCD_Update(void)
1301
{
596 tk 1302
  // if UI message active: copy over the text
1303
  if( ui_msg_ctr ) {
1304
    const char *animation_l_ptr;
1305
    const char *animation_r_ptr;
1306
    u8 msg_x = 0;
1307
    u8 right_aligned = 0;
299 tk 1308
 
596 tk 1309
    switch( ui_msg_type ) {
1310
      case SEQ_UI_MSG_SDCARD: {
1311
    //                             00112233
1312
    const char animation_l[2*4] = "   >>>> ";
1313
    //                             00112233
1314
    const char animation_r[2*4] = "  < << <";
1315
    animation_l_ptr = animation_l;
1316
    animation_r_ptr = animation_r;
1317
    msg_x = 0; // MEMO: print such important information at first LCD for the case the user hasn't connected the second LCD yet
1318
    right_aligned = 0;
1319
      } break;
1320
 
1321
      default: {
1322
    //                             00112233
1323
    const char animation_l[2*4] = "   **** ";
1324
    //                             00112233
1325
    const char animation_r[2*4] = "  * ** *";
1326
    animation_l_ptr = animation_l;
1327
    animation_r_ptr = animation_r;
1328
    msg_x = 39;
1329
    right_aligned = 1;
1330
      } break;
1331
 
1332
    }
1333
    int anum = (ui_msg_ctr % 1000) / 250;
1334
 
1335
    int len[2];
1336
    len[0] = strlen((char *)ui_msg[0]);
1337
    len[1] = strlen((char *)ui_msg[1]);
1338
    int len_max = len[0];
1339
    if( len[1] > len_max )
1340
      len_max = len[1];
1341
 
1342
    if( right_aligned )
1343
      msg_x -= (9 + len_max);
1344
 
299 tk 1345
    int line;
1346
    for(line=0; line<2; ++line) {
596 tk 1347
      SEQ_LCD_CursorSet(msg_x, line);
1348
 
1349
      // ensure that both lines are padded with same number of spaces
1350
      int end_pos = len[line];
1351
      while( end_pos < len_max )
1352
    ui_msg[line][end_pos++] = ' ';
1353
      ui_msg[line][end_pos] = 0;
1354
 
1355
      SEQ_LCD_PrintFormattedString(" %c%c| %s |%c%c ",
1356
                   *(animation_l_ptr + 2*anum + 0), *(animation_l_ptr + 2*anum + 1),
1357
                   (char *)ui_msg[line],
1358
                   *(animation_r_ptr + 2*anum + 0), *(animation_r_ptr + 2*anum + 1));
299 tk 1359
    }
1360
  }
1361
 
596 tk 1362
 
278 tk 1363
  // transfer all changed characters to LCD
353 tk 1364
  // SEQ_LCD_Update provides a MUTEX handling to allow updates from different tasks
1365
  return SEQ_LCD_Update(0);
134 tk 1366
}
1367
 
1368
 
1369
/////////////////////////////////////////////////////////////////////////////
1370
// Update all LEDs
1371
// Usually called from background task
1372
/////////////////////////////////////////////////////////////////////////////
1373
s32 SEQ_UI_LED_Handler(void)
1374
{
524 tk 1375
  int i;
1376
 
496 tk 1377
  // ignore so long hardware config hasn't been read
1378
  if( !SEQ_FILE_HW_ConfigLocked() )
1379
    return -1;
1380
 
326 tk 1381
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1382
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1383
 
134 tk 1384
  // track LEDs
484 tk 1385
  u8 selected_tracks = ui_selected_tracks >> (4*ui_selected_group);
492 tk 1386
  SEQ_LED_PinSet(seq_hwcfg_led.track[0], (selected_tracks & (1 << 0)));
1387
  SEQ_LED_PinSet(seq_hwcfg_led.track[1], (selected_tracks & (1 << 1)));
1388
  SEQ_LED_PinSet(seq_hwcfg_led.track[2], (selected_tracks & (1 << 2)));
1389
  SEQ_LED_PinSet(seq_hwcfg_led.track[3], (selected_tracks & (1 << 3)));
513 tk 1390
  SEQ_LED_PinSet(seq_hwcfg_led.track_sel, seq_ui_button_state.TRACK_SEL);
134 tk 1391
 
1392
  // parameter layer LEDs
492 tk 1393
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], (ui_selected_par_layer == 0));
1394
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], (ui_selected_par_layer == 1));
1395
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], (ui_selected_par_layer >= 2) || seq_ui_button_state.PAR_LAYER_SEL);
513 tk 1396
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer_sel, seq_ui_button_state.PAR_LAYER_SEL);
134 tk 1397
 
1398
  // group LEDs
492 tk 1399
  SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_group == 0));
1400
  SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_group == 1));
1401
  SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_group == 2));
1402
  SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_group == 3));
134 tk 1403
 
1404
  // trigger layer LEDs
492 tk 1405
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[0], (ui_selected_trg_layer == 0));
1406
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[1], (ui_selected_trg_layer == 1));
1407
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[2], (ui_selected_trg_layer >= 2) || seq_ui_button_state.TRG_LAYER_SEL);
513 tk 1408
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer_sel, seq_ui_button_state.TRG_LAYER_SEL);
134 tk 1409
 
1410
  // remaining LEDs
492 tk 1411
  SEQ_LED_PinSet(seq_hwcfg_led.edit, ui_page == SEQ_UI_PAGE_EDIT);
1412
  SEQ_LED_PinSet(seq_hwcfg_led.mute, ui_page == SEQ_UI_PAGE_MUTE);
1413
  SEQ_LED_PinSet(seq_hwcfg_led.pattern, ui_page == SEQ_UI_PAGE_PATTERN);
399 tk 1414
  if( SEQ_SONG_ActiveGet() )
492 tk 1415
    SEQ_LED_PinSet(seq_hwcfg_led.song, 1);
399 tk 1416
  else
492 tk 1417
    SEQ_LED_PinSet(seq_hwcfg_led.song, ui_cursor_flash ? 0 : (ui_page == SEQ_UI_PAGE_SONG));
134 tk 1418
 
492 tk 1419
  SEQ_LED_PinSet(seq_hwcfg_led.solo, seq_ui_button_state.SOLO);
1420
  SEQ_LED_PinSet(seq_hwcfg_led.fast, seq_ui_button_state.FAST_ENCODERS);
1421
  SEQ_LED_PinSet(seq_hwcfg_led.all, seq_ui_button_state.CHANGE_ALL_STEPS);
134 tk 1422
 
492 tk 1423
  SEQ_LED_PinSet(seq_hwcfg_led.play, SEQ_BPM_IsRunning());
1424
  SEQ_LED_PinSet(seq_hwcfg_led.stop, !SEQ_BPM_IsRunning() && !ui_seq_pause);
1425
  SEQ_LED_PinSet(seq_hwcfg_led.pause, ui_seq_pause);
240 tk 1426
 
492 tk 1427
  SEQ_LED_PinSet(seq_hwcfg_led.rew, seq_ui_button_state.REW);
1428
  SEQ_LED_PinSet(seq_hwcfg_led.fwd, seq_ui_button_state.FWD);
596 tk 1429
 
1430
  SEQ_LED_PinSet(seq_hwcfg_led.loop, seq_core_state.LOOP);
134 tk 1431
 
513 tk 1432
  SEQ_LED_PinSet(seq_hwcfg_led.step_view, seq_ui_button_state.STEP_VIEW);
134 tk 1433
 
591 tk 1434
  SEQ_LED_PinSet(seq_hwcfg_led.exit, seq_ui_button_state.EXIT_PRESSED);
1435
  SEQ_LED_PinSet(seq_hwcfg_led.select, seq_ui_button_state.SELECT_PRESSED);
492 tk 1436
  SEQ_LED_PinSet(seq_hwcfg_led.menu, seq_ui_button_state.MENU_PRESSED);
134 tk 1437
 
596 tk 1438
  // handle double functions
1439
  if( seq_ui_button_state.MENU_PRESSED ) {
1440
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_core_state.LOOP);
1441
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.EXT_RESTART_REQ);
1442
  } else {
1443
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_ui_button_state.SCRUB);
1444
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.METRONOME);
1445
  }
1446
 
492 tk 1447
  SEQ_LED_PinSet(seq_hwcfg_led.utility, ui_page == SEQ_UI_PAGE_UTIL);
1448
  SEQ_LED_PinSet(seq_hwcfg_led.copy, seq_ui_button_state.COPY);
1449
  SEQ_LED_PinSet(seq_hwcfg_led.paste, seq_ui_button_state.PASTE);
1450
  SEQ_LED_PinSet(seq_hwcfg_led.clear, seq_ui_button_state.CLEAR);
240 tk 1451
 
513 tk 1452
  SEQ_LED_PinSet(seq_hwcfg_led.tap_tempo, seq_ui_button_state.TAP_TEMPO);
1453
  SEQ_LED_PinSet(seq_hwcfg_led.tempo_preset, seq_ui_button_state.TEMPO_PRESET);
524 tk 1454
  SEQ_LED_PinSet(seq_hwcfg_led.ext_restart, seq_core_state.EXT_RESTART_REQ);
240 tk 1455
 
492 tk 1456
  SEQ_LED_PinSet(seq_hwcfg_led.down, seq_ui_button_state.DOWN);
1457
  SEQ_LED_PinSet(seq_hwcfg_led.up, seq_ui_button_state.UP);
240 tk 1458
 
167 tk 1459
 
306 tk 1460
  // in MENU page: overrule GP LEDs so long MENU button is pressed/active
1461
  if( seq_ui_button_state.MENU_PRESSED ) {
1462
    if( ui_cursor_flash ) // if flashing flag active: no LED flag set
1463
      ui_gp_leds = 0x0000;
1464
    else {
1465
      int i;
1466
      u16 new_ui_gp_leds = 0x0000;
1467
      for(i=0; i<16; ++i)
1468
    if( ui_page == ui_shortcut_menu_pages[i] )
1469
      new_ui_gp_leds |= (1 << i);
1470
      ui_gp_leds = new_ui_gp_leds;
1471
    }
1472
  } else {
1473
    // note: the background function is permanently interrupted - therefore we write the GP pattern
1474
    // into a temporary variable, and take it over once completed
1475
    u16 new_ui_gp_leds = 0x0000;
1476
    // request GP LED values from current menu page
1477
    // will be transfered to DOUT registers in SEQ_UI_LED_Handler_Periodic
1478
    new_ui_gp_leds = 0x0000;
206 tk 1479
 
306 tk 1480
    if( ui_led_callback != NULL )
1481
      ui_led_callback(&new_ui_gp_leds);
167 tk 1482
 
306 tk 1483
    ui_gp_leds = new_ui_gp_leds;
1484
  }
1485
 
524 tk 1486
 
1487
  // BLM LEDs
1488
  u8 visible_track0 = 4*ui_selected_group;
1489
  u8 visible_sr0  = 2*ui_selected_step_view;
1490
 
1491
  for(i=0; i<NUM_BLM_LED_SRS; ++i)
1492
    ui_blm_leds[i] = SEQ_TRG_Get8(visible_track0+(i>>1), visible_sr0+(i&1), ui_selected_trg_layer, ui_selected_instrument);
1493
 
134 tk 1494
  return 0; // no error
1495
}
1496
 
1497
 
1498
/////////////////////////////////////////////////////////////////////////////
1499
// updates high-prio LED functions (GP LEDs and Beat LED)
168 tk 1500
// called each mS
134 tk 1501
/////////////////////////////////////////////////////////////////////////////
1502
s32 SEQ_UI_LED_Handler_Periodic()
1503
{
496 tk 1504
  // ignore so long hardware config hasn't been read
1505
  if( !SEQ_FILE_HW_ConfigLocked() )
1506
    return -1;
1507
 
134 tk 1508
  // GP LEDs are only updated when ui_gp_leds or pos_marker_mask has changed
1509
  static u16 prev_ui_gp_leds = 0x0000;
1510
  static u16 prev_pos_marker_mask = 0x0000;
1511
 
1512
  // beat LED: tmp. for demo w/o real sequencer
193 tk 1513
  u8 sequencer_running = SEQ_BPM_IsRunning();
492 tk 1514
  SEQ_LED_PinSet(seq_hwcfg_led.beat, sequencer_running && ((seq_core_state.ref_step & 3) == 0));
134 tk 1515
 
1516
  // for song position marker (supports 16 LEDs, check for selected step view)
1517
  u16 pos_marker_mask = 0x0000;
325 tk 1518
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1519
  u8 played_step = seq_core_trk[visible_track].step;
513 tk 1520
  if( seq_ui_button_state.STEP_VIEW ) {
1521
    // if STEP_VIEW button pressed: pos marker correlated to zoom ratio
325 tk 1522
    if( sequencer_running )
1523
      pos_marker_mask = 1 << (played_step / (SEQ_TRG_NumStepsGet(visible_track)/16));
1524
  } else {
1525
    if( sequencer_running && (played_step >> 4) == ui_selected_step_view )
1526
      pos_marker_mask = 1 << (played_step & 0xf);
1527
  }
134 tk 1528
 
1529
  // exit of pattern hasn't changed
173 tk 1530
  if( prev_ui_gp_leds == ui_gp_leds && prev_pos_marker_mask == pos_marker_mask )
134 tk 1531
    return 0;
173 tk 1532
  prev_ui_gp_leds = ui_gp_leds;
134 tk 1533
  prev_pos_marker_mask = pos_marker_mask;
1534
 
1535
  // transfer to GP LEDs
514 tk 1536
  if( seq_hwcfg_led.gp_dout_l_sr ) {
1537
    if( seq_hwcfg_led.gp_dout_l2_sr )
1538
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_l_sr-1, (ui_gp_leds >> 0) & 0xff);
496 tk 1539
    else
514 tk 1540
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_l_sr-1, ((ui_gp_leds ^ pos_marker_mask) >> 0) & 0xff);
496 tk 1541
  }
134 tk 1542
 
514 tk 1543
  if( seq_hwcfg_led.gp_dout_r_sr ) {
1544
    if( seq_hwcfg_led.gp_dout_r2_sr )
1545
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_r_sr-1, (ui_gp_leds >> 8) & 0xff);
496 tk 1546
    else
514 tk 1547
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_r_sr-1, ((ui_gp_leds ^ pos_marker_mask) >> 8) & 0xff);
496 tk 1548
  }
134 tk 1549
 
514 tk 1550
  if( seq_hwcfg_led.gp_dout_l2_sr )
1551
    SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_l2_sr-1, (pos_marker_mask >> 0) & 0xff);
1552
  if( seq_hwcfg_led.gp_dout_r2_sr )
1553
    SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_r2_sr-1, (pos_marker_mask >> 8) & 0xff);
496 tk 1554
 
524 tk 1555
 
1556
  if( seq_hwcfg_blm.enabled ) {
1557
    // Red LEDs (position marker)
1558
    int track_ix;
1559
    for(track_ix=0; track_ix<(NUM_BLM_LED_SRS/2); ++track_ix) {
1560
      u16 pos_marker_mask = 0x0000;
1561
      if( sequencer_running ) {
1562
    u8 track = ui_selected_group + track_ix;
1563
    u8 played_step = seq_core_trk[track].step;
1564
    if( (played_step >> 4) == ui_selected_step_view )
1565
      pos_marker_mask = 1 << (played_step & 0xf);
1566
      }
1567
 
1568
      // Prepare Green LEDs (triggers)
1569
      u8 green_l = ui_blm_leds[2*track_ix+0];
1570
      u8 green_r = ui_blm_leds[2*track_ix+1];
1571
 
1572
      // Red LEDs (position marker)
1573
      if( seq_hwcfg_blm.dout_duocolour ) {
1574
    BLM_DOUT_SRSet(1, 2*track_ix+0, pos_marker_mask & 0xff);
1575
    BLM_DOUT_SRSet(1, 2*track_ix+1, (pos_marker_mask >> 8) & 0xff);
1576
 
1577
    if( seq_hwcfg_blm.dout_duocolour == 2 ) {
1578
      // Colour Mode 2: clear green LED, so that only one LED is lit
1579
      if( pos_marker_mask & 0x00ff )
1580
        green_l &= ~pos_marker_mask;
1581
      else if( pos_marker_mask & 0xff00 )
1582
        green_r &= ~(pos_marker_mask >> 8);
1583
    }
1584
      } else {
1585
    // If Duo-LEDs not enabled: invert Green LEDs
1586
    if( pos_marker_mask & 0x00ff )
1587
      green_l ^= pos_marker_mask;
1588
    else if( pos_marker_mask & 0xff00 )
1589
      green_r ^= (pos_marker_mask >> 8);
1590
      }
1591
 
1592
      // Set Green LEDs
1593
      BLM_DOUT_SRSet(0, 2*track_ix+0, green_l);
1594
      BLM_DOUT_SRSet(0, 2*track_ix+1, green_r);
1595
    }
1596
  }
1597
 
1598
 
514 tk 1599
  if( seq_hwcfg_blm8x8.enabled && seq_hwcfg_blm8x8.dout_gp_mapping ) {
513 tk 1600
    // for wilba's frontpanel
134 tk 1601
 
513 tk 1602
    // BLM_X DOUT -> GP LED mapping
1603
    // 0 = 15,16    1 = 13,14   2 = 11,12   3 = 9,10
1604
    // 4 = 1,2  5 = 3,4     6 = 5,6     7 = 7,8
134 tk 1605
 
513 tk 1606
    // bit 7: first green (i.e. GP1-G)
1607
    // bit 6: first red (i.e. GP1-R)
1608
    // bit 5: second green (i.e. GP2-G)
1609
    // bit 4: second red (i.e. GP2-R)
134 tk 1610
 
513 tk 1611
    // this mapping routine takes ca. 5 uS
1612
    // since it's only executed when ui_gp_leds or gp_mask has changed, it doesn't really hurt
134 tk 1613
 
513 tk 1614
    u16 modified_gp_leds = ui_gp_leds;
134 tk 1615
#if 1
513 tk 1616
    // extra: red LED is lit exclusively for higher contrast
1617
    modified_gp_leds &= ~pos_marker_mask;
134 tk 1618
#endif
1619
 
513 tk 1620
    int sr;
1621
    const u8 blm_x_sr_map[8] = {4, 5, 6, 7, 3, 2, 1, 0};
1622
    u16 gp_mask = 1 << 0;
1623
    for(sr=0; sr<8; ++sr) {
1624
      u8 pattern = 0;
134 tk 1625
 
513 tk 1626
      if( modified_gp_leds & gp_mask )
1627
    pattern |= 0x80;
1628
      if( pos_marker_mask & gp_mask )
1629
    pattern |= 0x40;
1630
      gp_mask <<= 1;
1631
      if( modified_gp_leds & gp_mask )
1632
    pattern |= 0x20;
1633
      if( pos_marker_mask & gp_mask )
1634
    pattern |= 0x10;
1635
      gp_mask <<= 1;
134 tk 1636
 
513 tk 1637
      u8 mapped_sr = blm_x_sr_map[sr];
1638
      BLM_X_LED_rows[mapped_sr][0] = (BLM_X_LED_rows[mapped_sr][0] & 0x0f) | pattern;
1639
    }
134 tk 1640
  }
1641
 
184 tk 1642
  return 0; // no error
134 tk 1643
}
1644
 
1645
 
1646
/////////////////////////////////////////////////////////////////////////////
168 tk 1647
// for menu handling (e.g. flashing cursor, doubleclick counter, etc...)
1648
// called each mS
1649
/////////////////////////////////////////////////////////////////////////////
1650
s32 SEQ_UI_MENU_Handler_Periodic()
1651
{
1652
  if( ++ui_cursor_flash_ctr >= SEQ_UI_CURSOR_FLASH_CTR_MAX ) {
1653
    ui_cursor_flash_ctr = 0;
1654
    seq_ui_display_update_req = 1;
173 tk 1655
  } else if( ui_cursor_flash_ctr == SEQ_UI_CURSOR_FLASH_CTR_LED_OFF ) {
168 tk 1656
    seq_ui_display_update_req = 1;
173 tk 1657
  }
1658
  // important: flash flag has to be recalculated on each invocation of this
1659
  // handler, since counter could also be reseted outside this function
1660
  ui_cursor_flash = ui_cursor_flash_ctr >= SEQ_UI_CURSOR_FLASH_CTR_LED_OFF;
168 tk 1661
 
184 tk 1662
 
240 tk 1663
  // used in some pages for temporary messages
416 tk 1664
  if( ui_hold_msg_ctr ) {
240 tk 1665
    --ui_hold_msg_ctr;
1666
 
416 tk 1667
    if( !ui_hold_msg_ctr )
1668
      seq_ui_display_update_req = 1;
1669
  }
1670
 
596 tk 1671
  // used for temporary messages
1672
  if( ui_msg_ctr )
1673
    --ui_msg_ctr;
299 tk 1674
 
184 tk 1675
  // VU meters (used in MUTE menu, could also be available as LED matrix...)
1676
  static u8 vu_meter_prediv = 0; // predivider for VU meters
1677
 
1678
  if( ++vu_meter_prediv >= 4 ) {
1679
    vu_meter_prediv = 0;
1680
 
333 tk 1681
 
1682
    portENTER_CRITICAL();
1683
 
184 tk 1684
    u8 track;
1685
    seq_core_trk_t *t = &seq_core_trk[0];
1686
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++t, ++track)
1687
      if( t->vu_meter )
1688
    --t->vu_meter;
333 tk 1689
 
1690
    int i;
1691
    u8 *vu_meter = (u8 *)&seq_layer_vu_meter[0];
1692
    for(i=0; i<sizeof(seq_layer_vu_meter); ++i, ++vu_meter) {
1693
      if( *vu_meter && !(*vu_meter & 0x80) ) // if bit 7 set: static value
1694
    *vu_meter -= 1;
1695
    }
1696
 
318 tk 1697
    portEXIT_CRITICAL();
184 tk 1698
  }
1699
 
168 tk 1700
  return 0;
1701
}
1702
 
1703
 
1704
/////////////////////////////////////////////////////////////////////////////
328 tk 1705
// Should be regulary called to check if the layer/instrument/step selection
1706
// is valid for the current track
1707
// At least executed before button/encoder and LCD function calls
1708
/////////////////////////////////////////////////////////////////////////////
1709
s32 SEQ_UI_CheckSelections(void)
1710
{
492 tk 1711
  if( (ui_selected_tracks >> (4*ui_selected_group)) == 0 )
1712
    ui_selected_tracks = 1 << (4*ui_selected_group);
1713
 
328 tk 1714
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1715
 
1716
  if( ui_selected_instrument >= SEQ_PAR_NumInstrumentsGet(visible_track) )
1717
    ui_selected_instrument = 0;
1718
 
1719
  if( ui_selected_par_layer >= SEQ_PAR_NumLayersGet(visible_track) )
1720
    ui_selected_par_layer = 0;
1721
 
1722
  if( ui_selected_trg_layer >= SEQ_TRG_NumLayersGet(visible_track) )
1723
    ui_selected_trg_layer = 0;
1724
 
1725
  if( ui_selected_step >= SEQ_TRG_NumStepsGet(visible_track) )
1726
    ui_selected_step = 0;
1727
 
1728
  if( ui_selected_step_view >= (SEQ_TRG_NumStepsGet(visible_track)/16) ) {
1729
    ui_selected_step_view = 0;
1730
    ui_selected_step %= 16;
1731
  }
1732
 
336 tk 1733
  if( ui_selected_step < (16*ui_selected_step_view) ||
1734
      ui_selected_step >= (16*(ui_selected_step_view+1)) )
328 tk 1735
    ui_selected_step_view = ui_selected_step / 16;
1736
 
1737
  return 0; // no error
1738
}
1739
 
1740
 
1741
/////////////////////////////////////////////////////////////////////////////
134 tk 1742
// Returns the currently visible track
1743
/////////////////////////////////////////////////////////////////////////////
1744
u8 SEQ_UI_VisibleTrackGet(void)
1745
{
1746
  u8 offset = 0;
1747
 
484 tk 1748
  u8 selected_tracks = ui_selected_tracks >> (4*ui_selected_group);
1749
  if( selected_tracks & (1 << 3) )
134 tk 1750
    offset = 3;
484 tk 1751
  if( selected_tracks & (1 << 2) )
134 tk 1752
    offset = 2;
484 tk 1753
  if( selected_tracks & (1 << 1) )
134 tk 1754
    offset = 1;
484 tk 1755
  if( selected_tracks & (1 << 0) )
134 tk 1756
    offset = 0;
1757
 
1758
  return 4*ui_selected_group + offset;
1759
}
1760
 
168 tk 1761
 
1762
/////////////////////////////////////////////////////////////////////////////
178 tk 1763
// Returns 1 if 'track' is selected
1764
/////////////////////////////////////////////////////////////////////////////
1765
s32 SEQ_UI_IsSelectedTrack(u8 track)
1766
{
484 tk 1767
  return (ui_selected_tracks & (1 << track)) ? 1 : 0;
178 tk 1768
}
1769
 
1770
 
1771
/////////////////////////////////////////////////////////////////////////////
240 tk 1772
// Sets a new selected step and updates the step view
1773
/////////////////////////////////////////////////////////////////////////////
1774
s32 SEQ_UI_SelectedStepSet(u8 step)
1775
{
1776
  ui_selected_step = step;
328 tk 1777
  SEQ_UI_CheckSelections();
1778
 
240 tk 1779
  return 0; // no error
1780
}
1781
 
1782
 
1783
/////////////////////////////////////////////////////////////////////////////
168 tk 1784
// Increments the selected tracks/groups
1785
// OUT: 1 if value has been changed, otherwise 0
1786
/////////////////////////////////////////////////////////////////////////////
1787
s32 SEQ_UI_GxTyInc(s32 incrementer)
1788
{
1789
  int gxty = SEQ_UI_VisibleTrackGet();
1790
  int prev_gxty = gxty;
1791
 
1792
  if( incrementer >= 0 ) {
1793
    if( (gxty += incrementer) >= SEQ_CORE_NUM_TRACKS )
1794
      gxty = SEQ_CORE_NUM_TRACKS-1;
1795
  } else {
1796
    if( (gxty += incrementer) < 0 )
1797
      gxty = 0;
1798
  }
1799
 
1800
  if( gxty == prev_gxty )
1801
    return 0; // no change
1802
 
484 tk 1803
  ui_selected_tracks = 1 << gxty;
168 tk 1804
  ui_selected_group = gxty / 4;
1805
 
1806
  return 1; // value changed
1807
}
1808
 
1809
 
1810
/////////////////////////////////////////////////////////////////////////////
236 tk 1811
// Increments a 16bit variable within given min/max range
1812
// OUT: 1 if value has been changed, otherwise 0
1813
/////////////////////////////////////////////////////////////////////////////
240 tk 1814
s32 SEQ_UI_Var16_Inc(u16 *value, u16 min, u16 max, s32 incrementer)
236 tk 1815
{
1816
  int new_value = *value;
1817
  int prev_value = new_value;
1818
 
1819
  if( incrementer >= 0 ) {
1820
    if( (new_value += incrementer) >= max )
1821
      new_value = max;
1822
  } else {
1823
    if( (new_value += incrementer) < min )
1824
      new_value = min;
1825
  }
1826
 
1827
  if( new_value == prev_value )
1828
    return 0; // no change
1829
 
1830
  *value = new_value;
1831
 
1832
  return 1; // value changed
1833
}
1834
 
240 tk 1835
/////////////////////////////////////////////////////////////////////////////
1836
// Increments an 8bit variable within given min/max range
1837
// OUT: 1 if value has been changed, otherwise 0
1838
/////////////////////////////////////////////////////////////////////////////
1839
s32 SEQ_UI_Var8_Inc(u8 *value, u16 min, u16 max, s32 incrementer)
1840
{
1841
  u16 tmp = *value;
1842
  if( SEQ_UI_Var16_Inc(&tmp, min, max, incrementer) ) {
1843
    *value = tmp;
1844
    return 1; // value changed
1845
  }
236 tk 1846
 
240 tk 1847
  return 0; // value hasn't been changed
1848
}
1849
 
1850
 
236 tk 1851
/////////////////////////////////////////////////////////////////////////////
168 tk 1852
// Increments a CC within given min/max range
1853
// OUT: 1 if value has been changed, otherwise 0
1854
/////////////////////////////////////////////////////////////////////////////
248 tk 1855
s32 SEQ_UI_CC_Inc(u8 cc, u8 min, u8 max, s32 incrementer)
168 tk 1856
{
1857
  u8 visible_track = SEQ_UI_VisibleTrackGet();
173 tk 1858
  int new_value = SEQ_CC_Get(visible_track, cc);
1859
  int prev_value = new_value;
168 tk 1860
 
1861
  if( incrementer >= 0 ) {
173 tk 1862
    if( (new_value += incrementer) >= max )
1863
      new_value = max;
168 tk 1864
  } else {
173 tk 1865
    if( (new_value += incrementer) < min )
1866
      new_value = min;
168 tk 1867
  }
1868
 
173 tk 1869
  if( new_value == prev_value )
168 tk 1870
    return 0; // no change
1871
 
173 tk 1872
  SEQ_CC_Set(visible_track, cc, new_value);
168 tk 1873
 
179 tk 1874
  // set same value for all selected tracks
1875
  u8 track;
1876
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1877
    if( track != visible_track && SEQ_UI_IsSelectedTrack(track) )
1878
      SEQ_CC_Set(track, cc, new_value);
1879
 
168 tk 1880
  return 1; // value changed
1881
}
1882
 
173 tk 1883
 
1884
/////////////////////////////////////////////////////////////////////////////
179 tk 1885
// Sets a CC value on all selected tracks
1886
// OUT: 1 if value has been changed, otherwise 0
1887
/////////////////////////////////////////////////////////////////////////////
248 tk 1888
s32 SEQ_UI_CC_Set(u8 cc, u8 value)
179 tk 1889
{
1890
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1891
  int prev_value = SEQ_CC_Get(visible_track, cc);
1892
 
1893
  if( value == prev_value )
1894
    return 0; // no change
1895
 
1896
  SEQ_CC_Set(visible_track, cc, value);
1897
 
1898
  // set same value for all selected tracks
1899
  u8 track;
1900
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1901
    if( track != visible_track && SEQ_UI_IsSelectedTrack(track) )
1902
      SEQ_CC_Set(track, cc, value);
1903
 
1904
  return 1; // value changed
1905
}
1906
 
1907
/////////////////////////////////////////////////////////////////////////////
173 tk 1908
// Modifies a bitfield in a CC value to a given value
1909
// OUT: 1 if value has been changed, otherwise 0
1910
/////////////////////////////////////////////////////////////////////////////
248 tk 1911
s32 SEQ_UI_CC_SetFlags(u8 cc, u8 flag_mask, u8 value)
173 tk 1912
{
1913
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1914
  int new_value = SEQ_CC_Get(visible_track, cc);
1915
  int prev_value = new_value;
1916
 
1917
  new_value = (new_value & ~flag_mask) | value;
1918
 
1919
  if( new_value == prev_value )
1920
    return 0; // no change
1921
 
1922
  SEQ_CC_Set(visible_track, cc, new_value);
1923
 
179 tk 1924
  // do same modification for all selected tracks
1925
  u8 track;
1926
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1927
    if( track != visible_track && SEQ_UI_IsSelectedTrack(track) ) {
1928
      int new_value = SEQ_CC_Get(track, cc);
1929
      new_value = (new_value & ~flag_mask) | value;
1930
      SEQ_CC_Set(track, cc, new_value);
1931
    }
1932
 
173 tk 1933
  return 1; // value changed
1934
}
1935
 
1936
 
299 tk 1937
/////////////////////////////////////////////////////////////////////////////
596 tk 1938
// Print temporary user messages (e.g. warnings, errors)
299 tk 1939
// expects mS delay and two lines, each up to 20 characters
1940
/////////////////////////////////////////////////////////////////////////////
596 tk 1941
s32 SEQ_UI_Msg(seq_ui_msg_type_t msg_type, u16 delay, char *line1, char *line2)
299 tk 1942
{
596 tk 1943
  ui_msg_type = msg_type;
1944
  ui_msg_ctr = delay;
1945
  strncpy((char *)ui_msg[0], line1, UI_MSG_MAX_CHAR);
1946
  strncpy((char *)ui_msg[1], line2, UI_MSG_MAX_CHAR);
299 tk 1947
 
1948
  return 0; // no error
1949
}
1950
 
1951
/////////////////////////////////////////////////////////////////////////////
596 tk 1952
// Stops temporary message if no SD card warning
1953
/////////////////////////////////////////////////////////////////////////////
1954
s32 SEQ_UI_MsgStop(void)
1955
{
1956
  if( ui_msg_type != SEQ_UI_MSG_SDCARD )
1957
    ui_msg_ctr = 0;
1958
 
1959
  return 0; // no error
1960
}
1961
 
1962
/////////////////////////////////////////////////////////////////////////////
299 tk 1963
// Prints a temporary error messages after file operation
1964
// Expects error status number (as defined in seq_file.h)
1965
/////////////////////////////////////////////////////////////////////////////
1966
s32 SEQ_UI_SDCardErrMsg(u16 delay, s32 status)
1967
{
1968
  // TODO: add more verbose error messages, they are clearly defined in seq_file.h)
1969
  char str[21];
1970
  sprintf(str, "E%3d (DOSFS: D%3d)", -status, seq_file_dfs_errno < 1000 ? seq_file_dfs_errno : 999);
596 tk 1971
  return SEQ_UI_Msg(SEQ_UI_MSG_SDCARD, delay, "!! SD Card Error !!!", str);
299 tk 1972
}