Subversion Repositories svn.mios32

Rev

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