Subversion Repositories svn.mios32

Rev

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