Subversion Repositories svn.mios32

Rev

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