Subversion Repositories svn.mios32

Rev

Rev 1203 | Rev 1206 | 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 1205 2011-05-13 22:06:38Z tk $
2
/*
3
 * User Interface Routines
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
 
272 tk 18
// with this switch, seq_ui.h/seq_ui_pages.inc will create local variables
19
#define SEQ_UI_PAGES_INC_LOCAL_VARS 1
20
 
134 tk 21
#include <mios32.h>
299 tk 22
#include <string.h>
690 tk 23
#include <blm.h>
464 tk 24
#include <blm_x.h>
190 tk 25
#include <seq_midi_out.h>
26
#include <seq_bpm.h>
134 tk 27
 
290 tk 28
#include "tasks.h"
134 tk 29
#include "seq_ui.h"
728 tk 30
#include "seq_lcd.h"
31
#include "seq_lcd_logo.h"
492 tk 32
#include "seq_hwcfg.h"
134 tk 33
#include "seq_lcd.h"
34
#include "seq_led.h"
186 tk 35
#include "seq_midply.h"
134 tk 36
#include "seq_core.h"
399 tk 37
#include "seq_song.h"
333 tk 38
#include "seq_par.h"
178 tk 39
#include "seq_layer.h"
184 tk 40
#include "seq_cc.h"
785 tk 41
#include "seq_midi_sysex.h"
1020 tk 42
#include "seq_blm.h"
299 tk 43
#include "seq_file.h"
690 tk 44
#include "seq_file_hw.h"
134 tk 45
 
46
 
47
/////////////////////////////////////////////////////////////////////////////
48
// Global variables
49
/////////////////////////////////////////////////////////////////////////////
50
 
159 tk 51
u8 seq_ui_display_update_req;
52
u8 seq_ui_display_init_req;
134 tk 53
 
167 tk 54
seq_ui_button_state_t seq_ui_button_state;
55
 
134 tk 56
u8 ui_selected_group;
484 tk 57
u16 ui_selected_tracks;
134 tk 58
u8 ui_selected_par_layer;
59
u8 ui_selected_trg_layer;
328 tk 60
u8 ui_selected_instrument;
134 tk 61
u8 ui_selected_step_view;
62
u8 ui_selected_step;
168 tk 63
u8 ui_selected_item;
134 tk 64
 
168 tk 65
u8 ui_selected_item;
134 tk 66
 
240 tk 67
u16 ui_hold_msg_ctr;
68
 
206 tk 69
seq_ui_page_t ui_page;
272 tk 70
seq_ui_page_t ui_selected_page;
600 tk 71
seq_ui_page_t ui_stepview_prev_page;
72
seq_ui_page_t ui_trglayer_prev_page;
73
seq_ui_page_t ui_parlayer_prev_page;
206 tk 74
 
173 tk 75
volatile u8 ui_cursor_flash;
740 tk 76
volatile u8 ui_cursor_flash_overrun_ctr;
173 tk 77
u16 ui_cursor_flash_ctr;
134 tk 78
 
316 tk 79
u8 ui_edit_name_cursor;
80
u8 ui_edit_preset_num_category;
81
u8 ui_edit_preset_num_label;
729 tk 82
u8 ui_edit_preset_num_drum;
316 tk 83
 
193 tk 84
u8 ui_seq_pause;
85
 
625 tk 86
seq_ui_remote_mode_t seq_ui_remote_mode;
626 tk 87
seq_ui_remote_mode_t seq_ui_remote_active_mode;
625 tk 88
mios32_midi_port_t seq_ui_remote_port;
626 tk 89
mios32_midi_port_t seq_ui_remote_active_port;
625 tk 90
u8 seq_ui_remote_id;
626 tk 91
u16 seq_ui_remote_client_timeout_ctr;
92
u8 seq_ui_remote_force_lcd_update;
93
u8 seq_ui_remote_force_led_update;
193 tk 94
 
634 tk 95
u8 seq_ui_backup_req;
740 tk 96
u8 seq_ui_format_req;
974 tk 97
u8 seq_ui_saveall_req;
625 tk 98
 
744 tk 99
// to display directories via SEQ_UI_SelectListItem() and SEQ_LCD_PrintList() -- see seq_ui_sysex.c as example
746 tk 100
char ui_global_dir_list[80];
634 tk 101
 
1203 tk 102
seq_ui_bookmark_t seq_ui_bookmarks[SEQ_UI_BOOKMARKS_NUM];
744 tk 103
 
134 tk 104
/////////////////////////////////////////////////////////////////////////////
105
// Local variables
106
/////////////////////////////////////////////////////////////////////////////
107
 
168 tk 108
static s32 (*ui_button_callback)(seq_ui_button_t button, s32 depressed);
109
static s32 (*ui_encoder_callback)(seq_ui_encoder_t encoder, s32 incrementer);
173 tk 110
static s32 (*ui_led_callback)(u16 *gp_leds);
167 tk 111
static s32 (*ui_lcd_callback)(u8 high_prio);
352 tk 112
static s32 (*ui_exit_callback)(void);
752 tk 113
static s32 (*ui_delayed_action_callback)(u32 parameter);
114
static u32 ui_delayed_action_parameter;
167 tk 115
 
168 tk 116
static u16 ui_gp_leds;
167 tk 117
 
1040 tk 118
#define UI_MSG_MAX_CHAR 31
596 tk 119
static char ui_msg[2][UI_MSG_MAX_CHAR];
120
static u16 ui_msg_ctr;
121
static seq_ui_msg_type_t ui_msg_type;
299 tk 122
 
740 tk 123
static u16 ui_delayed_action_ctr;
299 tk 124
 
1203 tk 125
static seq_ui_page_t ui_page_before_bookmark;
752 tk 126
 
127
 
134 tk 128
/////////////////////////////////////////////////////////////////////////////
129
// Initialisation
130
/////////////////////////////////////////////////////////////////////////////
131
s32 SEQ_UI_Init(u32 mode)
132
{
626 tk 133
  int i;
134
  // clear all LEDs
135
  for(i=0; i<SEQ_LED_NUM_SR; ++i)
136
    SEQ_LED_SRSet(i, 0x00);
137
 
134 tk 138
  // init selection variables
139
  ui_selected_group = 0;
140
  ui_selected_tracks = (1 << 0);
141
  ui_selected_par_layer = 0;
142
  ui_selected_trg_layer = 0;
328 tk 143
  ui_selected_instrument = 0;
134 tk 144
  ui_selected_step_view = 0;
145
  ui_selected_step = 0;
168 tk 146
  ui_selected_item = 0;
134 tk 147
 
240 tk 148
  ui_hold_msg_ctr = 0;
596 tk 149
  ui_msg_ctr = 0;
740 tk 150
  ui_delayed_action_ctr = 0;
240 tk 151
 
740 tk 152
  ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
173 tk 153
  ui_cursor_flash = 0;
168 tk 154
 
167 tk 155
  seq_ui_button_state.ALL = 0;
156
 
193 tk 157
  ui_seq_pause = 0;
158
 
134 tk 159
  // visible GP pattern
160
  ui_gp_leds = 0x0000;
161
 
625 tk 162
  // default remote mode
163
  seq_ui_remote_mode = SEQ_UI_REMOTE_MODE_AUTO;
626 tk 164
  seq_ui_remote_active_mode = SEQ_UI_REMOTE_MODE_AUTO;
625 tk 165
  seq_ui_remote_port = DEFAULT;
626 tk 166
  seq_ui_remote_active_port = DEFAULT;
625 tk 167
  seq_ui_remote_id = 0x00;
626 tk 168
  seq_ui_remote_client_timeout_ctr = 0;
169
  seq_ui_remote_force_lcd_update = 0;
170
  seq_ui_remote_force_led_update = 0;
625 tk 171
 
634 tk 172
  // misc
173
  seq_ui_backup_req = 0;
740 tk 174
  seq_ui_format_req = 0;
974 tk 175
  seq_ui_saveall_req = 0;
634 tk 176
 
167 tk 177
  // change to edit page
178
  ui_page = SEQ_UI_PAGE_NONE;
179
  SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
134 tk 180
 
1203 tk 181
  // finally init bookmarks
182
  ui_page_before_bookmark = SEQ_UI_PAGE_EDIT;
183
  for(i=0; i<SEQ_UI_BOOKMARKS_NUM; ++i) {
184
    char buffer[10];
185
    seq_ui_bookmark_t *bm = (seq_ui_bookmark_t *)&seq_ui_bookmarks[i];
596 tk 186
 
1203 tk 187
    sprintf(buffer, "BM%2d ", i+1);
188
    memcpy((char *)bm->name, buffer, 6);
189
    bm->enable.ALL = ~0;
190
    bm->flags.LOCKED = 0;
191
    SEQ_UI_Bookmark_Store(i);
192
  }
193
 
134 tk 194
  return 0; // no error
195
}
196
 
197
 
198
/////////////////////////////////////////////////////////////////////////////
178 tk 199
// Inits the speed mode of all encoders
200
// Auto mode should be used whenever:
201
//    - the edit screen is entered
202
//    - the group is changed
203
//    - a track is changed
204
//    - a layer is changed
205
/////////////////////////////////////////////////////////////////////////////
206
s32 SEQ_UI_InitEncSpeed(u32 auto_config)
207
{
208
  mios32_enc_config_t enc_config;
209
 
210
  if( auto_config ) {
513 tk 211
 
212
    if( !seq_hwcfg_enc.auto_fast )
213
      return 0; // auto mode not enabled - ignore auto reconfiguration request
214
 
333 tk 215
    switch( SEQ_PAR_AssignmentGet(SEQ_UI_VisibleTrackGet(), ui_selected_par_layer) ) {
216
      case SEQ_PAR_Type_Velocity:
217
      case SEQ_PAR_Type_Length:
218
      case SEQ_PAR_Type_CC:
219
      case SEQ_PAR_Type_PitchBend:
220
      case SEQ_PAR_Type_Probability:
221
      case SEQ_PAR_Type_Delay:
178 tk 222
    seq_ui_button_state.FAST_ENCODERS = 1;
223
    break;
224
 
225
      default:
226
    seq_ui_button_state.FAST_ENCODERS = 0;
227
    }
228
  }
229
 
230
  // change for datawheel and GP encoders
231
  int enc;
232
  for(enc=0; enc<17; ++enc) {
233
    enc_config = MIOS32_ENC_ConfigGet(enc);
1121 tk 234
    enc_config.cfg.speed = (seq_ui_button_state.FAST_ENCODERS || seq_ui_button_state.FAST2_ENCODERS) ? FAST : NORMAL;
513 tk 235
    enc_config.cfg.speed_par = (enc == 0) ? seq_hwcfg_enc.datawheel_fast_speed : seq_hwcfg_enc.gp_fast_speed;
178 tk 236
    MIOS32_ENC_ConfigSet(enc, enc_config);
237
  }
238
 
239
  return 0; // no error
240
}
241
 
242
 
243
/////////////////////////////////////////////////////////////////////////////
167 tk 244
// Various installation routines for menu page LCD handlers
245
/////////////////////////////////////////////////////////////////////////////
168 tk 246
s32 SEQ_UI_InstallButtonCallback(void *callback)
167 tk 247
{
168 tk 248
  ui_button_callback = callback;
167 tk 249
  return 0; // no error
250
}
251
 
168 tk 252
s32 SEQ_UI_InstallEncoderCallback(void *callback)
167 tk 253
{
168 tk 254
  ui_encoder_callback = callback;
167 tk 255
  return 0; // no error
256
}
257
 
168 tk 258
s32 SEQ_UI_InstallLEDCallback(void *callback)
167 tk 259
{
168 tk 260
  ui_led_callback = callback;
167 tk 261
  return 0; // no error
262
}
263
 
168 tk 264
s32 SEQ_UI_InstallLCDCallback(void *callback)
167 tk 265
{
266
  ui_lcd_callback = callback;
267
  return 0; // no error
268
}
269
 
352 tk 270
s32 SEQ_UI_InstallExitCallback(void *callback)
271
{
272
  ui_exit_callback = callback;
273
  return 0; // no error
274
}
167 tk 275
 
352 tk 276
 
752 tk 277
s32 SEQ_UI_InstallDelayedActionCallback(void *callback, u16 delay_mS, u32 parameter)
740 tk 278
{
752 tk 279
  // must be atomic
280
  MIOS32_IRQ_Disable();
281
  ui_delayed_action_parameter = parameter;
740 tk 282
  ui_delayed_action_callback = callback;
752 tk 283
  ui_delayed_action_ctr = delay_mS;
284
  MIOS32_IRQ_Enable();
740 tk 285
 
286
  return 0; // no error
287
}
288
 
289
s32 SEQ_UI_UnInstallDelayedActionCallback(void *callback)
290
{
752 tk 291
  // must be atomic
292
  MIOS32_IRQ_Disable();
740 tk 293
  if( ui_delayed_action_callback == callback )
294
    ui_delayed_action_callback = 0;
752 tk 295
  MIOS32_IRQ_Enable();
296
 
740 tk 297
  return 0; // no error
298
}
299
 
300
 
167 tk 301
/////////////////////////////////////////////////////////////////////////////
302
// Change the menu page
303
/////////////////////////////////////////////////////////////////////////////
304
s32 SEQ_UI_PageSet(seq_ui_page_t page)
305
{
306
  if( page != ui_page ) {
352 tk 307
 
308
    // call page exit callback
309
    if( ui_exit_callback != NULL )
310
      ui_exit_callback();
311
 
167 tk 312
    // disable hooks of previous page and request re-initialisation
318 tk 313
    portENTER_CRITICAL();
167 tk 314
    ui_page = page;
168 tk 315
    ui_button_callback = NULL;
316
    ui_encoder_callback = NULL;
317
    ui_led_callback = NULL;
167 tk 318
    ui_lcd_callback = NULL;
352 tk 319
    ui_exit_callback = NULL;
740 tk 320
    ui_delayed_action_callback = NULL;
318 tk 321
    portEXIT_CRITICAL();
167 tk 322
 
323
    // request display initialisation
324
    seq_ui_display_init_req = 1;
325
  }
173 tk 326
 
306 tk 327
  // for MENU button:
1024 tk 328
  if( seq_hwcfg_button_beh.menu )
329
    seq_ui_button_state.MENU_PRESSED = 0; // MENU page selection finished
306 tk 330
  // first page has been selected - display new screen
331
  seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 1;
332
 
272 tk 333
  // for SEQ_UI_MENU which is accessible with EXIT button
334
  // remember the current selectable page
335
  if( ui_page >= SEQ_UI_FIRST_MENU_SELECTION_PAGE )
336
    ui_selected_page = ui_page;
337
 
184 tk 338
  return 0; // no error
167 tk 339
}
340
 
341
 
342
/////////////////////////////////////////////////////////////////////////////
272 tk 343
// Returns name of menu page (18 characters)
344
/////////////////////////////////////////////////////////////////////////////
345
char *SEQ_UI_PageNameGet(seq_ui_page_t page)
346
{
690 tk 347
  return (char *)ui_menu_pages[page].name;
272 tk 348
}
349
 
350
 
351
/////////////////////////////////////////////////////////////////////////////
134 tk 352
// Dedicated button functions
353
// Mapped to physical buttons in SEQ_UI_Button_Handler()
354
// Will also be mapped to MIDI keys later (for MIDI remote function)
355
/////////////////////////////////////////////////////////////////////////////
356
static s32 SEQ_UI_Button_GP(s32 depressed, u32 gp)
357
{
1044 tk 358
  // in MENU page: overrule GP buttons as long as MENU button is pressed/active
306 tk 359
  if( seq_ui_button_state.MENU_PRESSED ) {
360
    if( depressed ) return -1;
361
    SEQ_UI_PageSet(ui_shortcut_menu_pages[gp]);
362
  } else {
363
    // forward to menu page
740 tk 364
    if( ui_button_callback != NULL ) {
306 tk 365
      ui_button_callback(gp, depressed);
740 tk 366
      ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
367
    }
306 tk 368
  }
134 tk 369
 
370
  return 0; // no error
371
}
372
 
373
static s32 SEQ_UI_Button_Left(s32 depressed)
374
{
168 tk 375
  // forward to menu page
740 tk 376
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL ) {
168 tk 377
    ui_button_callback(SEQ_UI_BUTTON_Left, depressed);
740 tk 378
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
379
  }
134 tk 380
 
381
  return 0; // no error
382
}
383
 
384
static s32 SEQ_UI_Button_Right(s32 depressed)
385
{
168 tk 386
  // forward to menu page
740 tk 387
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL ) {
168 tk 388
    ui_button_callback(SEQ_UI_BUTTON_Right, depressed);
740 tk 389
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
390
  }
134 tk 391
 
392
  return 0; // no error
393
}
394
 
168 tk 395
static s32 SEQ_UI_Button_Down(s32 depressed)
396
{
240 tk 397
  seq_ui_button_state.DOWN = depressed ? 0 : 1;
398
 
168 tk 399
  // forward to menu page
740 tk 400
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL ) {
168 tk 401
    ui_button_callback(SEQ_UI_BUTTON_Down, depressed);
740 tk 402
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
403
  }
168 tk 404
 
405
  return 0; // no error
406
}
407
 
408
static s32 SEQ_UI_Button_Up(s32 depressed)
409
{
240 tk 410
  seq_ui_button_state.UP = depressed ? 0 : 1;
411
 
168 tk 412
  // forward to menu page
740 tk 413
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL ) {
168 tk 414
    ui_button_callback(SEQ_UI_BUTTON_Up, depressed);
740 tk 415
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
416
  }
168 tk 417
 
418
  return 0; // no error
419
}
420
 
1068 tk 421
s32 SEQ_UI_Button_Stop(s32 depressed)
134 tk 422
{
423
  if( depressed ) return -1; // ignore when button depressed
424
 
159 tk 425
  // if sequencer running: stop it
426
  // if sequencer already stopped: reset song position
193 tk 427
  if( SEQ_BPM_IsRunning() )
428
    SEQ_BPM_Stop();
759 tk 429
  else {
1145 tk 430
    SEQ_SONG_Reset(0);
431
    SEQ_CORE_Reset(0);
759 tk 432
    SEQ_MIDPLY_Reset();
433
  }
159 tk 434
 
134 tk 435
  return 0; // no error
436
}
437
 
438
static s32 SEQ_UI_Button_Pause(s32 depressed)
439
{
440
  if( depressed ) return -1; // ignore when button depressed
441
 
193 tk 442
  // if in auto mode and BPM generator is clocked in slave mode:
443
  // change to master mode
444
  SEQ_BPM_CheckAutoMaster();
159 tk 445
 
193 tk 446
  // toggle pause mode
447
  ui_seq_pause ^= 1;
448
 
449
  // execute stop/continue depending on new mode
450
  if( ui_seq_pause )
451
    SEQ_BPM_Stop();
452
  else
453
    SEQ_BPM_Cont();
454
 
134 tk 455
  return 0; // no error
456
}
457
 
1068 tk 458
s32 SEQ_UI_Button_Play(s32 depressed)
134 tk 459
{
460
  if( depressed ) return -1; // ignore when button depressed
461
 
1090 tk 462
  // if MENU button pressed -> tap tempo
463
  if( seq_ui_button_state.MENU_PRESSED )
464
    return SEQ_UI_BPM_TapTempo();
465
 
186 tk 466
  // if in auto mode and BPM generator is clocked in slave mode:
467
  // change to master mode
468
  SEQ_BPM_CheckAutoMaster();
469
 
193 tk 470
#if 0
471
  // if sequencer running: restart it
472
  // if sequencer stopped: continue at last song position
473
  if( SEQ_BPM_IsRunning() )
474
    SEQ_BPM_Start();
475
  else
476
    SEQ_BPM_Cont();
186 tk 477
#else
193 tk 478
  // always restart sequencer
479
  SEQ_BPM_Start();
186 tk 480
#endif
159 tk 481
 
134 tk 482
  return 0; // no error
483
}
484
 
485
static s32 SEQ_UI_Button_Rew(s32 depressed)
486
{
240 tk 487
  seq_ui_button_state.REW = depressed ? 0 : 1;
488
 
134 tk 489
  if( depressed ) return -1; // ignore when button depressed
490
 
607 tk 491
  if( SEQ_SONG_ActiveGet() ) {
492
    portENTER_CRITICAL();
493
    SEQ_SONG_Rew();
494
    portEXIT_CRITICAL();
495
  } else
496
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "We are not", "in Song Mode!");
497
 
134 tk 498
  return 0; // no error
499
}
500
 
501
static s32 SEQ_UI_Button_Fwd(s32 depressed)
502
{
240 tk 503
  seq_ui_button_state.FWD = depressed ? 0 : 1;
504
 
134 tk 505
  if( depressed ) return -1; // ignore when button depressed
506
 
607 tk 507
  if( SEQ_SONG_ActiveGet() ) {
508
    portENTER_CRITICAL();
509
    SEQ_SONG_Fwd();
510
    portEXIT_CRITICAL();
511
  } else
512
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "We are not", "in Song Mode!");
513
 
134 tk 514
  return 0; // no error
515
}
516
 
596 tk 517
static s32 SEQ_UI_Button_Loop(s32 depressed)
518
{
519
  if( seq_hwcfg_button_beh.loop ) {
520
    // toggle mode
521
    if( depressed ) return -1; // ignore when button depressed
522
    // should be atomic
523
    portENTER_CRITICAL();
524
    seq_core_state.LOOP ^= 1;
525
  } else {
526
    // should be atomic
527
    portENTER_CRITICAL();
528
    // set mode
529
    seq_core_state.LOOP = depressed ? 0 : 1;
530
  }
531
  portEXIT_CRITICAL();
532
 
533
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Loop Mode", seq_core_state.LOOP ? "    on" : "   off");
534
 
535
  return 0; // no error
536
}
537
 
951 tk 538
static s32 SEQ_UI_Button_Follow(s32 depressed)
539
{
540
  if( seq_hwcfg_button_beh.follow ) {
541
    // toggle mode
542
    if( depressed ) return -1; // ignore when button depressed
543
    // should be atomic
544
    portENTER_CRITICAL();
545
    seq_core_state.FOLLOW ^= 1;
546
  } else {
547
    // should be atomic
548
    portENTER_CRITICAL();
549
    // set mode
550
    seq_core_state.FOLLOW = depressed ? 0 : 1;
551
  }
552
  portEXIT_CRITICAL();
553
 
554
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Follow Mode", seq_core_state.FOLLOW ? "    on" : "   off");
555
 
556
  return 0; // no error
557
}
558
 
596 tk 559
static s32 SEQ_UI_Button_Scrub(s32 depressed)
560
{
561
  // double function: -> Loop if menu button pressed
562
  if( seq_ui_button_state.MENU_PRESSED )
563
    return SEQ_UI_Button_Loop(depressed);
564
 
565
  if( seq_hwcfg_button_beh.scrub ) {
566
    // toggle mode
567
    if( depressed ) return -1; // ignore when button depressed
568
    seq_ui_button_state.SCRUB ^= 1;
569
  } else {
570
    // set mode
571
    seq_ui_button_state.SCRUB = depressed ? 0 : 1;
572
  }
573
 
574
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Scrub Mode", seq_ui_button_state.SCRUB ? "    on" : "   off");
575
 
576
  return 0; // no error
577
}
578
 
513 tk 579
static s32 SEQ_UI_Button_TempoPreset(s32 depressed)
134 tk 580
{
513 tk 581
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
240 tk 582
 
513 tk 583
  if( seq_hwcfg_button_beh.tempo_preset ) {
584
    if( depressed ) return -1; // ignore when button depressed
678 tk 585
    if( !seq_ui_button_state.TEMPO_PRESET ) // due to page change: button going to be set, clear other toggle buttons
586
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 587
    seq_ui_button_state.TEMPO_PRESET ^= 1; // toggle TEMPO_PRESET pressed (will also be released once GP button has been pressed)
588
  } else {
589
    // set mode
590
    seq_ui_button_state.TEMPO_PRESET = depressed ? 0 : 1;
591
  }
134 tk 592
 
513 tk 593
  if( seq_ui_button_state.TEMPO_PRESET ) {
594
    prev_page = ui_page;
595
    SEQ_UI_PageSet(SEQ_UI_PAGE_BPM_PRESETS);
596
  } else {
524 tk 597
    if( ui_page == SEQ_UI_PAGE_BPM_PRESETS )
598
      SEQ_UI_PageSet(prev_page);
513 tk 599
  }
240 tk 600
 
134 tk 601
  return 0; // no error
602
}
603
 
513 tk 604
static s32 SEQ_UI_Button_TapTempo(s32 depressed)
134 tk 605
{
513 tk 606
  seq_ui_button_state.TAP_TEMPO = depressed ? 0 : 1;
240 tk 607
 
134 tk 608
  if( depressed ) return -1; // ignore when button depressed
609
 
1142 tk 610
  return SEQ_UI_BPM_TapTempo();
134 tk 611
}
612
 
524 tk 613
static s32 SEQ_UI_Button_ExtRestart(s32 depressed)
134 tk 614
{
615
  if( depressed ) return -1; // ignore when button depressed
616
 
596 tk 617
  // should be atomic
524 tk 618
  portENTER_CRITICAL();
619
  seq_core_state.EXT_RESTART_REQ = 1;
620
  portEXIT_CRITICAL();
621
 
596 tk 622
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "External Restart", "requested");
623
 
134 tk 624
  return 0; // no error
625
}
626
 
596 tk 627
static s32 SEQ_UI_Button_Metronome(s32 depressed)
628
{
629
  // double function: -> ExtRestart if menu button pressed
630
  if( seq_ui_button_state.MENU_PRESSED )
631
    return SEQ_UI_Button_ExtRestart(depressed);
632
 
633
  if( seq_hwcfg_button_beh.metronome ) {
634
    // toggle mode
635
    if( depressed ) return -1; // ignore when button depressed
636
    // should be atomic
637
    portENTER_CRITICAL();
638
    seq_core_state.METRONOME ^= 1;
639
  } else {
640
    // should be atomic
641
    portENTER_CRITICAL();
642
    // set mode
643
    seq_core_state.METRONOME = depressed ? 0 : 1;
644
  }
645
  portEXIT_CRITICAL();
646
 
647
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Metronome", seq_core_state.METRONOME ? "    on" : "   off");
648
 
599 tk 649
#if 0
650
  // metronome button can be used to trigger pattern file fixes
651
  if( !depressed )
652
    SEQ_PATTERN_FixAll();
653
#endif
654
 
596 tk 655
  return 0; // no error
656
}
657
 
630 tk 658
static s32 SEQ_UI_Button_Record(s32 depressed)
659
{
660
  if( depressed ) return -1; // ignore when button depressed
661
 
662
  // change to utility page
663
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKREC);
664
 
665
  return 0; // no error
666
}
667
 
134 tk 668
static s32 SEQ_UI_Button_Utility(s32 depressed)
669
{
670
  if( depressed ) return -1; // ignore when button depressed
671
 
240 tk 672
  // change to utility page
673
  SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
674
 
134 tk 675
  return 0; // no error
676
}
677
 
678
static s32 SEQ_UI_Button_Copy(s32 depressed)
679
{
240 tk 680
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 681
 
240 tk 682
  seq_ui_button_state.COPY = depressed ? 0 : 1;
683
 
280 tk 684
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
685
    if( depressed ) return -1;
686
    SEQ_UI_MIXER_Copy();
729 tk 687
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Mixer Map", "copied");
280 tk 688
    return 1;
729 tk 689
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
690
    if( depressed ) return -1;
691
    SEQ_UI_SONG_Copy();
692
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Song Position", "copied");
693
    return 1;
280 tk 694
  } else {
695
    if( !depressed ) {
696
      prev_page = ui_page;
697
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
698
    }
240 tk 699
 
280 tk 700
    s32 status = SEQ_UI_UTIL_CopyButton(depressed);
240 tk 701
 
596 tk 702
    if( depressed ) {
703
      if( prev_page != SEQ_UI_PAGE_UTIL )
704
    SEQ_UI_PageSet(prev_page);
240 tk 705
 
596 tk 706
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "copied");
707
    }
708
 
280 tk 709
    return status;
710
  }
134 tk 711
}
712
 
713
static s32 SEQ_UI_Button_Paste(s32 depressed)
714
{
240 tk 715
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 716
 
240 tk 717
  seq_ui_button_state.PASTE = depressed ? 0 : 1;
718
 
280 tk 719
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
720
    if( depressed ) return -1;
721
    SEQ_UI_MIXER_Paste();
729 tk 722
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Mixer Map", "pasted");
280 tk 723
    return 1;
729 tk 724
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
725
    if( depressed ) return -1;
726
    SEQ_UI_SONG_Paste();
727
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Song Position", "pasted");
728
    return 1;
280 tk 729
  } else {
730
    if( !depressed ) {
731
      prev_page = ui_page;
732
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
733
    }
240 tk 734
 
280 tk 735
    s32 status = SEQ_UI_UTIL_PasteButton(depressed);
240 tk 736
 
596 tk 737
    if( depressed ) {
738
      if( prev_page != SEQ_UI_PAGE_UTIL )
739
    SEQ_UI_PageSet(prev_page);
240 tk 740
 
596 tk 741
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "pasted");
742
    }
743
 
280 tk 744
    return status;
745
  }
134 tk 746
}
747
 
740 tk 748
 
749
// callback function for delayed Clear Mixer function
752 tk 750
static void SEQ_UI_Button_Clear_Mixer(u32 dummy)
740 tk 751
{
752
  SEQ_UI_MIXER_Clear();
753
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Mixer Map", "cleared");
754
}
755
 
756
// callback function for delayed Clear SongPos function
752 tk 757
static void SEQ_UI_Button_Clear_SongPos(u32 dummy)
740 tk 758
{
759
  SEQ_UI_SONG_Clear();
760
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Song Position", "cleared");
761
}
762
 
763
// callback function for clear track
752 tk 764
static void SEQ_UI_Button_Clear_Track(u32 dummy)
740 tk 765
{
766
  SEQ_UI_UTIL_ClearButton(0); // button pressed
767
  SEQ_UI_UTIL_ClearButton(1); // button depressed
768
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "cleared");
769
}
770
 
134 tk 771
static s32 SEQ_UI_Button_Clear(s32 depressed)
772
{
240 tk 773
  seq_ui_button_state.CLEAR = depressed ? 0 : 1;
280 tk 774
 
775
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
740 tk 776
    if( depressed )
777
      SEQ_UI_UnInstallDelayedActionCallback(SEQ_UI_Button_Clear_Mixer);
752 tk 778
    else {
779
      SEQ_UI_InstallDelayedActionCallback(SEQ_UI_Button_Clear_Mixer, 2000, 0);
780
      SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION, 2001, "", "to clear Mixer Map");
781
    }
729 tk 782
    return 1;
783
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
740 tk 784
    if( depressed )
785
      SEQ_UI_UnInstallDelayedActionCallback(SEQ_UI_Button_Clear_SongPos);
752 tk 786
    else {
787
      SEQ_UI_InstallDelayedActionCallback(SEQ_UI_Button_Clear_SongPos, 2000, 0);
788
      SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION, 2001, "", "to clear SongPos");
789
    }
729 tk 790
    return 1;
791
  } else {
740 tk 792
    if( depressed )
793
      SEQ_UI_UnInstallDelayedActionCallback(SEQ_UI_Button_Clear_Track);
752 tk 794
    else {
795
      SEQ_UI_InstallDelayedActionCallback(SEQ_UI_Button_Clear_Track, 2000, 0);
796
      SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION, 2001, "", "to clear Track");
797
    }
280 tk 798
    return 1;
799
  }
134 tk 800
}
801
 
1014 tk 802
 
803
static s32 SEQ_UI_Button_Undo(s32 depressed)
804
{
805
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
806
 
807
  seq_ui_button_state.UNDO = depressed ? 0 : 1;
808
 
809
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
810
    if( depressed ) return -1;
811
    SEQ_UI_MIXER_Undo();
812
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Mixer Map", "Undo applied");
813
    return 1;
814
  } else {
815
    if( !depressed ) {
816
      prev_page = ui_page;
817
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
818
    }
819
 
820
    s32 status = SEQ_UI_UTIL_UndoButton(depressed);
821
 
822
    if( depressed ) {
823
      if( prev_page != SEQ_UI_PAGE_UTIL )
824
    SEQ_UI_PageSet(prev_page);
825
 
826
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "Undo applied");
827
    }
828
 
829
    return status;
830
  }
831
}
832
 
833
 
134 tk 834
static s32 SEQ_UI_Button_Menu(s32 depressed)
835
{
513 tk 836
  if( seq_hwcfg_button_beh.menu ) {
837
    // toggle mode
838
    if( depressed ) return -1; // ignore when button depressed
839
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
678 tk 840
    if( !seq_ui_button_state.MENU_PRESSED ) // due to page change: button going to be set, clear other toggle buttons
841
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 842
    seq_ui_button_state.MENU_PRESSED ^= 1; // toggle MENU pressed (will also be released once GP button has been pressed)
843
  } else {
844
    // set mode
845
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
846
    seq_ui_button_state.MENU_PRESSED = depressed ? 0 : 1;
847
  }
134 tk 848
 
849
  return 0; // no error
850
}
851
 
1203 tk 852
 
853
static s32 SEQ_UI_Button_Bookmark(s32 depressed)
854
{
855
  if( seq_hwcfg_button_beh.bookmark ) {
856
    if( depressed ) return -1; // ignore when button depressed
857
    if( !seq_ui_button_state.BOOKMARK ) // due to page change: button going to be set, clear other toggle buttons
858
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
859
#if 0
860
    seq_ui_button_state.BOOKMARK ^= 1; // toggle BOOKMARK pressed (will also be released once GP button has been pressed)
861
#else
862
    seq_ui_button_state.BOOKMARK = 1; // seems that it's better *not* to toggle!
863
#endif
864
  } else {
865
    // set mode
866
    seq_ui_button_state.BOOKMARK = depressed ? 0 : 1;
867
  }
868
 
869
  if( seq_ui_button_state.BOOKMARK ) {
870
    if( ui_page != SEQ_UI_PAGE_BOOKMARKS )
871
      ui_page_before_bookmark = ui_page;
872
    SEQ_UI_PageSet(SEQ_UI_PAGE_BOOKMARKS);
873
  } else {
874
    if( ui_page == SEQ_UI_PAGE_BOOKMARKS )
875
      SEQ_UI_PageSet(ui_page_before_bookmark);
876
  }
877
 
878
  return 0; // no error
879
}
880
 
881
 
1205 tk 882
static s32 SEQ_UI_Button_DirectBookmark(s32 depressed, u32 bookmark_button)
883
{
884
  if( !depressed )
885
    ui_page_before_bookmark = ui_page;
886
 
887
  return SEQ_UI_BOOKMARKS_Button_Handler(bookmark_button, depressed);
888
}
889
 
890
 
134 tk 891
static s32 SEQ_UI_Button_Select(s32 depressed)
892
{
1203 tk 893
  // double function: -> Bookmark if menu button pressed
894
  if( seq_ui_button_state.MENU_PRESSED )
895
    return SEQ_UI_Button_Bookmark(depressed);
896
 
168 tk 897
  // forward to menu page
591 tk 898
  if( !seq_ui_button_state.MENU_PRESSED ) {
899
    seq_ui_button_state.SELECT_PRESSED = depressed ? 0 : 1;
740 tk 900
    if( ui_button_callback != NULL ) {
591 tk 901
      ui_button_callback(SEQ_UI_BUTTON_Select, depressed);
740 tk 902
      ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
903
    }
591 tk 904
  }
134 tk 905
 
906
  return 0; // no error
907
}
908
 
909
static s32 SEQ_UI_Button_Exit(s32 depressed)
910
{
951 tk 911
  // double function: -> Follow if menu button pressed
912
  if( seq_ui_button_state.MENU_PRESSED )
913
    return SEQ_UI_Button_Follow(depressed);
914
 
272 tk 915
  if( depressed ) return -1; // ignore when button depressed
916
 
917
  u8 prev_ui_page = ui_page;
918
 
168 tk 919
  // forward to menu page
1123 tk 920
  if( ui_button_callback != NULL ) {
921
    if( ui_button_callback(SEQ_UI_BUTTON_Exit, depressed) >= 1 )
922
      return 1; // page has already handled exit button
740 tk 923
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
924
  }
134 tk 925
 
167 tk 926
  // release all button states
984 tk 927
  // seq_ui_button_state.ALL = 0;
928
  // clashes with SOLO/ALL/etc.
167 tk 929
 
272 tk 930
  // enter menu page if we were not there before
931
  if( prev_ui_page != SEQ_UI_PAGE_MENU )
932
    SEQ_UI_PageSet(SEQ_UI_PAGE_MENU);
933
 
134 tk 934
  return 0; // no error
935
}
936
 
937
static s32 SEQ_UI_Button_Edit(s32 depressed)
938
{
741 tk 939
  seq_ui_button_state.EDIT_PRESSED = depressed ? 0 : 1;
591 tk 940
 
134 tk 941
  if( depressed ) return -1; // ignore when button depressed
942
 
167 tk 943
  // change to edit page
944
  SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
945
 
178 tk 946
  // set/clear encoder fast function if required
947
  SEQ_UI_InitEncSpeed(1); // auto config
948
 
134 tk 949
  return 0; // no error
950
}
951
 
952
static s32 SEQ_UI_Button_Mute(s32 depressed)
953
{
591 tk 954
  seq_ui_button_state.MUTE_PRESSED = depressed ? 0 : 1;
955
 
134 tk 956
  if( depressed ) return -1; // ignore when button depressed
957
 
184 tk 958
  SEQ_UI_PageSet(SEQ_UI_PAGE_MUTE);
959
 
134 tk 960
  return 0; // no error
961
}
962
 
963
static s32 SEQ_UI_Button_Pattern(s32 depressed)
964
{
591 tk 965
  seq_ui_button_state.PATTERN_PRESSED = depressed ? 0 : 1;
966
 
134 tk 967
  if( depressed ) return -1; // ignore when button depressed
968
 
184 tk 969
  SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN);
970
 
134 tk 971
  return 0; // no error
972
}
973
 
974
static s32 SEQ_UI_Button_Song(s32 depressed)
975
{
591 tk 976
  seq_ui_button_state.SONG_PRESSED = depressed ? 0 : 1;
977
 
134 tk 978
  if( depressed ) return -1; // ignore when button depressed
979
 
399 tk 980
  SEQ_UI_PageSet(SEQ_UI_PAGE_SONG);
981
 
134 tk 982
  return 0; // no error
983
}
984
 
985
static s32 SEQ_UI_Button_Solo(s32 depressed)
986
{
513 tk 987
  if( seq_hwcfg_button_beh.solo ) {
988
    // toggle mode
989
    if( depressed ) return -1; // ignore when button depressed
990
    seq_ui_button_state.SOLO ^= 1;
991
  } else {
992
    // set mode
993
    seq_ui_button_state.SOLO = depressed ? 0 : 1;
994
  }
134 tk 995
 
996
  return 0; // no error
997
}
998
 
999
static s32 SEQ_UI_Button_Fast(s32 depressed)
1000
{
513 tk 1001
  if( seq_hwcfg_button_beh.fast ) {
1002
    // toggle mode
1003
    if( depressed ) return -1; // ignore when button depressed
1004
    seq_ui_button_state.FAST_ENCODERS ^= 1;
1005
  } else {
1006
    // set mode
1007
    seq_ui_button_state.FAST_ENCODERS = depressed ? 0 : 1;
1008
  }
134 tk 1009
 
178 tk 1010
  SEQ_UI_InitEncSpeed(0); // no auto config
1011
 
134 tk 1012
  return 0; // no error
1013
}
1014
 
1121 tk 1015
static s32 SEQ_UI_Button_Fast2(s32 depressed)
1016
{
1017
  if( seq_hwcfg_button_beh.fast2 ) {
1018
    // toggle mode
1019
    if( depressed ) return -1; // ignore when button depressed
1020
    seq_ui_button_state.FAST2_ENCODERS ^= 1;
1021
  } else {
1022
    // set mode
1023
    seq_ui_button_state.FAST2_ENCODERS = depressed ? 0 : 1;
1024
  }
1025
 
1026
  SEQ_UI_InitEncSpeed(0); // no auto config
1027
 
1028
  return 0; // no error
1029
}
1030
 
134 tk 1031
static s32 SEQ_UI_Button_All(s32 depressed)
1032
{
178 tk 1033
  seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE = depressed ? 0 : 1;
134 tk 1034
 
513 tk 1035
  if( seq_hwcfg_button_beh.all ) {
1036
    // toggle mode
1037
    if( depressed ) return -1;
1038
    seq_ui_button_state.CHANGE_ALL_STEPS ^= 1;
1039
  } else {
1040
    // set mode
1041
    seq_ui_button_state.CHANGE_ALL_STEPS = depressed ? 0 : 1;
1042
  }
178 tk 1043
 
134 tk 1044
  return 0; // no error
1045
}
1046
 
1047
static s32 SEQ_UI_Button_StepView(s32 depressed)
1048
{
600 tk 1049
  //  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1050
  // also used by seq_ui_stepsel
1051
 
513 tk 1052
  if( seq_hwcfg_button_beh.step_view ) {
1053
    if( depressed ) return -1; // ignore when button depressed
678 tk 1054
    if( !seq_ui_button_state.STEP_VIEW ) // due to page change: button going to be set, clear other toggle buttons
1055
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1056
    seq_ui_button_state.STEP_VIEW ^= 1; // toggle STEP_VIEW pressed (will also be released once GP button has been pressed)
1057
  } else {
1058
    // set mode
1059
    seq_ui_button_state.STEP_VIEW = depressed ? 0 : 1;
1060
  }
134 tk 1061
 
513 tk 1062
  if( seq_ui_button_state.STEP_VIEW ) {
600 tk 1063
    ui_stepview_prev_page = ui_page;
303 tk 1064
    SEQ_UI_PageSet(SEQ_UI_PAGE_STEPSEL);
1065
  } else {
524 tk 1066
    if( ui_page == SEQ_UI_PAGE_STEPSEL )
600 tk 1067
      SEQ_UI_PageSet(ui_stepview_prev_page);
303 tk 1068
  }
134 tk 1069
 
1070
  return 0; // no error
1071
}
1072
 
513 tk 1073
static s32 SEQ_UI_Button_TrackSel(s32 depressed)
134 tk 1074
{
513 tk 1075
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 1076
 
513 tk 1077
  if( seq_hwcfg_button_beh.track_sel ) {
1078
    if( depressed ) return -1; // ignore when button depressed
678 tk 1079
    if( !seq_ui_button_state.TRACK_SEL ) // due to page change: button going to be set, clear other toggle buttons
1080
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1081
    seq_ui_button_state.TRACK_SEL ^= 1; // toggle TRACKSEL status (will also be released once GP button has been pressed)
1082
  } else {
1083
    seq_ui_button_state.TRACK_SEL = depressed ? 0 : 1;
1084
  }
1085
 
1086
  if( seq_ui_button_state.TRACK_SEL ) {
1087
    prev_page = ui_page;
1088
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRACKSEL);
1089
  } else {
524 tk 1090
    if( ui_page == SEQ_UI_PAGE_TRACKSEL )
1091
      SEQ_UI_PageSet(prev_page);
513 tk 1092
  }
1093
 
134 tk 1094
  return 0; // no error
1095
}
1096
 
987 tk 1097
static s32 SEQ_UI_Button_Group(s32 depressed, u32 group)
1098
{
1099
  if( depressed ) return -1; // ignore when button depressed
1100
 
1101
  if( group >= 4 ) return -2; // max. 4 group buttons
1102
 
1103
  // in song page: track and group buttons are used to select the cursor position
1104
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1105
    ui_selected_item = 3 + group;
1106
    return 0;
1107
  }
1108
 
1109
  // if group has changed:
1110
  if( group != ui_selected_group ) {
1111
    // get current track selection
1112
    u16 old_tracks = ui_selected_tracks >> (4*ui_selected_group);
1113
 
1114
    // select new group
1115
    ui_selected_group = group;
1116
 
1117
    // take over old track selection
1118
    ui_selected_tracks = old_tracks << (4*ui_selected_group);
1119
  }
1120
 
1121
  // set/clear encoder fast function if required
1122
  SEQ_UI_InitEncSpeed(1); // auto config
1123
 
1124
  return 0; // no error
1125
}
1126
 
484 tk 1127
static s32 SEQ_UI_Button_Track(s32 depressed, u32 track_button)
134 tk 1128
{
484 tk 1129
  static u8 button_state = 0x0f; // all 4 buttons depressed
134 tk 1130
 
484 tk 1131
  if( track_button >= 4 ) return -2; // max. 4 track buttons
134 tk 1132
 
484 tk 1133
  if( depressed ) {
1134
    button_state |= (1 << track_button);
1135
    return 0; // no error
1136
  }
134 tk 1137
 
484 tk 1138
  button_state &= ~(1 << track_button);
1139
 
987 tk 1140
  // in pattern and song page: use track buttons as group buttons
1141
  if( ui_page == SEQ_UI_PAGE_PATTERN || ui_page == SEQ_UI_PAGE_SONG ) {
1142
    return SEQ_UI_Button_Group(depressed, track_button);
1143
  }
1144
 
484 tk 1145
  if( button_state == (~(1 << track_button) & 0xf) ) {
1146
    // if only one select button pressed: radio-button function (1 of 4)
1147
    ui_selected_tracks = 1 << (track_button + 4*ui_selected_group);
1148
  } else {
1149
    // if more than one select button pressed: toggle function (4 of 4)
1150
    ui_selected_tracks ^= 1 << (track_button + 4*ui_selected_group);
1151
  }
1152
 
178 tk 1153
  // set/clear encoder fast function if required
1154
  SEQ_UI_InitEncSpeed(1); // auto config
1155
 
134 tk 1156
  return 0; // no error
1157
}
1158
 
1146 tk 1159
static s32 SEQ_UI_Button_DirectTrack(s32 depressed, u32 track_button)
1160
{
1161
  static u16 button_state = 0xffff; // all 16 buttons depressed
1162
 
1163
  if( track_button >= 16 ) return -2; // max. 16 direct track buttons
1164
 
1165
  if( depressed ) {
1166
    button_state |= (1 << track_button);
1167
    return 0; // no error
1168
  }
1169
 
1170
  button_state &= ~(1 << track_button);
1171
 
1172
  if( button_state == (~(1 << track_button) & 0xffff) ) {
1173
    // if only one select button pressed: radio-button function (1 of 16)
1174
    ui_selected_tracks = 1 << track_button;
1175
  } else {
1176
    // if more than one select button pressed: toggle function (16 of 16)
1177
    ui_selected_tracks ^= 1 << track_button;
1178
  }
1179
 
1180
  // set/clear encoder fast function if required
1181
  SEQ_UI_InitEncSpeed(1); // auto config
1182
 
1183
  return 0; // no error
1184
}
1185
 
513 tk 1186
static s32 SEQ_UI_Button_ParLayerSel(s32 depressed)
1187
{
600 tk 1188
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1189
  // also used by seq_ui_parsel.c
513 tk 1190
 
1191
  if( seq_hwcfg_button_beh.par_layer ) {
1192
    if( depressed ) return -1; // ignore when button depressed
678 tk 1193
    if( !seq_ui_button_state.PAR_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1194
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1195
    seq_ui_button_state.PAR_LAYER_SEL ^= 1; // toggle PARSEL status (will also be released once GP button has been pressed)
1196
  } else {
1197
    seq_ui_button_state.PAR_LAYER_SEL = depressed ? 0 : 1;
1198
  }
1199
 
1200
  if( seq_ui_button_state.PAR_LAYER_SEL ) {
600 tk 1201
    ui_parlayer_prev_page = ui_page;
513 tk 1202
    SEQ_UI_PageSet(SEQ_UI_PAGE_PARSEL);
1203
  } else {
524 tk 1204
    if( ui_page == SEQ_UI_PAGE_PARSEL )
600 tk 1205
      SEQ_UI_PageSet(ui_parlayer_prev_page);
513 tk 1206
  }
1207
 
1208
  // set/clear encoder fast function if required
1209
  SEQ_UI_InitEncSpeed(1); // auto config
1210
 
1211
  return 0; // no error
1212
}
1213
 
134 tk 1214
static s32 SEQ_UI_Button_ParLayer(s32 depressed, u32 par_layer)
1215
{
1117 tk 1216
  static u8 layer_c_pressed = 0;
784 tk 1217
 
134 tk 1218
  if( par_layer >= 3 ) return -2; // max. 3 parlayer buttons
1219
 
1205 tk 1220
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1221
  u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1222
 
987 tk 1223
  // in song page: parameter layer buttons are used to select the cursor position
1224
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1225
    ui_selected_item = par_layer;
1226
    return 0;
1227
  }
1228
 
1205 tk 1229
  // drum mode in edit page: print parameter layer as long as button is pressed
1230
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1231
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1232
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1233
      ui_hold_msg_ctr = depressed ? 0 : ~0; // show value for at least 65 seconds... enough?
1234
    }
1235
  }
134 tk 1236
 
784 tk 1237
  // holding Layer C button allows to increment/decrement layer with A/B button
1238
  if( par_layer == 2 )
1239
    layer_c_pressed = !depressed;
1240
 
1241
  if( layer_c_pressed && par_layer == 0 ) {
333 tk 1242
    if( depressed ) return -1; // ignore when button depressed
784 tk 1243
    // increment layer
1244
    if( ++ui_selected_par_layer >= num_p_layers )
1245
      ui_selected_par_layer = 0;
1246
  } else if( layer_c_pressed && par_layer == 1 ) {
333 tk 1247
    if( depressed ) return -1; // ignore when button depressed
784 tk 1248
    // decrement layer
1249
    if( ui_selected_par_layer == 0 )
1250
      ui_selected_par_layer = num_p_layers - 1;
333 tk 1251
    else
784 tk 1252
      --ui_selected_par_layer;
333 tk 1253
  } else {
784 tk 1254
    if( num_p_layers <= 3 ) {
1255
      // 3 layers: direct selection with LayerA/B/C button
333 tk 1256
      if( depressed ) return -1; // ignore when button depressed
784 tk 1257
      if( par_layer >= num_p_layers ) {
1258
    char str1[21];
1259
    sprintf(str1, "Parameter Layer %c", 'A'+par_layer);
1260
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1261
      } else {
1262
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1263
    ui_selected_par_layer = par_layer;
1264
      }
1265
    } else if( num_p_layers <= 4 ) {
1266
      // 4 layers: LayerC Button toggles between C and D
1267
      if( depressed ) return -1; // ignore when button depressed
333 tk 1268
      seq_ui_button_state.PAR_LAYER_SEL = 0;
784 tk 1269
      if( par_layer == 2 )
1270
    ui_selected_par_layer = (ui_selected_par_layer == 2) ? 3 : 2;
1271
      else
1272
    ui_selected_par_layer = par_layer;
333 tk 1273
    } else {
784 tk 1274
      // >4 layers: LayerA/B button selects directly, Layer C button enters layer selection page
1275
      if( par_layer <= 1 ) {
1276
    if( depressed ) return -1; // ignore when button depressed
1277
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1278
    ui_selected_par_layer = par_layer;
1279
      } else {
1280
    return SEQ_UI_Button_ParLayerSel(depressed);
1281
      }
333 tk 1282
    }
1283
  }
1284
 
178 tk 1285
  // set/clear encoder fast function if required
1286
  SEQ_UI_InitEncSpeed(1); // auto config
1287
 
134 tk 1288
  return 0; // no error
1289
}
1290
 
513 tk 1291
static s32 SEQ_UI_Button_TrgLayerSel(s32 depressed)
1292
{
600 tk 1293
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1294
  // also used by seq_ui_trgsel.c
513 tk 1295
 
1296
  if( seq_hwcfg_button_beh.trg_layer ) {
1297
    if( depressed ) return -1; // ignore when button depressed
678 tk 1298
    if( !seq_ui_button_state.TRG_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1299
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1300
    seq_ui_button_state.TRG_LAYER_SEL ^= 1; // toggle TRGSEL status (will also be released once GP button has been pressed)
1301
  } else {
1302
    seq_ui_button_state.TRG_LAYER_SEL = depressed ? 0 : 1;
1303
  }
1304
 
1305
  if( seq_ui_button_state.TRG_LAYER_SEL ) {
600 tk 1306
    ui_trglayer_prev_page = ui_page;
513 tk 1307
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRGSEL);
1308
  } else {
524 tk 1309
    if( ui_page == SEQ_UI_PAGE_TRGSEL )
600 tk 1310
      SEQ_UI_PageSet(ui_trglayer_prev_page);
513 tk 1311
  }
1312
 
1313
  return 0; // no error
1314
}
1315
 
134 tk 1316
static s32 SEQ_UI_Button_TrgLayer(s32 depressed, u32 trg_layer)
1317
{
1117 tk 1318
  static u8 layer_c_pressed = 0;
784 tk 1319
 
134 tk 1320
  if( trg_layer >= 3 ) return -2; // max. 3 trglayer buttons
1321
 
326 tk 1322
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1323
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1324
  u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
134 tk 1325
 
1205 tk 1326
  // drum mode in edit page: ensure that trigger layer is print again
1327
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1328
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1329
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1330
      if( !depressed )
1331
    ui_hold_msg_ctr = 0;
1332
    }
1333
  }
1334
 
784 tk 1335
  // holding Layer C button allows to increment/decrement layer with A/B button
1336
  if( trg_layer == 2 )
1337
    layer_c_pressed = !depressed;
1338
 
1339
  if( layer_c_pressed && trg_layer == 0 ) {
326 tk 1340
    if( depressed ) return -1; // ignore when button depressed
784 tk 1341
    // increment layer
1342
    if( ++ui_selected_trg_layer >= num_t_layers )
1343
      ui_selected_trg_layer = 0;
1344
  } else if( layer_c_pressed && trg_layer == 1 ) {
326 tk 1345
    if( depressed ) return -1; // ignore when button depressed
784 tk 1346
    // decrement layer
1347
    if( ui_selected_trg_layer == 0 )
1348
      ui_selected_trg_layer = num_t_layers - 1;
326 tk 1349
    else
784 tk 1350
      --ui_selected_trg_layer;
326 tk 1351
  } else {
784 tk 1352
    if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 3 ) {
1353
      // 3 layers: direct selection with LayerA/B/C button
326 tk 1354
      if( depressed ) return -1; // ignore when button depressed
784 tk 1355
      if( trg_layer >= num_t_layers ) {
1356
    char str1[21];
1357
    sprintf(str1, "Trigger Layer %c", 'A'+trg_layer);
1358
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1359
      } else {
1360
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1361
    ui_selected_trg_layer = trg_layer;
1362
      }
1363
    } else if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 4 ) {
1364
      // 4 layers: LayerC Button toggles between C and D
1365
      if( depressed ) return -1; // ignore when button depressed
328 tk 1366
      seq_ui_button_state.TRG_LAYER_SEL = 0;
784 tk 1367
      if( trg_layer == 2 )
1368
    ui_selected_trg_layer = (ui_selected_trg_layer == 2) ? 3 : 2;
1369
      else
1370
    ui_selected_trg_layer = trg_layer;
326 tk 1371
    } else {
784 tk 1372
      // >4 layers or drum mode: LayerA/B button selects directly, Layer C button enters trigger selection page
1373
      // also used for drum tracks
1374
      if( trg_layer <= 1 ) {
1375
    if( depressed ) return -1; // ignore when button depressed
1376
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1377
    ui_selected_trg_layer = trg_layer;
1378
      } else {
1379
    return SEQ_UI_Button_TrgLayerSel(depressed);
1380
      }
326 tk 1381
    }
1382
  }
1383
 
134 tk 1384
  return 0; // no error
1385
}
1386
 
1387
 
1119 tk 1388
static s32 SEQ_UI_Button_Mixer(s32 depressed)
544 tk 1389
{
1390
  if( depressed ) return -1; // ignore when button depressed
134 tk 1391
 
1119 tk 1392
  SEQ_UI_PageSet(SEQ_UI_PAGE_MIXER);
544 tk 1393
 
1394
  return 0; // no error
1395
}
1396
 
1119 tk 1397
static s32 SEQ_UI_Button_TrackMode(s32 depressed)
544 tk 1398
{
1399
  if( depressed ) return -1; // ignore when button depressed
1400
 
1119 tk 1401
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMODE);
544 tk 1402
 
1403
  return 0; // no error
1404
}
1405
 
1119 tk 1406
static s32 SEQ_UI_Button_TrackGroove(s32 depressed)
544 tk 1407
{
1408
  if( depressed ) return -1; // ignore when button depressed
1409
 
1119 tk 1410
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKGRV);
1411
 
1412
  return 0; // no error
1413
}
1414
 
1415
static s32 SEQ_UI_Button_TrackLength(s32 depressed)
1416
{
1417
  if( depressed ) return -1; // ignore when button depressed
1418
 
1419
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKLEN);
1420
 
1421
  return 0; // no error
1422
}
1423
 
1424
static s32 SEQ_UI_Button_TrackDirection(s32 depressed)
1425
{
1426
  if( depressed ) return -1; // ignore when button depressed
1427
 
1428
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKDIR);
1429
 
1430
  return 0; // no error
1431
}
1432
 
1433
static s32 SEQ_UI_Button_TrackMorph(s32 depressed)
1434
{
1435
  if( depressed ) return -1; // ignore when button depressed
1436
 
1437
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMORPH);
1438
 
1439
  return 0; // no error
1440
}
1441
 
1442
static s32 SEQ_UI_Button_TrackTranspose(s32 depressed)
1443
{
1444
  if( depressed ) return -1; // ignore when button depressed
1445
 
544 tk 1446
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKTRAN);
1447
 
1448
  return 0; // no error
1449
}
1450
 
1451
 
742 tk 1452
// only used by keyboard remote function
1453
static s32 SEQ_UI_Button_ToggleGate(s32 depressed)
1454
{
1455
  if( depressed ) return -1; // ignore when button depressed
544 tk 1456
 
742 tk 1457
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1458
  u8 gate = SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? 0 : 1;
1459
  SEQ_TRG_GateSet(visible_track, ui_selected_step, ui_selected_instrument, gate);
544 tk 1460
 
742 tk 1461
  return 0; // no error
1462
}
1463
 
1464
 
1465
 
134 tk 1466
/////////////////////////////////////////////////////////////////////////////
1467
// Button handler
1468
/////////////////////////////////////////////////////////////////////////////
1469
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
1470
{
492 tk 1471
  int i;
1472
 
625 tk 1473
  // send MIDI event in remote mode and exit
626 tk 1474
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 1475
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendButton(pin, pin_value);
1476
 
1044 tk 1477
  // ignore as long as hardware config hasn't been read
496 tk 1478
  if( !SEQ_FILE_HW_ConfigLocked() )
1479
    return -1;
1480
 
740 tk 1481
  // ignore during a backup or format is created
1482
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1483
    return -1;
1484
 
328 tk 1485
  // ensure that selections are matching with track constraints
1486
  SEQ_UI_CheckSelections();
1487
 
492 tk 1488
  // request display update
1489
  seq_ui_display_update_req = 1;
134 tk 1490
 
596 tk 1491
  // stop current message if (new) button has been pressed
1492
  if( pin_value == 0 )
1493
    SEQ_UI_MsgStop();
134 tk 1494
 
596 tk 1495
 
492 tk 1496
  // MEMO: we could also use a jump table with references to the functions
1497
  // here, but this "spagetthi code" simplifies the configuration and
1498
  // the resulting ASM doesn't look that bad!
168 tk 1499
 
492 tk 1500
  for(i=0; i<SEQ_HWCFG_NUM_GP; ++i)
1501
    if( pin == seq_hwcfg_button.gp[i] )
1502
      return SEQ_UI_Button_GP(pin_value, i);
134 tk 1503
 
492 tk 1504
  for(i=0; i<SEQ_HWCFG_NUM_TRACK; ++i)
1505
    if( pin == seq_hwcfg_button.track[i] )
1506
      return SEQ_UI_Button_Track(pin_value, i);
1146 tk 1507
 
1508
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_TRACK; ++i)
1509
    if( pin == seq_hwcfg_button.direct_track[i] )
1510
      return SEQ_UI_Button_DirectTrack(pin_value, i);
1511
 
1205 tk 1512
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_BOOKMARK; ++i)
1513
    if( pin == seq_hwcfg_button.direct_bookmark[i] )
1514
      return SEQ_UI_Button_DirectBookmark(pin_value, i);
1515
 
513 tk 1516
  if( pin == seq_hwcfg_button.track_sel )
1517
    return SEQ_UI_Button_TrackSel(pin_value);
134 tk 1518
 
492 tk 1519
  for(i=0; i<SEQ_HWCFG_NUM_GROUP; ++i)
1520
    if( pin == seq_hwcfg_button.group[i] )
1521
      return SEQ_UI_Button_Group(pin_value, i);
134 tk 1522
 
492 tk 1523
  for(i=0; i<SEQ_HWCFG_NUM_PAR_LAYER; ++i)
1524
    if( pin == seq_hwcfg_button.par_layer[i] )
1525
      return SEQ_UI_Button_ParLayer(pin_value, i);
513 tk 1526
  if( pin == seq_hwcfg_button.par_layer_sel )
1527
    return SEQ_UI_Button_ParLayerSel(pin_value);
134 tk 1528
 
492 tk 1529
  for(i=0; i<SEQ_HWCFG_NUM_TRG_LAYER; ++i)
1530
    if( pin == seq_hwcfg_button.trg_layer[i] )
1531
      return SEQ_UI_Button_TrgLayer(pin_value, i);
513 tk 1532
  if( pin == seq_hwcfg_button.trg_layer_sel )
1533
    return SEQ_UI_Button_TrgLayerSel(pin_value);
134 tk 1534
 
492 tk 1535
  if( pin == seq_hwcfg_button.left )
1536
    return SEQ_UI_Button_Left(pin_value);
1537
  if( pin == seq_hwcfg_button.right )
1538
    return SEQ_UI_Button_Right(pin_value);
1539
  if( pin == seq_hwcfg_button.down )
1540
    return SEQ_UI_Button_Down(pin_value);
1541
  if( pin == seq_hwcfg_button.up )
1542
    return SEQ_UI_Button_Up(pin_value);
134 tk 1543
 
492 tk 1544
  if( pin == seq_hwcfg_button.scrub )
1545
    return SEQ_UI_Button_Scrub(pin_value);
1546
  if( pin == seq_hwcfg_button.metronome )
1547
    return SEQ_UI_Button_Metronome(pin_value);
134 tk 1548
 
630 tk 1549
  if( pin == seq_hwcfg_button.record )
1550
    return SEQ_UI_Button_Record(pin_value);
1551
 
492 tk 1552
  if( pin == seq_hwcfg_button.stop )
1553
    return SEQ_UI_Button_Stop(pin_value);
1554
  if( pin == seq_hwcfg_button.pause )
1555
    return SEQ_UI_Button_Pause(pin_value);
1556
  if( pin == seq_hwcfg_button.play )
1557
    return SEQ_UI_Button_Play(pin_value);
1558
  if( pin == seq_hwcfg_button.rew )
1559
    return SEQ_UI_Button_Rew(pin_value);
1560
  if( pin == seq_hwcfg_button.fwd )
1561
    return SEQ_UI_Button_Fwd(pin_value);
596 tk 1562
  if( pin == seq_hwcfg_button.loop )
1563
    return SEQ_UI_Button_Loop(pin_value);
973 tk 1564
  if( pin == seq_hwcfg_button.follow )
1565
    return SEQ_UI_Button_Follow(pin_value);
134 tk 1566
 
492 tk 1567
  if( pin == seq_hwcfg_button.utility )
1568
    return SEQ_UI_Button_Utility(pin_value);
1569
  if( pin == seq_hwcfg_button.copy )
1570
    return SEQ_UI_Button_Copy(pin_value);
1571
  if( pin == seq_hwcfg_button.paste )
1572
    return SEQ_UI_Button_Paste(pin_value);
1573
  if( pin == seq_hwcfg_button.clear )
1574
    return SEQ_UI_Button_Clear(pin_value);
1014 tk 1575
  if( pin == seq_hwcfg_button.undo )
1576
    return SEQ_UI_Button_Undo(pin_value);
134 tk 1577
 
492 tk 1578
  if( pin == seq_hwcfg_button.menu )
1579
    return SEQ_UI_Button_Menu(pin_value);
1203 tk 1580
  if( pin == seq_hwcfg_button.bookmark )
1581
    return SEQ_UI_Button_Bookmark(pin_value);
492 tk 1582
  if( pin == seq_hwcfg_button.select )
1583
    return SEQ_UI_Button_Select(pin_value);
1584
  if( pin == seq_hwcfg_button.exit )
1585
    return SEQ_UI_Button_Exit(pin_value);
134 tk 1586
 
513 tk 1587
  if( pin == seq_hwcfg_button.tap_tempo )
1588
    return SEQ_UI_Button_TapTempo(pin_value);
1589
  if( pin == seq_hwcfg_button.tempo_preset )
1590
    return SEQ_UI_Button_TempoPreset(pin_value);
524 tk 1591
  if( pin == seq_hwcfg_button.ext_restart )
1592
    return SEQ_UI_Button_ExtRestart(pin_value);
134 tk 1593
 
492 tk 1594
  if( pin == seq_hwcfg_button.edit )
1595
    return SEQ_UI_Button_Edit(pin_value);
1596
  if( pin == seq_hwcfg_button.mute )
1597
    return SEQ_UI_Button_Mute(pin_value);
1598
  if( pin == seq_hwcfg_button.pattern )
1599
    return SEQ_UI_Button_Pattern(pin_value);
1600
  if( pin == seq_hwcfg_button.song )
1601
    return SEQ_UI_Button_Song(pin_value);
134 tk 1602
 
492 tk 1603
  if( pin == seq_hwcfg_button.solo )
1604
    return SEQ_UI_Button_Solo(pin_value);
1605
  if( pin == seq_hwcfg_button.fast )
1606
    return SEQ_UI_Button_Fast(pin_value);
1121 tk 1607
  if( pin == seq_hwcfg_button.fast2 )
1608
    return SEQ_UI_Button_Fast2(pin_value);
492 tk 1609
  if( pin == seq_hwcfg_button.all )
1610
    return SEQ_UI_Button_All(pin_value);
134 tk 1611
 
492 tk 1612
  if( pin == seq_hwcfg_button.step_view )
1613
    return SEQ_UI_Button_StepView(pin_value);
134 tk 1614
 
544 tk 1615
  if( pin == seq_hwcfg_button.mixer )
1616
    return SEQ_UI_Button_Mixer(pin_value);
1617
 
1119 tk 1618
  if( pin == seq_hwcfg_button.track_mode )
1619
    return SEQ_UI_Button_TrackMode(pin_value);
1620
  if( pin == seq_hwcfg_button.track_groove )
1621
    return SEQ_UI_Button_TrackGroove(pin_value);
1622
  if( pin == seq_hwcfg_button.track_length )
1623
    return SEQ_UI_Button_TrackLength(pin_value);
1624
  if( pin == seq_hwcfg_button.track_direction )
1625
    return SEQ_UI_Button_TrackDirection(pin_value);
1626
  if( pin == seq_hwcfg_button.track_morph )
1627
    return SEQ_UI_Button_TrackMorph(pin_value);
1628
  if( pin == seq_hwcfg_button.track_transpose )
1629
    return SEQ_UI_Button_TrackTranspose(pin_value);
1630
 
625 tk 1631
  // always print debugging message
1632
#if 1
1081 tk 1633
  MUTEX_MIDIOUT_TAKE;
1634
  DEBUG_MSG("[SEQ_UI_Button_Handler] Button SR:%d, Pin:%d not mapped, it has been %s.\n",
1635
        (pin >> 3) + 1,
1636
        pin & 7,
1637
        pin_value ? "depressed" : "pressed");
1638
  MUTEX_MIDIOUT_GIVE;
625 tk 1639
#endif
1640
 
492 tk 1641
  return -1; // button not mapped
134 tk 1642
}
1643
 
1644
 
1645
/////////////////////////////////////////////////////////////////////////////
524 tk 1646
// BLM Button handler
1647
/////////////////////////////////////////////////////////////////////////////
1648
s32 SEQ_UI_BLM_Button_Handler(u32 row, u32 pin, u32 pin_value)
1649
{
625 tk 1650
  // send MIDI event in remote mode and exit
626 tk 1651
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 1652
    return SEQ_MIDI_SYSEX_REMOTE_Client_Send_BLM_Button(row, pin, pin_value);
1653
 
1044 tk 1654
  // ignore as long as hardware config hasn't been read
524 tk 1655
  if( !SEQ_FILE_HW_ConfigLocked() )
1656
    return -1;
1657
 
740 tk 1658
  // ignore during a backup or format is created
1659
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1660
    return -1;
1661
 
524 tk 1662
  if( row >= SEQ_CORE_NUM_TRACKS_PER_GROUP )
1663
    return -1; // more than 4 tracks not supported (yet) - could be done in this function w/o much effort
1664
 
1665
  if( pin >= 16 )
1666
    return -1; // more than 16 step buttons not supported (yet) - could be done by selecting the step view
1667
 
1668
  // select track depending on row
1669
  ui_selected_tracks = 1 << (row + 4*ui_selected_group);
1670
 
1671
  // ensure that selections are matching with track constraints
1672
  SEQ_UI_CheckSelections();
1673
 
1674
  // request display update
1675
  seq_ui_display_update_req = 1;
1676
 
1677
  // emulate general purpose button
758 tk 1678
  if( seq_hwcfg_blm.buttons_no_ui ) {
763 tk 1679
    s32 status = SEQ_UI_EDIT_Button_Handler(pin, pin_value);
758 tk 1680
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1681
    return status;
763 tk 1682
  }
1683
 
1684
  return SEQ_UI_Button_GP(pin_value, pin); // no error, pin_value and pin are swapped for this function due to consistency reasons
524 tk 1685
}
1686
 
1687
 
1688
/////////////////////////////////////////////////////////////////////////////
134 tk 1689
// Encoder handler
1690
/////////////////////////////////////////////////////////////////////////////
1691
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
1692
{
625 tk 1693
  // send MIDI event in remote mode and exit
626 tk 1694
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 1695
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendEncoder(encoder, incrementer);
1696
 
1044 tk 1697
  // ignore as long as hardware config hasn't been read
496 tk 1698
  if( !SEQ_FILE_HW_ConfigLocked() )
1699
    return -1;
1700
 
740 tk 1701
  // ignore during a backup or format is created
1702
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1703
    return -1;
1704
 
134 tk 1705
  if( encoder > 16 )
1706
    return -1; // encoder doesn't exist
1707
 
328 tk 1708
  // ensure that selections are matching with track constraints
1709
  SEQ_UI_CheckSelections();
1710
 
596 tk 1711
  // stop current message
1712
  SEQ_UI_MsgStop();
1713
 
134 tk 1714
  // limit incrementer
1715
  if( incrementer > 3 )
1716
    incrementer = 3;
1717
  else if( incrementer < -3 )
1718
    incrementer = -3;
1719
 
607 tk 1720
  if( seq_ui_button_state.SCRUB && encoder == 0 ) {
1721
    // if sequencer isn't already running, continue it (don't restart)
1722
    if( !SEQ_BPM_IsRunning() )
1723
      SEQ_BPM_Cont();
1724
    ui_seq_pause = 0; // clear pause mode
1725
    // Scrub sequence back or forth
1726
    portENTER_CRITICAL(); // should be atomic
1727
    SEQ_CORE_Scrub(incrementer);
1728
    portEXIT_CRITICAL();
1729
  } else if( !seq_ui_button_state.MENU_PRESSED && ui_encoder_callback != NULL ) {
173 tk 1730
    ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
740 tk 1731
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0; // ensure that value is visible when it has been changed
134 tk 1732
  }
1733
 
1734
  // request display update
159 tk 1735
  seq_ui_display_update_req = 1;
134 tk 1736
 
1737
  return 0; // no error
1738
}
1739
 
1740
 
353 tk 1741
 
134 tk 1742
/////////////////////////////////////////////////////////////////////////////
626 tk 1743
// Receives a MIDI package from APP_NotifyReceivedEvent (-> app.c)
1744
/////////////////////////////////////////////////////////////////////////////
1745
s32 SEQ_UI_REMOTE_MIDI_Receive(mios32_midi_port_t port, mios32_midi_package_t midi_package)
1746
{
1747
#if 1
1748
  // check for active remote mode
1749
  if( seq_ui_remote_active_mode != SEQ_UI_REMOTE_MODE_SERVER )
1750
    return 0; // no error
1751
#endif
1752
 
1753
  if( (seq_ui_remote_port == DEFAULT && seq_ui_remote_active_port != port) ||
1754
      (seq_ui_remote_port != DEFAULT && port != seq_ui_remote_port) )
1755
    return 0; // wrong port
1756
 
1757
  // for easier parsing: convert Note Off -> Note On with velocity 0
1758
  if( midi_package.event == NoteOff ) {
1759
    midi_package.event = NoteOn;
1760
    midi_package.velocity = 0;
1761
  }
1762
 
1763
  switch( midi_package.event ) {
1764
    case NoteOn: {
1765
      switch( midi_package.chn ) {
1766
        case Chn1:
1767
      SEQ_UI_Button_Handler(midi_package.note + 0x00, midi_package.velocity ? 0 : 1);
1768
      break;
1769
        case Chn2:
1770
      SEQ_UI_Button_Handler(midi_package.note + 0x80, midi_package.velocity ? 0 : 1);
1771
      break;
1772
        case Chn3:
1773
      SEQ_UI_BLM_Button_Handler(midi_package.note >> 5, midi_package.note & 0x1f, midi_package.velocity ? 0 : 1);
1774
      break;
1775
      }
1776
    } break;
1777
 
1778
    case CC: {
1779
      if( midi_package.cc_number >= 15 && midi_package.cc_number <= 31 )
1780
    SEQ_UI_Encoder_Handler(midi_package.cc_number-15, (int)midi_package.value - 0x40);
1781
    } break;
1782
  }
1783
 
632 tk 1784
  return 1; // MIDI event has been taken for remote function -> don't forward to router/MIDI event parser
626 tk 1785
}
1786
 
1787
 
1788
/////////////////////////////////////////////////////////////////////////////
741 tk 1789
// MIDI Remote Keyboard Function (called from SEQ_MIDI_IN)
1790
/////////////////////////////////////////////////////////////////////////////
742 tk 1791
s32 SEQ_UI_REMOTE_MIDI_Keyboard(u8 key, u8 depressed)
741 tk 1792
{
742 tk 1793
#if 0
1794
  MIOS32_MIDI_SendDebugMessage("SEQ_UI_REMOTE_MIDI_Keyboard(%d, %d)\n", key, depressed);
741 tk 1795
#endif
742 tk 1796
 
1797
  switch( key ) {
1798
    case 0x24: // C-2
1799
      return SEQ_UI_Button_GP(depressed, 0);
1800
    case 0x25: // C#2
1801
      return SEQ_UI_Button_Track(depressed, 0);
1802
    case 0x26: // D-2
1803
      return SEQ_UI_Button_GP(depressed, 1);
1804
    case 0x27: // D#2
1805
      return SEQ_UI_Button_Track(depressed, 1);
1806
    case 0x28: // E-2
1807
      return SEQ_UI_Button_GP(depressed, 2);
1808
    case 0x29: // F-2
1809
      return SEQ_UI_Button_GP(depressed, 3);
1810
    case 0x2a: // F#2
1811
      return SEQ_UI_Button_Track(depressed, 2);
1812
    case 0x2b: // G-2
1813
      return SEQ_UI_Button_GP(depressed, 4);
1814
    case 0x2c: // G#2
1815
      return SEQ_UI_Button_Track(depressed, 3);
1816
    case 0x2d: // A-2
1817
      return SEQ_UI_Button_GP(depressed, 5);
1818
    case 0x2e: // A#2
1819
      return SEQ_UI_Button_ParLayer(depressed, 0);
1820
    case 0x2f: // B-2
1821
      return SEQ_UI_Button_GP(depressed, 6);
1822
 
1823
    case 0x30: // C-3
1824
      return SEQ_UI_Button_GP(depressed, 7);
1825
    case 0x31: // C#3
1826
      return SEQ_UI_Button_ParLayer(depressed, 1);
1827
    case 0x32: // D-3
1828
      return SEQ_UI_Button_GP(depressed, 8);
1829
    case 0x33: // D#3
1830
      return SEQ_UI_Button_ParLayer(depressed, 2);
1831
    case 0x34: // E-3
1832
      return SEQ_UI_Button_GP(depressed, 9);
1833
    case 0x35: // F-3
1834
      return SEQ_UI_Button_GP(depressed, 10);
1835
    case 0x36: // F#3
1836
      return SEQ_UI_Button_TrgLayer(depressed, 0);
1837
    case 0x37: // G-3
1838
      return SEQ_UI_Button_GP(depressed, 11);
1839
    case 0x38: // G#3
1840
      return SEQ_UI_Button_TrgLayer(depressed, 1);
1841
    case 0x39: // A-3
1842
      return SEQ_UI_Button_GP(depressed, 12);
1843
    case 0x3a: // A#3
1844
      return SEQ_UI_Button_TrgLayer(depressed, 2);
1845
    case 0x3b: // B-3
1846
      return SEQ_UI_Button_GP(depressed, 13);
1847
 
1848
    case 0x3c: // C-4
1849
      return SEQ_UI_Button_GP(depressed, 14);
1850
    case 0x3d: // C#4
1851
      return SEQ_UI_Button_Group(depressed, 0);
1852
    case 0x3e: // D-4
1853
      return SEQ_UI_Button_GP(depressed, 15);
1854
    case 0x3f: // D#4
1855
      return SEQ_UI_Button_Group(depressed, 1);
1856
    case 0x40: // E-4
1857
      return 0; // ignore
1858
    case 0x41: // F-4
1859
      return SEQ_UI_Button_StepView(depressed);
1860
    case 0x42: // F#4
1861
      return SEQ_UI_Button_Group(depressed, 1);
1862
    case 0x43: // G-4
1863
      return 0; // ignore
1864
    case 0x44: // G#4
1865
      return SEQ_UI_Button_Group(depressed, 2);
1866
    case 0x45: // A-4
1867
      return SEQ_UI_Button_Left(depressed);
1868
    case 0x46: // A#4
1869
      return SEQ_UI_Button_ToggleGate(depressed);
1870
    case 0x47: // B-4
1871
      return SEQ_UI_Button_Right(depressed);
1872
 
1873
    case 0x48: // C-5
1874
      return SEQ_UI_Button_Edit(depressed);
1875
    case 0x49: // C#5
1876
      return SEQ_UI_Button_Solo(depressed);
1877
    case 0x4a: // D-5
1878
      return SEQ_UI_Button_Mute(depressed);
1879
    case 0x4b: // D#5
1880
      return SEQ_UI_Button_All(depressed);
1881
    case 0x4c: // E-5
1882
      return SEQ_UI_Button_Pattern(depressed);
1883
    case 0x4d: // F-5
1884
      return SEQ_UI_Button_Song(depressed);
1885
    case 0x4e: // F#5
1886
      return SEQ_UI_Button_Fast(depressed);
1887
    case 0x4f: // G-5
1888
      return SEQ_UI_Button_Metronome(depressed);
1889
    case 0x50: // G#5
1890
      return SEQ_UI_Button_ExtRestart(depressed);
1891
    case 0x51: // A-5
1892
      return SEQ_UI_Button_ParLayerSel(depressed);
1893
    case 0x52: // A#5
1894
      return SEQ_UI_Button_TrackSel(depressed);
1895
    case 0x53: // B-5
1896
      return SEQ_UI_Button_Stop(depressed);
1897
 
1898
    case 0x54: // C-6
1899
      return SEQ_UI_Button_Play(depressed);
1900
    case 0x55: // C#6
1901
      return SEQ_UI_Button_Pause(depressed);
1902
    case 0x56: // D-6
1903
      return SEQ_UI_Button_Rew(depressed);
1904
    case 0x57: // D#6
1905
      return SEQ_UI_Button_Fwd(depressed);
1906
    case 0x58: // E-6
1907
      return SEQ_UI_Button_Utility(depressed);
1908
    case 0x59: // F-6
1909
      return SEQ_UI_Button_TempoPreset(depressed);
1910
    case 0x5a: // F#6
1911
      return 0; // ignore
1912
    case 0x5b: // G-6
1913
      return SEQ_UI_Button_Menu(depressed);
1914
    case 0x5c: // G#6
1915
      return SEQ_UI_Button_Select(depressed);
1916
    case 0x5d: // A-6
1917
      return SEQ_UI_Button_Exit(depressed);
1918
    case 0x5e: // A#6
1919
      return SEQ_UI_Button_Down(depressed);
1920
    case 0x5f: // B-6
1921
      return SEQ_UI_Button_Up(depressed);
1922
  }
1923
 
741 tk 1924
  return 0; // no error
1925
}
1926
 
1927
 
1928
/////////////////////////////////////////////////////////////////////////////
134 tk 1929
// Update LCD messages
1930
// Usually called from background task
1931
/////////////////////////////////////////////////////////////////////////////
1932
s32 SEQ_UI_LCD_Handler(void)
1933
{
728 tk 1934
  static u8 boot_animation_wait_ctr = 0;
1935
  static u8 boot_animation_lcd_pos = 0;
1936
 
625 tk 1937
  // special handling in remote client mode
626 tk 1938
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 1939
    return SEQ_UI_LCD_Update();
1940
 
159 tk 1941
  if( seq_ui_display_init_req ) {
1942
    seq_ui_display_init_req = 0; // clear request
134 tk 1943
 
278 tk 1944
    // clear force update of LCD
1945
    SEQ_LCD_Clear();
1946
    SEQ_LCD_Update(1);
134 tk 1947
 
168 tk 1948
    // select first menu item
1949
    ui_selected_item = 0;
1950
 
167 tk 1951
    // call init function of current page
272 tk 1952
    if( ui_menu_pages[ui_page].init_callback != NULL )
1953
      ui_menu_pages[ui_page].init_callback(0); // mode
134 tk 1954
 
1955
    // request display update
159 tk 1956
    seq_ui_display_update_req = 1;
134 tk 1957
  }
1958
 
1044 tk 1959
  // print boot screen as long as hardware config hasn't been read
496 tk 1960
  if( !SEQ_FILE_HW_ConfigLocked() ) {
728 tk 1961
    if( boot_animation_lcd_pos < (40-3) ) {
1962
      if( ++boot_animation_wait_ctr >= 75 ) {
1963
    boot_animation_wait_ctr = 0;
637 tk 1964
 
728 tk 1965
    if( boot_animation_lcd_pos == 0 ) {
1966
      SEQ_LCD_Clear();
1967
      SEQ_LCD_CursorSet(0, 0);
1968
      SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE1 " " MIOS32_LCD_BOOT_MSG_LINE2);
1969
      SEQ_LCD_CursorSet(0, 1);
1970
      SEQ_LCD_PrintString("Searching for SD Card...");
1971
    }
1972
 
1973
    // logo is print on second LCD
1974
    SEQ_LCD_LOGO_Print(boot_animation_lcd_pos++);
1975
      }
1976
    }
740 tk 1977
  } else if( seq_ui_backup_req || seq_ui_format_req ) {
634 tk 1978
    SEQ_LCD_Clear();
1979
    SEQ_LCD_CursorSet(0, 0);
740 tk 1980
    //                     <-------------------------------------->
1981
    //                     0123456789012345678901234567890123456789
1982
    if( seq_ui_backup_req )
959 tk 1983
      SEQ_LCD_PrintString("Copy Files - be patient!!!");
740 tk 1984
    else if( seq_ui_format_req )
959 tk 1985
      SEQ_LCD_PrintString("Creating Files - be patient!!!");
740 tk 1986
    else
1987
      SEQ_LCD_PrintString("Don't know what I'm doing! :-/");
637 tk 1988
 
1989
    if( seq_file_backup_notification != NULL ) {
1990
      int i;
1991
 
1992
      SEQ_LCD_CursorSet(0, 1);
959 tk 1993
      SEQ_LCD_PrintFormattedString("Creating %s", seq_file_backup_notification);
637 tk 1994
 
1995
      SEQ_LCD_CursorSet(40+3, 0);
1996
      SEQ_LCD_PrintString("Total: [");
1997
      for(i=0; i<20; ++i)
1998
    SEQ_LCD_PrintChar((i>(seq_file_backup_percentage/5)) ? ' ' : '#');
1999
      SEQ_LCD_PrintFormattedString("] %3d%%", seq_file_backup_percentage);
2000
 
2001
      SEQ_LCD_CursorSet(40+3, 1);
2002
      SEQ_LCD_PrintString("File:  [");
2003
      for(i=0; i<20; ++i)
2004
    SEQ_LCD_PrintChar((i>(seq_file_copy_percentage/5)) ? ' ' : '#');
2005
      SEQ_LCD_PrintFormattedString("] %3d%%", seq_file_copy_percentage);
2006
    }
2007
 
496 tk 2008
  } else if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
2009
    SEQ_LCD_CursorSet(0, 0);
2010
    //                   <-------------------------------------->
2011
    //                   0123456789012345678901234567890123456789
306 tk 2012
    SEQ_LCD_PrintString("Menu Shortcuts:");
2013
    SEQ_LCD_PrintSpaces(25 + 40);
2014
    SEQ_LCD_CursorSet(0, 1);
2015
    SEQ_LCD_PrintString(UI_SHORTCUT_STR); // defined in seq_ui_pages.inc
2016
  } else {
2017
    // perform high priority LCD update request
2018
    if( ui_lcd_callback != NULL )
2019
      ui_lcd_callback(1); // high_prio
167 tk 2020
 
306 tk 2021
    // perform low priority LCD update request if requested
2022
    if( seq_ui_display_update_req ) {
2023
      seq_ui_display_update_req = 0; // clear request
328 tk 2024
 
2025
      // ensure that selections are matching with track constraints
2026
      SEQ_UI_CheckSelections();
2027
 
306 tk 2028
      if( ui_lcd_callback != NULL )
2029
    ui_lcd_callback(0); // no high_prio
2030
    }
134 tk 2031
  }
2032
 
353 tk 2033
  // transfer all changed characters to LCD
2034
  SEQ_UI_LCD_Update();
2035
 
2036
  return 0; // no error
2037
}
2038
 
2039
 
2040
/////////////////////////////////////////////////////////////////////////////
2041
// Called from SEQ_UI_LCD_Handler(), but optionally also from other tasks
2042
// to update the LCD screen immediately
2043
/////////////////////////////////////////////////////////////////////////////
1117 tk 2044
// for newer GCC versions it's important to declare constant arrays outside a function
2045
//                                             00112233
2046
static const char animation_l_arrows[2*4+1] = "   >>>> ";
2047
//                                             00112233
2048
static const char animation_r_arrows[2*4+1] = "  < << <";
2049
//                                               00112233
2050
static const char animation_l_brackets[2*4+1] = "   )))) ";
2051
//                                               00112233
2052
static const char animation_r_brackets[2*4+1] = "  ( (( (";
2053
//                                            00112233
2054
static const char animation_l_stars[2*4+1] = "   **** ";
2055
//                                            00112233
2056
static const char animation_r_stars[2*4+1] = "  * ** *";
353 tk 2057
s32 SEQ_UI_LCD_Update(void)
2058
{
625 tk 2059
  // special handling in remote client mode
626 tk 2060
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT ) {
2061
    MIOS32_IRQ_Disable();
2062
    u8 force = seq_ui_remote_force_lcd_update;
2063
    seq_ui_remote_force_lcd_update = 0;
2064
    MIOS32_IRQ_Enable();
2065
    return SEQ_LCD_Update(force);
625 tk 2066
  }
2067
 
596 tk 2068
  // if UI message active: copy over the text
2069
  if( ui_msg_ctr ) {
774 tk 2070
    char *animation_l_ptr;
2071
    char *animation_r_ptr;
596 tk 2072
    u8 msg_x = 0;
2073
    u8 right_aligned = 0;
740 tk 2074
    u8 disable_message = 0;
299 tk 2075
 
596 tk 2076
    switch( ui_msg_type ) {
2077
      case SEQ_UI_MSG_SDCARD: {
1117 tk 2078
    animation_l_ptr = (char *)animation_l_arrows;
2079
    animation_r_ptr = (char *)animation_r_arrows;
596 tk 2080
    msg_x = 0; // MEMO: print such important information at first LCD for the case the user hasn't connected the second LCD yet
2081
    right_aligned = 0;
2082
      } break;
2083
 
756 tk 2084
      case SEQ_UI_MSG_DELAYED_ACTION:
2085
      case SEQ_UI_MSG_DELAYED_ACTION_R: {
1117 tk 2086
    animation_l_ptr = (char *)animation_l_brackets;
2087
    animation_r_ptr = (char *)animation_r_brackets;
756 tk 2088
    if( ui_msg_type == SEQ_UI_MSG_DELAYED_ACTION_R ) {
2089
      msg_x = 40; // right LCD
2090
      right_aligned = 0;
2091
    } else {
2092
      msg_x = 39; // left LCD
2093
      right_aligned = 1;
2094
    }
740 tk 2095
 
2096
    if( ui_delayed_action_callback == NULL ) {
2097
      disable_message = 1; // button has been depressed before delay
2098
    } else {
2099
      int seconds = (ui_delayed_action_ctr / 1000) + 1;
2100
      if( seconds == 1 )
2101
        sprintf(ui_msg[0], "Hold for 1 second ");
2102
      else
2103
        sprintf(ui_msg[0], "Hold for %d seconds", seconds);
2104
    }
2105
      } break;
2106
 
741 tk 2107
      case SEQ_UI_MSG_USER_R: {
1117 tk 2108
    animation_l_ptr = (char *)animation_l_stars;
2109
    animation_r_ptr = (char *)animation_r_stars;
741 tk 2110
    msg_x = 40; // right display
2111
    right_aligned = 0;
2112
      } break;
2113
 
596 tk 2114
      default: {
1117 tk 2115
    animation_l_ptr = (char *)animation_l_stars;
2116
    animation_r_ptr = (char *)animation_r_stars;
596 tk 2117
    msg_x = 39;
2118
    right_aligned = 1;
2119
      } break;
2120
 
2121
    }
2122
 
740 tk 2123
    if( !disable_message ) {
2124
      int anum = (ui_msg_ctr % 1000) / 250;
596 tk 2125
 
740 tk 2126
      int len[2];
2127
      len[0] = strlen((char *)ui_msg[0]);
2128
      len[1] = strlen((char *)ui_msg[1]);
2129
      int len_max = len[0];
2130
      if( len[1] > len_max )
2131
    len_max = len[1];
596 tk 2132
 
740 tk 2133
      if( right_aligned )
2134
    msg_x -= (9 + len_max);
596 tk 2135
 
740 tk 2136
      int line;
2137
      for(line=0; line<2; ++line) {
2138
    SEQ_LCD_CursorSet(msg_x, line);
596 tk 2139
 
740 tk 2140
    // ensure that both lines are padded with same number of spaces
2141
    int end_pos = len[line];
2142
    while( end_pos < len_max )
2143
      ui_msg[line][end_pos++] = ' ';
2144
    ui_msg[line][end_pos] = 0;
2145
 
2146
    SEQ_LCD_PrintFormattedString(" %c%c| %s |%c%c ",
2147
                     *(animation_l_ptr + 2*anum + 0), *(animation_l_ptr + 2*anum + 1),
2148
                     (char *)ui_msg[line],
2149
                     *(animation_r_ptr + 2*anum + 0), *(animation_r_ptr + 2*anum + 1));
2150
      }
299 tk 2151
    }
2152
  }
2153
 
637 tk 2154
  // MSD USB notification at right corner if not in Disk page
2155
  // to warn user that USB MIDI is disabled and seq performance is bad now!
638 tk 2156
  if( (TASK_MSD_EnableGet() > 0) && ui_page != SEQ_UI_PAGE_DISK ) {
637 tk 2157
    SEQ_LCD_CursorSet(80-11, 0);
2158
    if( ui_cursor_flash ) SEQ_LCD_PrintSpaces(13); else SEQ_LCD_PrintString(" [MSD USB] ");
2159
    SEQ_LCD_CursorSet(80-11, 1);
2160
    char str[5];
2161
    TASK_MSD_FlagStrGet(str);
2162
    if( ui_cursor_flash ) SEQ_LCD_PrintSpaces(13); else SEQ_LCD_PrintFormattedString(" [ %s  ] ", str);
2163
  }
596 tk 2164
 
278 tk 2165
  // transfer all changed characters to LCD
353 tk 2166
  // SEQ_LCD_Update provides a MUTEX handling to allow updates from different tasks
2167
  return SEQ_LCD_Update(0);
134 tk 2168
}
2169
 
2170
 
2171
/////////////////////////////////////////////////////////////////////////////
2172
// Update all LEDs
2173
// Usually called from background task
2174
/////////////////////////////////////////////////////////////////////////////
2175
s32 SEQ_UI_LED_Handler(void)
2176
{
626 tk 2177
  static u8 remote_led_sr[SEQ_LED_NUM_SR];
2178
 
625 tk 2179
  // ignore in remote client mode
626 tk 2180
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 2181
    return 0; // no error
2182
 
1044 tk 2183
  // ignore as long as hardware config hasn't been read
496 tk 2184
  if( !SEQ_FILE_HW_ConfigLocked() )
2185
    return -1;
2186
 
134 tk 2187
  // track LEDs
987 tk 2188
  // in pattern page: track buttons are used as group buttons
2189
  if( ui_page == SEQ_UI_PAGE_PATTERN ) {
2190
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (ui_selected_group == 0));
2191
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (ui_selected_group == 1));
2192
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (ui_selected_group == 2));
2193
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (ui_selected_group == 3));
2194
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
2195
    // in song page: track and group buttons are used to select the cursor position
2196
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (ui_selected_item == 3));
2197
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (ui_selected_item == 4));
2198
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (ui_selected_item == 5));
2199
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (ui_selected_item == 6));
2200
  } else {
2201
    u8 selected_tracks = ui_selected_tracks >> (4*ui_selected_group);
2202
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (selected_tracks & (1 << 0)));
2203
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (selected_tracks & (1 << 1)));
2204
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (selected_tracks & (1 << 2)));
2205
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (selected_tracks & (1 << 3)));
2206
  }
2207
 
678 tk 2208
  SEQ_LED_PinSet(seq_hwcfg_led.track_sel, ui_page == SEQ_UI_PAGE_TRACKSEL);
134 tk 2209
 
2210
  // parameter layer LEDs
987 tk 2211
  // in song page: layer buttons are used to select the cursor position
2212
  if( ui_page == SEQ_UI_PAGE_SONG ) {
2213
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], ui_selected_item == 0);
2214
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], ui_selected_item == 1);
2215
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], ui_selected_item == 2);
2216
  } else {
2217
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], (ui_selected_par_layer == 0));
2218
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], (ui_selected_par_layer == 1));
2219
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], (ui_selected_par_layer >= 2) || seq_ui_button_state.PAR_LAYER_SEL);
2220
  }
678 tk 2221
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer_sel, ui_page == SEQ_UI_PAGE_PARSEL);
134 tk 2222
 
2223
  // group LEDs
987 tk 2224
  // in song page: track and group buttons are used to select the cursor position
2225
  if( ui_page == SEQ_UI_PAGE_SONG ) {
2226
    SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_item == 3));
2227
    SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_item == 4));
2228
    SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_item == 5));
2229
    SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_item == 6));
2230
  } else {
2231
    SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_group == 0));
2232
    SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_group == 1));
2233
    SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_group == 2));
2234
    SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_group == 3));
2235
  }
134 tk 2236
 
2237
  // trigger layer LEDs
492 tk 2238
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[0], (ui_selected_trg_layer == 0));
2239
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[1], (ui_selected_trg_layer == 1));
2240
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[2], (ui_selected_trg_layer >= 2) || seq_ui_button_state.TRG_LAYER_SEL);
678 tk 2241
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer_sel, ui_page == SEQ_UI_PAGE_TRGSEL);
134 tk 2242
 
2243
  // remaining LEDs
492 tk 2244
  SEQ_LED_PinSet(seq_hwcfg_led.edit, ui_page == SEQ_UI_PAGE_EDIT);
2245
  SEQ_LED_PinSet(seq_hwcfg_led.mute, ui_page == SEQ_UI_PAGE_MUTE);
2246
  SEQ_LED_PinSet(seq_hwcfg_led.pattern, ui_page == SEQ_UI_PAGE_PATTERN);
399 tk 2247
  if( SEQ_SONG_ActiveGet() )
492 tk 2248
    SEQ_LED_PinSet(seq_hwcfg_led.song, 1);
399 tk 2249
  else
492 tk 2250
    SEQ_LED_PinSet(seq_hwcfg_led.song, ui_cursor_flash ? 0 : (ui_page == SEQ_UI_PAGE_SONG));
743 tk 2251
  SEQ_LED_PinSet(seq_hwcfg_led.mixer, ui_page == SEQ_UI_PAGE_MIXER);
1119 tk 2252
 
2253
  SEQ_LED_PinSet(seq_hwcfg_led.track_mode, ui_page == SEQ_UI_PAGE_TRKMODE);
2254
  SEQ_LED_PinSet(seq_hwcfg_led.track_groove, ui_page == SEQ_UI_PAGE_TRKGRV);
2255
  SEQ_LED_PinSet(seq_hwcfg_led.track_length, ui_page == SEQ_UI_PAGE_TRKLEN);
2256
  SEQ_LED_PinSet(seq_hwcfg_led.track_direction, ui_page == SEQ_UI_PAGE_TRKDIR);
2257
  SEQ_LED_PinSet(seq_hwcfg_led.track_morph, ui_page == SEQ_UI_PAGE_TRKMORPH);
2258
  SEQ_LED_PinSet(seq_hwcfg_led.track_transpose, ui_page == SEQ_UI_PAGE_TRKTRAN);
134 tk 2259
 
492 tk 2260
  SEQ_LED_PinSet(seq_hwcfg_led.solo, seq_ui_button_state.SOLO);
2261
  SEQ_LED_PinSet(seq_hwcfg_led.fast, seq_ui_button_state.FAST_ENCODERS);
1121 tk 2262
  SEQ_LED_PinSet(seq_hwcfg_led.fast2, seq_ui_button_state.FAST2_ENCODERS);
492 tk 2263
  SEQ_LED_PinSet(seq_hwcfg_led.all, seq_ui_button_state.CHANGE_ALL_STEPS);
134 tk 2264
 
492 tk 2265
  SEQ_LED_PinSet(seq_hwcfg_led.play, SEQ_BPM_IsRunning());
2266
  SEQ_LED_PinSet(seq_hwcfg_led.stop, !SEQ_BPM_IsRunning() && !ui_seq_pause);
2267
  SEQ_LED_PinSet(seq_hwcfg_led.pause, ui_seq_pause);
240 tk 2268
 
492 tk 2269
  SEQ_LED_PinSet(seq_hwcfg_led.rew, seq_ui_button_state.REW);
2270
  SEQ_LED_PinSet(seq_hwcfg_led.fwd, seq_ui_button_state.FWD);
596 tk 2271
 
2272
  SEQ_LED_PinSet(seq_hwcfg_led.loop, seq_core_state.LOOP);
951 tk 2273
  SEQ_LED_PinSet(seq_hwcfg_led.follow, seq_core_state.FOLLOW);
134 tk 2274
 
678 tk 2275
  SEQ_LED_PinSet(seq_hwcfg_led.step_view, ui_page == SEQ_UI_PAGE_STEPSEL);
134 tk 2276
 
591 tk 2277
  SEQ_LED_PinSet(seq_hwcfg_led.select, seq_ui_button_state.SELECT_PRESSED);
492 tk 2278
  SEQ_LED_PinSet(seq_hwcfg_led.menu, seq_ui_button_state.MENU_PRESSED);
1203 tk 2279
  SEQ_LED_PinSet(seq_hwcfg_led.bookmark, ui_page == SEQ_UI_PAGE_BOOKMARKS);
134 tk 2280
 
596 tk 2281
  // handle double functions
2282
  if( seq_ui_button_state.MENU_PRESSED ) {
2283
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_core_state.LOOP);
951 tk 2284
    SEQ_LED_PinSet(seq_hwcfg_led.exit, seq_core_state.FOLLOW);
596 tk 2285
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.EXT_RESTART_REQ);
2286
  } else {
2287
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_ui_button_state.SCRUB);
951 tk 2288
    SEQ_LED_PinSet(seq_hwcfg_led.exit, ui_page == SEQ_UI_PAGE_MENU);
596 tk 2289
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.METRONOME);
2290
  }
2291
 
630 tk 2292
  SEQ_LED_PinSet(seq_hwcfg_led.record, ui_page == SEQ_UI_PAGE_TRKREC);
2293
 
492 tk 2294
  SEQ_LED_PinSet(seq_hwcfg_led.utility, ui_page == SEQ_UI_PAGE_UTIL);
2295
  SEQ_LED_PinSet(seq_hwcfg_led.copy, seq_ui_button_state.COPY);
2296
  SEQ_LED_PinSet(seq_hwcfg_led.paste, seq_ui_button_state.PASTE);
1014 tk 2297
  SEQ_LED_PinSet(seq_hwcfg_led.undo, seq_ui_button_state.UNDO);
492 tk 2298
  SEQ_LED_PinSet(seq_hwcfg_led.clear, seq_ui_button_state.CLEAR);
240 tk 2299
 
513 tk 2300
  SEQ_LED_PinSet(seq_hwcfg_led.tap_tempo, seq_ui_button_state.TAP_TEMPO);
678 tk 2301
  SEQ_LED_PinSet(seq_hwcfg_led.tempo_preset, ui_page == SEQ_UI_PAGE_BPM_PRESETS);
524 tk 2302
  SEQ_LED_PinSet(seq_hwcfg_led.ext_restart, seq_core_state.EXT_RESTART_REQ);
240 tk 2303
 
492 tk 2304
  SEQ_LED_PinSet(seq_hwcfg_led.down, seq_ui_button_state.DOWN);
2305
  SEQ_LED_PinSet(seq_hwcfg_led.up, seq_ui_button_state.UP);
240 tk 2306
 
167 tk 2307
 
1044 tk 2308
  // in MENU page: overrule GP LEDs as long as MENU button is pressed/active
306 tk 2309
  if( seq_ui_button_state.MENU_PRESSED ) {
2310
    if( ui_cursor_flash ) // if flashing flag active: no LED flag set
2311
      ui_gp_leds = 0x0000;
2312
    else {
2313
      int i;
2314
      u16 new_ui_gp_leds = 0x0000;
2315
      for(i=0; i<16; ++i)
2316
    if( ui_page == ui_shortcut_menu_pages[i] )
2317
      new_ui_gp_leds |= (1 << i);
2318
      ui_gp_leds = new_ui_gp_leds;
2319
    }
2320
  } else {
2321
    // note: the background function is permanently interrupted - therefore we write the GP pattern
2322
    // into a temporary variable, and take it over once completed
2323
    u16 new_ui_gp_leds = 0x0000;
2324
    // request GP LED values from current menu page
2325
    // will be transfered to DOUT registers in SEQ_UI_LED_Handler_Periodic
2326
    new_ui_gp_leds = 0x0000;
206 tk 2327
 
306 tk 2328
    if( ui_led_callback != NULL )
2329
      ui_led_callback(&new_ui_gp_leds);
167 tk 2330
 
306 tk 2331
    ui_gp_leds = new_ui_gp_leds;
2332
  }
2333
 
1020 tk 2334
  // update BLM LEDs
2335
  SEQ_BLM_LED_Update();
524 tk 2336
 
626 tk 2337
  // send LED changes in remote server mode
2338
  if( seq_ui_remote_mode == SEQ_UI_REMOTE_MODE_SERVER || seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_SERVER ) {
2339
    int first_sr = -1;
2340
    int last_sr = -1;
2341
    int sr;
2342
    for(sr=0; sr<SEQ_LED_NUM_SR; ++sr) {
2343
      u8 value = SEQ_LED_SRGet(sr);
2344
      if( value != remote_led_sr[sr] ) {
2345
    if( first_sr == -1 )
2346
      first_sr = sr;
2347
    last_sr = sr;
2348
    remote_led_sr[sr] = value;
2349
      }
2350
    }
2351
 
2352
    MIOS32_IRQ_Disable();
2353
    if( seq_ui_remote_force_led_update ) {
2354
      first_sr = 0;
2355
      last_sr = SEQ_LED_NUM_SR-1;
2356
    }
2357
    seq_ui_remote_force_led_update = 0;
2358
    MIOS32_IRQ_Enable();
2359
 
2360
    if( first_sr >= 0 )
2361
      SEQ_MIDI_SYSEX_REMOTE_Server_SendLED(first_sr, (u8 *)&remote_led_sr[first_sr], last_sr-first_sr+1);
2362
  }
2363
 
2364
 
134 tk 2365
  return 0; // no error
2366
}
2367
 
2368
 
2369
/////////////////////////////////////////////////////////////////////////////
2370
// updates high-prio LED functions (GP LEDs and Beat LED)
168 tk 2371
// called each mS
134 tk 2372
/////////////////////////////////////////////////////////////////////////////
2373
s32 SEQ_UI_LED_Handler_Periodic()
2374
{
625 tk 2375
  // ignore in remote client mode
626 tk 2376
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 2377
    return 0; // no error
2378
 
1044 tk 2379
  // ignore as long as hardware config hasn't been read
496 tk 2380
  if( !SEQ_FILE_HW_ConfigLocked() )
2381
    return -1;
2382
 
752 tk 2383
  // GP LEDs are updated when ui_gp_leds has changed
134 tk 2384
  static u16 prev_ui_gp_leds = 0x0000;
2385
 
755 tk 2386
  // beat LED
193 tk 2387
  u8 sequencer_running = SEQ_BPM_IsRunning();
1068 tk 2388
  u8 beat_led_on = sequencer_running && ((seq_core_state.ref_step & 3) == 0);
2389
  SEQ_LED_PinSet(seq_hwcfg_led.beat, beat_led_on);
134 tk 2390
 
1068 tk 2391
  // mirror to status LED (inverted, so that LED is normaly on)
2392
  MIOS32_BOARD_LED_Set(0xffffffff, beat_led_on ? 0 : 1);
755 tk 2393
 
1068 tk 2394
 
755 tk 2395
  // don't continue if no new step has been generated and GP LEDs haven't changed
1044 tk 2396
  if( !seq_core_step_update_req && prev_ui_gp_leds == ui_gp_leds && sequencer_running ) // sequencer running check: workaround - as long as sequencer not running, we won't get an step update request!
755 tk 2397
    return 0;
2398
  seq_core_step_update_req = 0; // requested from SEQ_CORE if any step has been changed
2399
  prev_ui_gp_leds = ui_gp_leds; // take over new GP pattern
2400
 
134 tk 2401
  // for song position marker (supports 16 LEDs, check for selected step view)
2402
  u16 pos_marker_mask = 0x0000;
325 tk 2403
  u8 visible_track = SEQ_UI_VisibleTrackGet();
2404
  u8 played_step = seq_core_trk[visible_track].step;
754 tk 2405
 
513 tk 2406
  if( seq_ui_button_state.STEP_VIEW ) {
2407
    // if STEP_VIEW button pressed: pos marker correlated to zoom ratio
325 tk 2408
    if( sequencer_running )
2409
      pos_marker_mask = 1 << (played_step / (SEQ_TRG_NumStepsGet(visible_track)/16));
2410
  } else {
2411
    if( sequencer_running && (played_step >> 4) == ui_selected_step_view )
2412
      pos_marker_mask = 1 << (played_step & 0xf);
2413
  }
134 tk 2414
 
752 tk 2415
 
2416
  // follow step position if enabled
951 tk 2417
  if( seq_core_state.FOLLOW ) {
752 tk 2418
    u8 trk_step = seq_core_trk[visible_track].step;
2419
    if( (trk_step & 0xf0) != (16*ui_selected_step_view) ) {
2420
      ui_selected_step_view = trk_step / 16;
2421
      ui_selected_step = (ui_selected_step % 16) + 16*ui_selected_step_view;
2422
      seq_ui_display_update_req = 1;
2423
    }
2424
  }
134 tk 2425
 
2426
  // transfer to GP LEDs
514 tk 2427
  if( seq_hwcfg_led.gp_dout_l_sr ) {
2428
    if( seq_hwcfg_led.gp_dout_l2_sr )
2429
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_l_sr-1, (ui_gp_leds >> 0) & 0xff);
496 tk 2430
    else
514 tk 2431
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_l_sr-1, ((ui_gp_leds ^ pos_marker_mask) >> 0) & 0xff);
496 tk 2432
  }
134 tk 2433
 
514 tk 2434
  if( seq_hwcfg_led.gp_dout_r_sr ) {
2435
    if( seq_hwcfg_led.gp_dout_r2_sr )
2436
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_r_sr-1, (ui_gp_leds >> 8) & 0xff);
496 tk 2437
    else
514 tk 2438
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_r_sr-1, ((ui_gp_leds ^ pos_marker_mask) >> 8) & 0xff);
496 tk 2439
  }
134 tk 2440
 
514 tk 2441
  if( seq_hwcfg_led.gp_dout_l2_sr )
2442
    SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_l2_sr-1, (pos_marker_mask >> 0) & 0xff);
2443
  if( seq_hwcfg_led.gp_dout_r2_sr )
2444
    SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_r2_sr-1, (pos_marker_mask >> 8) & 0xff);
496 tk 2445
 
1146 tk 2446
  // transfer to optional track LEDs
2447
  if( seq_hwcfg_led.tracks_dout_l_sr )
2448
    SEQ_LED_SRSet(seq_hwcfg_led.tracks_dout_l_sr-1, (ui_selected_tracks >> 0) & 0xff);
2449
  if( seq_hwcfg_led.tracks_dout_r_sr )
2450
    SEQ_LED_SRSet(seq_hwcfg_led.tracks_dout_r_sr-1, (ui_selected_tracks >> 8) & 0xff);
524 tk 2451
 
2452
  if( seq_hwcfg_blm.enabled ) {
2453
    // Red LEDs (position marker)
2454
    int track_ix;
784 tk 2455
    for(track_ix=0; track_ix<4; ++track_ix) {
2456
      u8 track = 4*ui_selected_group + track_ix;
1020 tk 2457
 
2458
      // determine position marker
524 tk 2459
      u16 pos_marker_mask = 0x0000;
2460
      if( sequencer_running ) {
2461
    u8 played_step = seq_core_trk[track].step;
2462
    if( (played_step >> 4) == ui_selected_step_view )
2463
      pos_marker_mask = 1 << (played_step & 0xf);
2464
      }
2465
 
2466
      // Prepare Green LEDs (triggers)
1020 tk 2467
      // re-used from BLM_SCALAR code
2468
      u16 green_pattern = SEQ_BLM_PatternGreenGet(track);
524 tk 2469
 
2470
      // Red LEDs (position marker)
2471
      if( seq_hwcfg_blm.dout_duocolour ) {
1020 tk 2472
    BLM_DOUT_SRSet(1, 2*track_ix+0, pos_marker_mask);
2473
    BLM_DOUT_SRSet(1, 2*track_ix+1, pos_marker_mask >> 8);
524 tk 2474
 
2475
    if( seq_hwcfg_blm.dout_duocolour == 2 ) {
2476
      // Colour Mode 2: clear green LED, so that only one LED is lit
1020 tk 2477
      green_pattern &= ~pos_marker_mask;
524 tk 2478
    }
2479
      } else {
2480
    // If Duo-LEDs not enabled: invert Green LEDs
1040 tk 2481
    green_pattern ^= pos_marker_mask;
524 tk 2482
      }
2483
 
2484
      // Set Green LEDs
1020 tk 2485
      BLM_DOUT_SRSet(0, 2*track_ix+0, green_pattern);
2486
      BLM_DOUT_SRSet(0, 2*track_ix+1, green_pattern >> 8);
524 tk 2487
    }
2488
  }
2489
 
2490
 
514 tk 2491
  if( seq_hwcfg_blm8x8.enabled && seq_hwcfg_blm8x8.dout_gp_mapping ) {
513 tk 2492
    // for wilba's frontpanel
134 tk 2493
 
513 tk 2494
    // BLM_X DOUT -> GP LED mapping
2495
    // 0 = 15,16    1 = 13,14   2 = 11,12   3 = 9,10
2496
    // 4 = 1,2  5 = 3,4     6 = 5,6     7 = 7,8
134 tk 2497
 
513 tk 2498
    // bit 7: first green (i.e. GP1-G)
2499
    // bit 6: first red (i.e. GP1-R)
2500
    // bit 5: second green (i.e. GP2-G)
2501
    // bit 4: second red (i.e. GP2-R)
134 tk 2502
 
513 tk 2503
    // this mapping routine takes ca. 5 uS
2504
    // since it's only executed when ui_gp_leds or gp_mask has changed, it doesn't really hurt
134 tk 2505
 
513 tk 2506
    u16 modified_gp_leds = ui_gp_leds;
134 tk 2507
#if 1
513 tk 2508
    // extra: red LED is lit exclusively for higher contrast
2509
    modified_gp_leds &= ~pos_marker_mask;
134 tk 2510
#endif
2511
 
513 tk 2512
    int sr;
2513
    const u8 blm_x_sr_map[8] = {4, 5, 6, 7, 3, 2, 1, 0};
2514
    u16 gp_mask = 1 << 0;
2515
    for(sr=0; sr<8; ++sr) {
2516
      u8 pattern = 0;
134 tk 2517
 
513 tk 2518
      if( modified_gp_leds & gp_mask )
2519
    pattern |= 0x80;
2520
      if( pos_marker_mask & gp_mask )
2521
    pattern |= 0x40;
2522
      gp_mask <<= 1;
2523
      if( modified_gp_leds & gp_mask )
2524
    pattern |= 0x20;
2525
      if( pos_marker_mask & gp_mask )
2526
    pattern |= 0x10;
2527
      gp_mask <<= 1;
134 tk 2528
 
513 tk 2529
      u8 mapped_sr = blm_x_sr_map[sr];
2530
      BLM_X_LED_rows[mapped_sr][0] = (BLM_X_LED_rows[mapped_sr][0] & 0x0f) | pattern;
2531
    }
134 tk 2532
  }
2533
 
184 tk 2534
  return 0; // no error
134 tk 2535
}
2536
 
2537
 
2538
/////////////////////////////////////////////////////////////////////////////
168 tk 2539
// for menu handling (e.g. flashing cursor, doubleclick counter, etc...)
2540
// called each mS
2541
/////////////////////////////////////////////////////////////////////////////
2542
s32 SEQ_UI_MENU_Handler_Periodic()
2543
{
625 tk 2544
  // ignore in remote client mode
626 tk 2545
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 2546
    return 0; // no error
2547
 
740 tk 2548
  if( ++ui_cursor_flash_ctr >= SEQ_UI_CURSOR_FLASH_CTR_MAX ) {
168 tk 2549
    ui_cursor_flash_ctr = 0;
740 tk 2550
    ++ui_cursor_flash_overrun_ctr;
2551
    seq_ui_display_update_req = 1;
2552
  }
2553
 
173 tk 2554
  // important: flash flag has to be recalculated on each invocation of this
2555
  // handler, since counter could also be reseted outside this function
652 tk 2556
  u8 old_ui_cursor_flash = ui_cursor_flash;
173 tk 2557
  ui_cursor_flash = ui_cursor_flash_ctr >= SEQ_UI_CURSOR_FLASH_CTR_LED_OFF;
652 tk 2558
  if( old_ui_cursor_flash != ui_cursor_flash )
2559
    seq_ui_display_update_req = 1;
168 tk 2560
 
240 tk 2561
  // used in some pages for temporary messages
416 tk 2562
  if( ui_hold_msg_ctr ) {
240 tk 2563
    --ui_hold_msg_ctr;
2564
 
416 tk 2565
    if( !ui_hold_msg_ctr )
2566
      seq_ui_display_update_req = 1;
2567
  }
2568
 
596 tk 2569
  // used for temporary messages
2570
  if( ui_msg_ctr )
2571
    --ui_msg_ctr;
299 tk 2572
 
184 tk 2573
  // VU meters (used in MUTE menu, could also be available as LED matrix...)
2574
  static u8 vu_meter_prediv = 0; // predivider for VU meters
2575
 
2576
  if( ++vu_meter_prediv >= 4 ) {
2577
    vu_meter_prediv = 0;
2578
 
333 tk 2579
 
2580
    portENTER_CRITICAL();
2581
 
184 tk 2582
    u8 track;
2583
    seq_core_trk_t *t = &seq_core_trk[0];
2584
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++t, ++track)
2585
      if( t->vu_meter )
2586
    --t->vu_meter;
333 tk 2587
 
2588
    int i;
2589
    u8 *vu_meter = (u8 *)&seq_layer_vu_meter[0];
2590
    for(i=0; i<sizeof(seq_layer_vu_meter); ++i, ++vu_meter) {
2591
      if( *vu_meter && !(*vu_meter & 0x80) ) // if bit 7 set: static value
2592
    *vu_meter -= 1;
2593
    }
2594
 
318 tk 2595
    portEXIT_CRITICAL();
184 tk 2596
  }
2597
 
740 tk 2598
  // delayed action will be triggered once counter reached 0
2599
  if( !ui_delayed_action_callback )
2600
    ui_delayed_action_ctr = 0;
2601
  else if( ui_delayed_action_ctr ) {
2602
    if( --ui_delayed_action_ctr == 0 ) {
752 tk 2603
      // must be atomic
2604
      MIOS32_IRQ_Disable();
2605
      s32 (*_ui_delayed_action_callback)(u32 parameter);
2606
      _ui_delayed_action_callback = ui_delayed_action_callback;
2607
      u32 parameter = ui_delayed_action_parameter;
740 tk 2608
      ui_delayed_action_callback = NULL;
752 tk 2609
      MIOS32_IRQ_Enable();
2610
      _ui_delayed_action_callback(parameter); // note: it's allowed that the delayed action generates a new delayed action
740 tk 2611
    }
2612
  }
2613
 
168 tk 2614
  return 0;
2615
}
2616
 
2617
 
2618
/////////////////////////////////////////////////////////////////////////////
328 tk 2619
// Should be regulary called to check if the layer/instrument/step selection
2620
// is valid for the current track
2621
// At least executed before button/encoder and LCD function calls
2622
/////////////////////////////////////////////////////////////////////////////
2623
s32 SEQ_UI_CheckSelections(void)
2624
{
492 tk 2625
  if( (ui_selected_tracks >> (4*ui_selected_group)) == 0 )
2626
    ui_selected_tracks = 1 << (4*ui_selected_group);
2627
 
328 tk 2628
  u8 visible_track = SEQ_UI_VisibleTrackGet();
2629
 
2630
  if( ui_selected_instrument >= SEQ_PAR_NumInstrumentsGet(visible_track) )
2631
    ui_selected_instrument =