Subversion Repositories svn.mios32

Rev

Rev 1341 | Rev 1350 | 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 1349 2011-11-04 21:27:56Z 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
 
134 tk 1101
  if( depressed ) return -1; // ignore when button depressed
1102
 
167 tk 1103
  // change to edit page
1104
  SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
1105
 
178 tk 1106
  // set/clear encoder fast function if required
1107
  SEQ_UI_InitEncSpeed(1); // auto config
1108
 
134 tk 1109
  return 0; // no error
1110
}
1111
 
1112
static s32 SEQ_UI_Button_Mute(s32 depressed)
1113
{
591 tk 1114
  seq_ui_button_state.MUTE_PRESSED = depressed ? 0 : 1;
1115
 
134 tk 1116
  if( depressed ) return -1; // ignore when button depressed
1117
 
184 tk 1118
  SEQ_UI_PageSet(SEQ_UI_PAGE_MUTE);
1119
 
134 tk 1120
  return 0; // no error
1121
}
1122
 
1123
static s32 SEQ_UI_Button_Pattern(s32 depressed)
1124
{
591 tk 1125
  seq_ui_button_state.PATTERN_PRESSED = depressed ? 0 : 1;
1126
 
134 tk 1127
  if( depressed ) return -1; // ignore when button depressed
1128
 
184 tk 1129
  SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN);
1130
 
134 tk 1131
  return 0; // no error
1132
}
1133
 
1134
static s32 SEQ_UI_Button_Song(s32 depressed)
1135
{
591 tk 1136
  seq_ui_button_state.SONG_PRESSED = depressed ? 0 : 1;
1137
 
134 tk 1138
  if( depressed ) return -1; // ignore when button depressed
1139
 
399 tk 1140
  SEQ_UI_PageSet(SEQ_UI_PAGE_SONG);
1141
 
134 tk 1142
  return 0; // no error
1143
}
1144
 
1145
static s32 SEQ_UI_Button_Solo(s32 depressed)
1146
{
513 tk 1147
  if( seq_hwcfg_button_beh.solo ) {
1148
    // toggle mode
1149
    if( depressed ) return -1; // ignore when button depressed
1150
    seq_ui_button_state.SOLO ^= 1;
1151
  } else {
1152
    // set mode
1153
    seq_ui_button_state.SOLO = depressed ? 0 : 1;
1154
  }
134 tk 1155
 
1156
  return 0; // no error
1157
}
1158
 
1159
static s32 SEQ_UI_Button_Fast(s32 depressed)
1160
{
513 tk 1161
  if( seq_hwcfg_button_beh.fast ) {
1162
    // toggle mode
1163
    if( depressed ) return -1; // ignore when button depressed
1164
    seq_ui_button_state.FAST_ENCODERS ^= 1;
1165
  } else {
1166
    // set mode
1167
    seq_ui_button_state.FAST_ENCODERS = depressed ? 0 : 1;
1168
  }
134 tk 1169
 
178 tk 1170
  SEQ_UI_InitEncSpeed(0); // no auto config
1171
 
134 tk 1172
  return 0; // no error
1173
}
1174
 
1121 tk 1175
static s32 SEQ_UI_Button_Fast2(s32 depressed)
1176
{
1177
  if( seq_hwcfg_button_beh.fast2 ) {
1178
    // toggle mode
1179
    if( depressed ) return -1; // ignore when button depressed
1180
    seq_ui_button_state.FAST2_ENCODERS ^= 1;
1181
  } else {
1182
    // set mode
1183
    seq_ui_button_state.FAST2_ENCODERS = depressed ? 0 : 1;
1184
  }
1185
 
1186
  SEQ_UI_InitEncSpeed(0); // no auto config
1187
 
1188
  return 0; // no error
1189
}
1190
 
134 tk 1191
static s32 SEQ_UI_Button_All(s32 depressed)
1192
{
178 tk 1193
  seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE = depressed ? 0 : 1;
134 tk 1194
 
513 tk 1195
  if( seq_hwcfg_button_beh.all ) {
1196
    // toggle mode
1197
    if( depressed ) return -1;
1198
    seq_ui_button_state.CHANGE_ALL_STEPS ^= 1;
1199
  } else {
1200
    // set mode
1201
    seq_ui_button_state.CHANGE_ALL_STEPS = depressed ? 0 : 1;
1202
  }
178 tk 1203
 
134 tk 1204
  return 0; // no error
1205
}
1206
 
1207
static s32 SEQ_UI_Button_StepView(s32 depressed)
1208
{
600 tk 1209
  //  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1210
  // also used by seq_ui_stepsel
1211
 
513 tk 1212
  if( seq_hwcfg_button_beh.step_view ) {
1213
    if( depressed ) return -1; // ignore when button depressed
678 tk 1214
    if( !seq_ui_button_state.STEP_VIEW ) // due to page change: button going to be set, clear other toggle buttons
1215
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1216
    seq_ui_button_state.STEP_VIEW ^= 1; // toggle STEP_VIEW pressed (will also be released once GP button has been pressed)
1217
  } else {
1218
    // set mode
1219
    seq_ui_button_state.STEP_VIEW = depressed ? 0 : 1;
1220
  }
134 tk 1221
 
513 tk 1222
  if( seq_ui_button_state.STEP_VIEW ) {
600 tk 1223
    ui_stepview_prev_page = ui_page;
303 tk 1224
    SEQ_UI_PageSet(SEQ_UI_PAGE_STEPSEL);
1225
  } else {
524 tk 1226
    if( ui_page == SEQ_UI_PAGE_STEPSEL )
600 tk 1227
      SEQ_UI_PageSet(ui_stepview_prev_page);
303 tk 1228
  }
134 tk 1229
 
1230
  return 0; // no error
1231
}
1232
 
513 tk 1233
static s32 SEQ_UI_Button_TrackSel(s32 depressed)
134 tk 1234
{
513 tk 1235
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 1236
 
513 tk 1237
  if( seq_hwcfg_button_beh.track_sel ) {
1238
    if( depressed ) return -1; // ignore when button depressed
678 tk 1239
    if( !seq_ui_button_state.TRACK_SEL ) // due to page change: button going to be set, clear other toggle buttons
1240
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1241
    seq_ui_button_state.TRACK_SEL ^= 1; // toggle TRACKSEL status (will also be released once GP button has been pressed)
1242
  } else {
1243
    seq_ui_button_state.TRACK_SEL = depressed ? 0 : 1;
1244
  }
1245
 
1246
  if( seq_ui_button_state.TRACK_SEL ) {
1247
    prev_page = ui_page;
1248
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRACKSEL);
1249
  } else {
524 tk 1250
    if( ui_page == SEQ_UI_PAGE_TRACKSEL )
1251
      SEQ_UI_PageSet(prev_page);
513 tk 1252
  }
1253
 
134 tk 1254
  return 0; // no error
1255
}
1256
 
987 tk 1257
static s32 SEQ_UI_Button_Group(s32 depressed, u32 group)
1258
{
1259
  if( depressed ) return -1; // ignore when button depressed
1260
 
1261
  if( group >= 4 ) return -2; // max. 4 group buttons
1262
 
1263
  // in song page: track and group buttons are used to select the cursor position
1264
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1265
    ui_selected_item = 3 + group;
1266
    return 0;
1267
  }
1268
 
1269
  // if group has changed:
1270
  if( group != ui_selected_group ) {
1271
    // get current track selection
1272
    u16 old_tracks = ui_selected_tracks >> (4*ui_selected_group);
1273
 
1274
    // select new group
1275
    ui_selected_group = group;
1276
 
1277
    // take over old track selection
1278
    ui_selected_tracks = old_tracks << (4*ui_selected_group);
1279
  }
1280
 
1281
  // set/clear encoder fast function if required
1282
  SEQ_UI_InitEncSpeed(1); // auto config
1283
 
1284
  return 0; // no error
1285
}
1286
 
484 tk 1287
static s32 SEQ_UI_Button_Track(s32 depressed, u32 track_button)
134 tk 1288
{
484 tk 1289
  static u8 button_state = 0x0f; // all 4 buttons depressed
134 tk 1290
 
484 tk 1291
  if( track_button >= 4 ) return -2; // max. 4 track buttons
134 tk 1292
 
484 tk 1293
  if( depressed ) {
1294
    button_state |= (1 << track_button);
1295
    return 0; // no error
1296
  }
134 tk 1297
 
484 tk 1298
  button_state &= ~(1 << track_button);
1299
 
987 tk 1300
  // in pattern and song page: use track buttons as group buttons
1301
  if( ui_page == SEQ_UI_PAGE_PATTERN || ui_page == SEQ_UI_PAGE_SONG ) {
1302
    return SEQ_UI_Button_Group(depressed, track_button);
1303
  }
1304
 
484 tk 1305
  if( button_state == (~(1 << track_button) & 0xf) ) {
1306
    // if only one select button pressed: radio-button function (1 of 4)
1307
    ui_selected_tracks = 1 << (track_button + 4*ui_selected_group);
1308
  } else {
1309
    // if more than one select button pressed: toggle function (4 of 4)
1310
    ui_selected_tracks ^= 1 << (track_button + 4*ui_selected_group);
1311
  }
1312
 
178 tk 1313
  // set/clear encoder fast function if required
1314
  SEQ_UI_InitEncSpeed(1); // auto config
1315
 
134 tk 1316
  return 0; // no error
1317
}
1318
 
1146 tk 1319
static s32 SEQ_UI_Button_DirectTrack(s32 depressed, u32 track_button)
1320
{
1321
  static u16 button_state = 0xffff; // all 16 buttons depressed
1322
 
1323
  if( track_button >= 16 ) return -2; // max. 16 direct track buttons
1324
 
1325
  if( depressed ) {
1326
    button_state |= (1 << track_button);
1327
    return 0; // no error
1328
  }
1329
 
1330
  button_state &= ~(1 << track_button);
1331
 
1332
  if( button_state == (~(1 << track_button) & 0xffff) ) {
1333
    // if only one select button pressed: radio-button function (1 of 16)
1334
    ui_selected_tracks = 1 << track_button;
1335
  } else {
1336
    // if more than one select button pressed: toggle function (16 of 16)
1337
    ui_selected_tracks ^= 1 << track_button;
1338
  }
1339
 
1340
  // set/clear encoder fast function if required
1341
  SEQ_UI_InitEncSpeed(1); // auto config
1342
 
1343
  return 0; // no error
1344
}
1345
 
513 tk 1346
static s32 SEQ_UI_Button_ParLayerSel(s32 depressed)
1347
{
600 tk 1348
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1349
  // also used by seq_ui_parsel.c
513 tk 1350
 
1351
  if( seq_hwcfg_button_beh.par_layer ) {
1352
    if( depressed ) return -1; // ignore when button depressed
678 tk 1353
    if( !seq_ui_button_state.PAR_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1354
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1355
    seq_ui_button_state.PAR_LAYER_SEL ^= 1; // toggle PARSEL status (will also be released once GP button has been pressed)
1356
  } else {
1357
    seq_ui_button_state.PAR_LAYER_SEL = depressed ? 0 : 1;
1358
  }
1359
 
1360
  if( seq_ui_button_state.PAR_LAYER_SEL ) {
600 tk 1361
    ui_parlayer_prev_page = ui_page;
513 tk 1362
    SEQ_UI_PageSet(SEQ_UI_PAGE_PARSEL);
1363
  } else {
524 tk 1364
    if( ui_page == SEQ_UI_PAGE_PARSEL )
600 tk 1365
      SEQ_UI_PageSet(ui_parlayer_prev_page);
513 tk 1366
  }
1367
 
1368
  // set/clear encoder fast function if required
1369
  SEQ_UI_InitEncSpeed(1); // auto config
1370
 
1371
  return 0; // no error
1372
}
1373
 
134 tk 1374
static s32 SEQ_UI_Button_ParLayer(s32 depressed, u32 par_layer)
1375
{
1117 tk 1376
  static u8 layer_c_pressed = 0;
784 tk 1377
 
134 tk 1378
  if( par_layer >= 3 ) return -2; // max. 3 parlayer buttons
1379
 
1205 tk 1380
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1381
  u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1382
 
987 tk 1383
  // in song page: parameter layer buttons are used to select the cursor position
1384
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1385
    ui_selected_item = par_layer;
1386
    return 0;
1387
  }
1388
 
1205 tk 1389
  // drum mode in edit page: print parameter layer as long as button is pressed
1390
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1391
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1392
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1393
      ui_hold_msg_ctr = depressed ? 0 : ~0; // show value for at least 65 seconds... enough?
1394
    }
1395
  }
134 tk 1396
 
784 tk 1397
  // holding Layer C button allows to increment/decrement layer with A/B button
1398
  if( par_layer == 2 )
1399
    layer_c_pressed = !depressed;
1400
 
1401
  if( layer_c_pressed && par_layer == 0 ) {
333 tk 1402
    if( depressed ) return -1; // ignore when button depressed
784 tk 1403
    // increment layer
1404
    if( ++ui_selected_par_layer >= num_p_layers )
1405
      ui_selected_par_layer = 0;
1406
  } else if( layer_c_pressed && par_layer == 1 ) {
333 tk 1407
    if( depressed ) return -1; // ignore when button depressed
784 tk 1408
    // decrement layer
1409
    if( ui_selected_par_layer == 0 )
1410
      ui_selected_par_layer = num_p_layers - 1;
333 tk 1411
    else
784 tk 1412
      --ui_selected_par_layer;
333 tk 1413
  } else {
784 tk 1414
    if( num_p_layers <= 3 ) {
1415
      // 3 layers: direct selection with LayerA/B/C button
333 tk 1416
      if( depressed ) return -1; // ignore when button depressed
784 tk 1417
      if( par_layer >= num_p_layers ) {
1418
    char str1[21];
1419
    sprintf(str1, "Parameter Layer %c", 'A'+par_layer);
1420
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1421
      } else {
1422
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1423
    ui_selected_par_layer = par_layer;
1424
      }
1425
    } else if( num_p_layers <= 4 ) {
1426
      // 4 layers: LayerC Button toggles between C and D
1427
      if( depressed ) return -1; // ignore when button depressed
333 tk 1428
      seq_ui_button_state.PAR_LAYER_SEL = 0;
784 tk 1429
      if( par_layer == 2 )
1430
    ui_selected_par_layer = (ui_selected_par_layer == 2) ? 3 : 2;
1431
      else
1432
    ui_selected_par_layer = par_layer;
333 tk 1433
    } else {
784 tk 1434
      // >4 layers: LayerA/B button selects directly, Layer C button enters layer selection page
1435
      if( par_layer <= 1 ) {
1436
    if( depressed ) return -1; // ignore when button depressed
1437
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1438
    ui_selected_par_layer = par_layer;
1439
      } else {
1440
    return SEQ_UI_Button_ParLayerSel(depressed);
1441
      }
333 tk 1442
    }
1443
  }
1444
 
178 tk 1445
  // set/clear encoder fast function if required
1446
  SEQ_UI_InitEncSpeed(1); // auto config
1447
 
134 tk 1448
  return 0; // no error
1449
}
1450
 
513 tk 1451
static s32 SEQ_UI_Button_TrgLayerSel(s32 depressed)
1452
{
600 tk 1453
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1454
  // also used by seq_ui_trgsel.c
513 tk 1455
 
1456
  if( seq_hwcfg_button_beh.trg_layer ) {
1457
    if( depressed ) return -1; // ignore when button depressed
678 tk 1458
    if( !seq_ui_button_state.TRG_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1459
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1460
    seq_ui_button_state.TRG_LAYER_SEL ^= 1; // toggle TRGSEL status (will also be released once GP button has been pressed)
1461
  } else {
1462
    seq_ui_button_state.TRG_LAYER_SEL = depressed ? 0 : 1;
1463
  }
1464
 
1465
  if( seq_ui_button_state.TRG_LAYER_SEL ) {
600 tk 1466
    ui_trglayer_prev_page = ui_page;
513 tk 1467
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRGSEL);
1468
  } else {
524 tk 1469
    if( ui_page == SEQ_UI_PAGE_TRGSEL )
600 tk 1470
      SEQ_UI_PageSet(ui_trglayer_prev_page);
513 tk 1471
  }
1472
 
1473
  return 0; // no error
1474
}
1475
 
134 tk 1476
static s32 SEQ_UI_Button_TrgLayer(s32 depressed, u32 trg_layer)
1477
{
1117 tk 1478
  static u8 layer_c_pressed = 0;
784 tk 1479
 
134 tk 1480
  if( trg_layer >= 3 ) return -2; // max. 3 trglayer buttons
1481
 
326 tk 1482
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1483
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1484
  u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
134 tk 1485
 
1205 tk 1486
  // drum mode in edit page: ensure that trigger layer is print again
1487
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1488
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1489
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1490
      if( !depressed )
1491
    ui_hold_msg_ctr = 0;
1492
    }
1493
  }
1494
 
784 tk 1495
  // holding Layer C button allows to increment/decrement layer with A/B button
1496
  if( trg_layer == 2 )
1497
    layer_c_pressed = !depressed;
1498
 
1499
  if( layer_c_pressed && trg_layer == 0 ) {
326 tk 1500
    if( depressed ) return -1; // ignore when button depressed
784 tk 1501
    // increment layer
1502
    if( ++ui_selected_trg_layer >= num_t_layers )
1503
      ui_selected_trg_layer = 0;
1504
  } else if( layer_c_pressed && trg_layer == 1 ) {
326 tk 1505
    if( depressed ) return -1; // ignore when button depressed
784 tk 1506
    // decrement layer
1507
    if( ui_selected_trg_layer == 0 )
1508
      ui_selected_trg_layer = num_t_layers - 1;
326 tk 1509
    else
784 tk 1510
      --ui_selected_trg_layer;
326 tk 1511
  } else {
784 tk 1512
    if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 3 ) {
1513
      // 3 layers: direct selection with LayerA/B/C button
326 tk 1514
      if( depressed ) return -1; // ignore when button depressed
784 tk 1515
      if( trg_layer >= num_t_layers ) {
1516
    char str1[21];
1517
    sprintf(str1, "Trigger Layer %c", 'A'+trg_layer);
1518
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1519
      } else {
1520
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1521
    ui_selected_trg_layer = trg_layer;
1522
      }
1523
    } else if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 4 ) {
1524
      // 4 layers: LayerC Button toggles between C and D
1525
      if( depressed ) return -1; // ignore when button depressed
328 tk 1526
      seq_ui_button_state.TRG_LAYER_SEL = 0;
784 tk 1527
      if( trg_layer == 2 )
1528
    ui_selected_trg_layer = (ui_selected_trg_layer == 2) ? 3 : 2;
1529
      else
1530
    ui_selected_trg_layer = trg_layer;
326 tk 1531
    } else {
784 tk 1532
      // >4 layers or drum mode: LayerA/B button selects directly, Layer C button enters trigger selection page
1533
      // also used for drum tracks
1534
      if( trg_layer <= 1 ) {
1535
    if( depressed ) return -1; // ignore when button depressed
1536
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1537
    ui_selected_trg_layer = trg_layer;
1538
      } else {
1539
    return SEQ_UI_Button_TrgLayerSel(depressed);
1540
      }
326 tk 1541
    }
1542
  }
1543
 
134 tk 1544
  return 0; // no error
1545
}
1546
 
1547
 
1119 tk 1548
static s32 SEQ_UI_Button_Mixer(s32 depressed)
544 tk 1549
{
1550
  if( depressed ) return -1; // ignore when button depressed
134 tk 1551
 
1119 tk 1552
  SEQ_UI_PageSet(SEQ_UI_PAGE_MIXER);
544 tk 1553
 
1554
  return 0; // no error
1555
}
1556
 
1119 tk 1557
static s32 SEQ_UI_Button_TrackMode(s32 depressed)
544 tk 1558
{
1559
  if( depressed ) return -1; // ignore when button depressed
1560
 
1119 tk 1561
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMODE);
544 tk 1562
 
1563
  return 0; // no error
1564
}
1565
 
1119 tk 1566
static s32 SEQ_UI_Button_TrackGroove(s32 depressed)
544 tk 1567
{
1568
  if( depressed ) return -1; // ignore when button depressed
1569
 
1119 tk 1570
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKGRV);
1571
 
1572
  return 0; // no error
1573
}
1574
 
1575
static s32 SEQ_UI_Button_TrackLength(s32 depressed)
1576
{
1577
  if( depressed ) return -1; // ignore when button depressed
1578
 
1579
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKLEN);
1580
 
1581
  return 0; // no error
1582
}
1583
 
1584
static s32 SEQ_UI_Button_TrackDirection(s32 depressed)
1585
{
1586
  if( depressed ) return -1; // ignore when button depressed
1587
 
1588
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKDIR);
1589
 
1590
  return 0; // no error
1591
}
1592
 
1593
static s32 SEQ_UI_Button_TrackMorph(s32 depressed)
1594
{
1595
  if( depressed ) return -1; // ignore when button depressed
1596
 
1597
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMORPH);
1598
 
1599
  return 0; // no error
1600
}
1601
 
1602
static s32 SEQ_UI_Button_TrackTranspose(s32 depressed)
1603
{
1604
  if( depressed ) return -1; // ignore when button depressed
1605
 
544 tk 1606
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKTRAN);
1607
 
1608
  return 0; // no error
1609
}
1610
 
1611
 
742 tk 1612
// only used by keyboard remote function
1613
static s32 SEQ_UI_Button_ToggleGate(s32 depressed)
1614
{
1615
  if( depressed ) return -1; // ignore when button depressed
544 tk 1616
 
742 tk 1617
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1618
  u8 gate = SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? 0 : 1;
1619
  SEQ_TRG_GateSet(visible_track, ui_selected_step, ui_selected_instrument, gate);
544 tk 1620
 
742 tk 1621
  return 0; // no error
1622
}
1623
 
1349 tk 1624
static s32 SEQ_UI_Button_FootSwitch(s32 depressed)
1625
{
1626
  // static variables (only used here, therefore local)
1627
  static u32 fs_time_control = 0; // timestamp of last operation
1628
  static u8  fs_mode = 0; // mode
742 tk 1629
 
1349 tk 1630
  // this is used as a constant value
1631
  u32 fs_time_delay = 1000; // mS - should this be configurable?
742 tk 1632
 
1349 tk 1633
 
1634
  // PUNCH_IN, PUNCH_OUT and Delete track data control
1635
  if( !depressed ) {
1636
    if( ( fs_time_control > (seq_core_timestamp_ms - fs_time_delay) ) && ( fs_time_control != 0 ) )
1637
    {
1638
      // that confirms the delete function
1639
      fs_mode = 1; // delete
1640
    } else {
1641
      // start time in count
1642
      fs_time_control = seq_core_timestamp_ms;
1643
    }
1644
  } else {
1645
    // if time pressed is less than fs_time_delay miliseconds, we got a possible delete function activation
1646
    if( fs_time_control > (seq_core_timestamp_ms - fs_time_delay) )
1647
    {
1648
      switch( fs_mode ) {
1649
      case 1: { // delete
1650
        SEQ_UI_Button_Clear_Track(0);
1651
        fs_mode = 0; // back to normal mode, later we would increment the value
1652
      } break;
1653
      default:
1654
        fs_mode = 0; // for the case that an invalid mode is selected
1655
      }
1656
 
1657
      fs_time_control = seq_core_timestamp_ms;
1658
    }
1659
  }
1660
 
1661
  if( depressed ) {
1662
    // disable recording
1663
    seq_record_state.ENABLED = 0;
1664
  } else {
1665
    // enable recording
1666
    seq_record_state.ENABLED = 1;
1667
    seq_record_state.ARMED_TRACKS = ui_selected_tracks; // not used yet, just preparation for future changes
1668
  }
1669
 
1670
  return 0; // no error
1671
}
1672
 
1673
 
134 tk 1674
/////////////////////////////////////////////////////////////////////////////
1675
// Button handler
1676
/////////////////////////////////////////////////////////////////////////////
1677
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
1678
{
492 tk 1679
  int i;
1680
 
625 tk 1681
  // send MIDI event in remote mode and exit
1316 tk 1682
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 1683
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendButton(pin, pin_value);
1684
 
1044 tk 1685
  // ignore as long as hardware config hasn't been read
496 tk 1686
  if( !SEQ_FILE_HW_ConfigLocked() )
1687
    return -1;
1688
 
740 tk 1689
  // ignore during a backup or format is created
1690
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1691
    return -1;
1692
 
328 tk 1693
  // ensure that selections are matching with track constraints
1694
  SEQ_UI_CheckSelections();
1695
 
492 tk 1696
  // request display update
1697
  seq_ui_display_update_req = 1;
134 tk 1698
 
596 tk 1699
  // stop current message if (new) button has been pressed
1700
  if( pin_value == 0 )
1701
    SEQ_UI_MsgStop();
134 tk 1702
 
596 tk 1703
 
492 tk 1704
  // MEMO: we could also use a jump table with references to the functions
1705
  // here, but this "spagetthi code" simplifies the configuration and
1706
  // the resulting ASM doesn't look that bad!
168 tk 1707
 
492 tk 1708
  for(i=0; i<SEQ_HWCFG_NUM_GP; ++i)
1709
    if( pin == seq_hwcfg_button.gp[i] )
1710
      return SEQ_UI_Button_GP(pin_value, i);
134 tk 1711
 
492 tk 1712
  for(i=0; i<SEQ_HWCFG_NUM_TRACK; ++i)
1713
    if( pin == seq_hwcfg_button.track[i] )
1714
      return SEQ_UI_Button_Track(pin_value, i);
1146 tk 1715
 
1716
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_TRACK; ++i)
1717
    if( pin == seq_hwcfg_button.direct_track[i] )
1718
      return SEQ_UI_Button_DirectTrack(pin_value, i);
1719
 
1205 tk 1720
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_BOOKMARK; ++i)
1721
    if( pin == seq_hwcfg_button.direct_bookmark[i] )
1722
      return SEQ_UI_Button_DirectBookmark(pin_value, i);
1723
 
513 tk 1724
  if( pin == seq_hwcfg_button.track_sel )
1725
    return SEQ_UI_Button_TrackSel(pin_value);
134 tk 1726
 
492 tk 1727
  for(i=0; i<SEQ_HWCFG_NUM_GROUP; ++i)
1728
    if( pin == seq_hwcfg_button.group[i] )
1729
      return SEQ_UI_Button_Group(pin_value, i);
134 tk 1730
 
492 tk 1731
  for(i=0; i<SEQ_HWCFG_NUM_PAR_LAYER; ++i)
1732
    if( pin == seq_hwcfg_button.par_layer[i] )
1733
      return SEQ_UI_Button_ParLayer(pin_value, i);
513 tk 1734
  if( pin == seq_hwcfg_button.par_layer_sel )
1735
    return SEQ_UI_Button_ParLayerSel(pin_value);
134 tk 1736
 
492 tk 1737
  for(i=0; i<SEQ_HWCFG_NUM_TRG_LAYER; ++i)
1738
    if( pin == seq_hwcfg_button.trg_layer[i] )
1739
      return SEQ_UI_Button_TrgLayer(pin_value, i);
513 tk 1740
  if( pin == seq_hwcfg_button.trg_layer_sel )
1741
    return SEQ_UI_Button_TrgLayerSel(pin_value);
134 tk 1742
 
492 tk 1743
  if( pin == seq_hwcfg_button.left )
1744
    return SEQ_UI_Button_Left(pin_value);
1745
  if( pin == seq_hwcfg_button.right )
1746
    return SEQ_UI_Button_Right(pin_value);
1747
  if( pin == seq_hwcfg_button.down )
1748
    return SEQ_UI_Button_Down(pin_value);
1749
  if( pin == seq_hwcfg_button.up )
1750
    return SEQ_UI_Button_Up(pin_value);
134 tk 1751
 
492 tk 1752
  if( pin == seq_hwcfg_button.scrub )
1753
    return SEQ_UI_Button_Scrub(pin_value);
1754
  if( pin == seq_hwcfg_button.metronome )
1755
    return SEQ_UI_Button_Metronome(pin_value);
134 tk 1756
 
630 tk 1757
  if( pin == seq_hwcfg_button.record )
1758
    return SEQ_UI_Button_Record(pin_value);
1219 tk 1759
  if( pin == seq_hwcfg_button.live )
1760
    return SEQ_UI_Button_Live(pin_value);
630 tk 1761
 
492 tk 1762
  if( pin == seq_hwcfg_button.stop )
1763
    return SEQ_UI_Button_Stop(pin_value);
1764
  if( pin == seq_hwcfg_button.pause )
1765
    return SEQ_UI_Button_Pause(pin_value);
1766
  if( pin == seq_hwcfg_button.play )
1767
    return SEQ_UI_Button_Play(pin_value);
1768
  if( pin == seq_hwcfg_button.rew )
1769
    return SEQ_UI_Button_Rew(pin_value);
1770
  if( pin == seq_hwcfg_button.fwd )
1771
    return SEQ_UI_Button_Fwd(pin_value);
596 tk 1772
  if( pin == seq_hwcfg_button.loop )
1773
    return SEQ_UI_Button_Loop(pin_value);
973 tk 1774
  if( pin == seq_hwcfg_button.follow )
1775
    return SEQ_UI_Button_Follow(pin_value);
134 tk 1776
 
492 tk 1777
  if( pin == seq_hwcfg_button.utility )
1778
    return SEQ_UI_Button_Utility(pin_value);
1779
  if( pin == seq_hwcfg_button.copy )
1780
    return SEQ_UI_Button_Copy(pin_value);
1781
  if( pin == seq_hwcfg_button.paste )
1782
    return SEQ_UI_Button_Paste(pin_value);
1783
  if( pin == seq_hwcfg_button.clear )
1784
    return SEQ_UI_Button_Clear(pin_value);
1014 tk 1785
  if( pin == seq_hwcfg_button.undo )
1786
    return SEQ_UI_Button_Undo(pin_value);
134 tk 1787
 
492 tk 1788
  if( pin == seq_hwcfg_button.menu )
1789
    return SEQ_UI_Button_Menu(pin_value);
1203 tk 1790
  if( pin == seq_hwcfg_button.bookmark )
1791
    return SEQ_UI_Button_Bookmark(pin_value);
492 tk 1792
  if( pin == seq_hwcfg_button.select )
1793
    return SEQ_UI_Button_Select(pin_value);
1794
  if( pin == seq_hwcfg_button.exit )
1795
    return SEQ_UI_Button_Exit(pin_value);
134 tk 1796
 
513 tk 1797
  if( pin == seq_hwcfg_button.tap_tempo )
1798
    return SEQ_UI_Button_TapTempo(pin_value);
1799
  if( pin == seq_hwcfg_button.tempo_preset )
1800
    return SEQ_UI_Button_TempoPreset(pin_value);
524 tk 1801
  if( pin == seq_hwcfg_button.ext_restart )
1802
    return SEQ_UI_Button_ExtRestart(pin_value);
134 tk 1803
 
492 tk 1804
  if( pin == seq_hwcfg_button.edit )
1805
    return SEQ_UI_Button_Edit(pin_value);
1806
  if( pin == seq_hwcfg_button.mute )
1807
    return SEQ_UI_Button_Mute(pin_value);
1808
  if( pin == seq_hwcfg_button.pattern )
1809
    return SEQ_UI_Button_Pattern(pin_value);
1810
  if( pin == seq_hwcfg_button.song )
1811
    return SEQ_UI_Button_Song(pin_value);
134 tk 1812
 
492 tk 1813
  if( pin == seq_hwcfg_button.solo )
1814
    return SEQ_UI_Button_Solo(pin_value);
1815
  if( pin == seq_hwcfg_button.fast )
1816
    return SEQ_UI_Button_Fast(pin_value);
1121 tk 1817
  if( pin == seq_hwcfg_button.fast2 )
1818
    return SEQ_UI_Button_Fast2(pin_value);
492 tk 1819
  if( pin == seq_hwcfg_button.all )
1820
    return SEQ_UI_Button_All(pin_value);
134 tk 1821
 
492 tk 1822
  if( pin == seq_hwcfg_button.step_view )
1823
    return SEQ_UI_Button_StepView(pin_value);
134 tk 1824
 
544 tk 1825
  if( pin == seq_hwcfg_button.mixer )
1826
    return SEQ_UI_Button_Mixer(pin_value);
1827
 
1119 tk 1828
  if( pin == seq_hwcfg_button.track_mode )
1829
    return SEQ_UI_Button_TrackMode(pin_value);
1830
  if( pin == seq_hwcfg_button.track_groove )
1831
    return SEQ_UI_Button_TrackGroove(pin_value);
1832
  if( pin == seq_hwcfg_button.track_length )
1833
    return SEQ_UI_Button_TrackLength(pin_value);
1834
  if( pin == seq_hwcfg_button.track_direction )
1835
    return SEQ_UI_Button_TrackDirection(pin_value);
1836
  if( pin == seq_hwcfg_button.track_morph )
1837
    return SEQ_UI_Button_TrackMorph(pin_value);
1838
  if( pin == seq_hwcfg_button.track_transpose )
1839
    return SEQ_UI_Button_TrackTranspose(pin_value);
1349 tk 1840
  if( pin == seq_hwcfg_button.footswitch )
1841
    return SEQ_UI_Button_FootSwitch(pin_value);
1119 tk 1842
 
625 tk 1843
  // always print debugging message
1844
#if 1
1081 tk 1845
  MUTEX_MIDIOUT_TAKE;
1846
  DEBUG_MSG("[SEQ_UI_Button_Handler] Button SR:%d, Pin:%d not mapped, it has been %s.\n",
1847
        (pin >> 3) + 1,
1848
        pin & 7,
1849
        pin_value ? "depressed" : "pressed");
1850
  MUTEX_MIDIOUT_GIVE;
625 tk 1851
#endif
1852
 
492 tk 1853
  return -1; // button not mapped
134 tk 1854
}
1855
 
1856
 
1857
/////////////////////////////////////////////////////////////////////////////
524 tk 1858
// BLM Button handler
1859
/////////////////////////////////////////////////////////////////////////////
1860
s32 SEQ_UI_BLM_Button_Handler(u32 row, u32 pin, u32 pin_value)
1861
{
625 tk 1862
  // send MIDI event in remote mode and exit
1316 tk 1863
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 1864
    return SEQ_MIDI_SYSEX_REMOTE_Client_Send_BLM_Button(row, pin, pin_value);
1865
 
1044 tk 1866
  // ignore as long as hardware config hasn't been read
524 tk 1867
  if( !SEQ_FILE_HW_ConfigLocked() )
1868
    return -1;
1869
 
740 tk 1870
  // ignore during a backup or format is created
1871
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1872
    return -1;
1873
 
524 tk 1874
  if( row >= SEQ_CORE_NUM_TRACKS_PER_GROUP )
1875
    return -1; // more than 4 tracks not supported (yet) - could be done in this function w/o much effort
1876
 
1877
  if( pin >= 16 )
1878
    return -1; // more than 16 step buttons not supported (yet) - could be done by selecting the step view
1879
 
1880
  // select track depending on row
1881
  ui_selected_tracks = 1 << (row + 4*ui_selected_group);
1882
 
1883
  // ensure that selections are matching with track constraints
1884
  SEQ_UI_CheckSelections();
1885
 
1886
  // request display update
1887
  seq_ui_display_update_req = 1;
1888
 
1889
  // emulate general purpose button
758 tk 1890
  if( seq_hwcfg_blm.buttons_no_ui ) {
763 tk 1891
    s32 status = SEQ_UI_EDIT_Button_Handler(pin, pin_value);
758 tk 1892
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1893
    return status;
763 tk 1894
  }
1895
 
1896
  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 1897
}
1898
 
1899
 
1900
/////////////////////////////////////////////////////////////////////////////
134 tk 1901
// Encoder handler
1902
/////////////////////////////////////////////////////////////////////////////
1903
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
1904
{
625 tk 1905
  // send MIDI event in remote mode and exit
1316 tk 1906
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 1907
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendEncoder(encoder, incrementer);
1908
 
1044 tk 1909
  // ignore as long as hardware config hasn't been read
496 tk 1910
  if( !SEQ_FILE_HW_ConfigLocked() )
1911
    return -1;
1912
 
740 tk 1913
  // ignore during a backup or format is created
1914
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1915
    return -1;
1916
 
1341 tk 1917
  if( encoder >= SEQ_HWCFG_NUM_ENCODERS )
134 tk 1918
    return -1; // encoder doesn't exist
1919
 
328 tk 1920
  // ensure that selections are matching with track constraints
1921
  SEQ_UI_CheckSelections();
1922
 
596 tk 1923
  // stop current message
1924
  SEQ_UI_MsgStop();
1925
 
134 tk 1926
  // limit incrementer
1927
  if( incrementer > 3 )
1928
    incrementer = 3;
1929
  else if( incrementer < -3 )
1930
    incrementer = -3;
1931
 
1341 tk 1932
  // encoder 17 increments BPM
1933
  if( encoder == 17 ) {
1934
    u16 value = (u16)(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num]*10);
1935
    if( SEQ_UI_Var16_Inc(&value, 25, 3000, incrementer) ) { // at 384ppqn, the minimum BPM rate is ca. 2.5
1936
      // set new BPM
1937
      seq_core_bpm_preset_tempo[seq_core_bpm_preset_num] = (float)value/10.0;
1938
      SEQ_CORE_BPM_Update(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num], seq_core_bpm_preset_ramp[seq_core_bpm_preset_num]);
1939
      //store_file_required = 1;
1940
      seq_ui_display_update_req = 1;      
1941
    }
1942
    return 0;
1943
  }
1944
 
607 tk 1945
  if( seq_ui_button_state.SCRUB && encoder == 0 ) {
1946
    // if sequencer isn't already running, continue it (don't restart)
1947
    if( !SEQ_BPM_IsRunning() )
1948
      SEQ_BPM_Cont();
1949
    ui_seq_pause = 0; // clear pause mode
1278 tk 1950
 
607 tk 1951
    // Scrub sequence back or forth
1952
    portENTER_CRITICAL(); // should be atomic
1953
    SEQ_CORE_Scrub(incrementer);
1954
    portEXIT_CRITICAL();
1955
  } else if( !seq_ui_button_state.MENU_PRESSED && ui_encoder_callback != NULL ) {
173 tk 1956
    ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
740 tk 1957
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0; // ensure that value is visible when it has been changed
134 tk 1958
  }
1959
 
1960
  // request display update
159 tk 1961
  seq_ui_display_update_req = 1;
134 tk 1962
 
1963
  return 0; // no error
1964
}
1965
 
1966
 
353 tk 1967
 
134 tk 1968
/////////////////////////////////////////////////////////////////////////////
626 tk 1969
// Receives a MIDI package from APP_NotifyReceivedEvent (-> app.c)
1970
/////////////////////////////////////////////////////////////////////////////
1971
s32 SEQ_UI_REMOTE_MIDI_Receive(mios32_midi_port_t port, mios32_midi_package_t midi_package)
1972
{
1973
#if 1
1974
  // check for active remote mode
1316 tk 1975
  if( seq_midi_sysex_remote_active_mode != SEQ_MIDI_SYSEX_REMOTE_MODE_SERVER )
626 tk 1976
    return 0; // no error
1977
#endif
1978
 
1316 tk 1979
  if( (seq_midi_sysex_remote_port == DEFAULT && seq_midi_sysex_remote_active_port != port) ||
1980
      (seq_midi_sysex_remote_port != DEFAULT && port != seq_midi_sysex_remote_port) )
626 tk 1981
    return 0; // wrong port
1982
 
1983
  // for easier parsing: convert Note Off -> Note On with velocity 0
1984
  if( midi_package.event == NoteOff ) {
1985
    midi_package.event = NoteOn;
1986
    midi_package.velocity = 0;
1987
  }
1988
 
1989
  switch( midi_package.event ) {
1990
    case NoteOn: {
1991
      switch( midi_package.chn ) {
1992
        case Chn1:
1993
      SEQ_UI_Button_Handler(midi_package.note + 0x00, midi_package.velocity ? 0 : 1);
1994
      break;
1995
        case Chn2:
1996
      SEQ_UI_Button_Handler(midi_package.note + 0x80, midi_package.velocity ? 0 : 1);
1997
      break;
1998
        case Chn3:
1999
      SEQ_UI_BLM_Button_Handler(midi_package.note >> 5, midi_package.note & 0x1f, midi_package.velocity ? 0 : 1);
2000
      break;
2001
      }
2002
    } break;
2003
 
2004
    case CC: {
2005
      if( midi_package.cc_number >= 15 && midi_package.cc_number <= 31 )
2006
    SEQ_UI_Encoder_Handler(midi_package.cc_number-15, (int)midi_package.value - 0x40);
2007
    } break;
2008
  }
2009
 
632 tk 2010
  return 1; // MIDI event has been taken for remote function -> don't forward to router/MIDI event parser
626 tk 2011
}
2012
 
2013
 
2014
/////////////////////////////////////////////////////////////////////////////
741 tk 2015
// MIDI Remote Keyboard Function (called from SEQ_MIDI_IN)
2016
/////////////////////////////////////////////////////////////////////////////
742 tk 2017
s32 SEQ_UI_REMOTE_MIDI_Keyboard(u8 key, u8 depressed)
741 tk 2018
{
742 tk 2019
#if 0
1316 tk 2020
  MIOS32_MIDI_SendDebugMessage("SEQ_MIDI_SYSEX_REMOTE_MIDI_Keyboard(%d, %d)\n", key, depressed);
741 tk 2021
#endif
742 tk 2022
 
2023
  switch( key ) {
2024
    case 0x24: // C-2
2025
      return SEQ_UI_Button_GP(depressed, 0);
2026
    case 0x25: // C#2
2027
      return SEQ_UI_Button_Track(depressed, 0);
2028
    case 0x26: // D-2
2029
      return SEQ_UI_Button_GP(depressed, 1);
2030
    case 0x27: // D#2
2031
      return SEQ_UI_Button_Track(depressed, 1);
2032
    case 0x28: // E-2
2033
      return SEQ_UI_Button_GP(depressed, 2);
2034
    case 0x29: // F-2
2035
      return SEQ_UI_Button_GP(depressed, 3);
2036
    case 0x2a: // F#2
2037
      return SEQ_UI_Button_Track(depressed, 2);
2038
    case 0x2b: // G-2
2039
      return SEQ_UI_Button_GP(depressed, 4);
2040
    case 0x2c: // G#2
2041
      return SEQ_UI_Button_Track(depressed, 3);
2042
    case 0x2d: // A-2
2043
      return SEQ_UI_Button_GP(depressed, 5);
2044
    case 0x2e: // A#2
2045
      return SEQ_UI_Button_ParLayer(depressed, 0);
2046
    case 0x2f: // B-2
2047
      return SEQ_UI_Button_GP(depressed, 6);
2048
 
2049
    case 0x30: // C-3
2050
      return SEQ_UI_Button_GP(depressed, 7);
2051
    case 0x31: // C#3
2052
      return SEQ_UI_Button_ParLayer(depressed, 1);
2053
    case 0x32: // D-3
2054
      return SEQ_UI_Button_GP(depressed, 8);
2055
    case 0x33: // D#3
2056
      return SEQ_UI_Button_ParLayer(depressed, 2);
2057
    case 0x34: // E-3
2058
      return SEQ_UI_Button_GP(depressed, 9);
2059
    case 0x35: // F-3
2060
      return SEQ_UI_Button_GP(depressed, 10);
2061
    case 0x36: // F#3
2062
      return SEQ_UI_Button_TrgLayer(depressed, 0);
2063
    case 0x37: // G-3
2064
      return SEQ_UI_Button_GP(depressed, 11);
2065
    case 0x38: // G#3
2066
      return SEQ_UI_Button_TrgLayer(depressed, 1);
2067
    case 0x39: // A-3
2068
      return SEQ_UI_Button_GP(depressed, 12);
2069
    case 0x3a: // A#3
2070
      return SEQ_UI_Button_TrgLayer(depressed, 2);
2071
    case 0x3b: // B-3
2072
      return SEQ_UI_Button_GP(depressed, 13);
2073
 
2074
    case 0x3c: // C-4
2075
      return SEQ_UI_Button_GP(depressed, 14);
2076
    case 0x3d: // C#4
2077
      return SEQ_UI_Button_Group(depressed, 0);
2078
    case 0x3e: // D-4
2079
      return SEQ_UI_Button_GP(depressed, 15);
2080
    case 0x3f: // D#4
2081
      return SEQ_UI_Button_Group(depressed, 1);
2082
    case 0x40: // E-4
2083
      return 0; // ignore
2084
    case 0x41: // F-4
2085
      return SEQ_UI_Button_StepView(depressed);
2086
    case 0x42: // F#4
2087
      return SEQ_UI_Button_Group(depressed, 1);
2088
    case 0x43: // G-4
2089
      return 0; // ignore
2090
    case 0x44: // G#4
2091
      return SEQ_UI_Button_Group(depressed, 2);
2092
    case 0x45: // A-4
2093
      return SEQ_UI_Button_Left(depressed);
2094
    case 0x46: // A#4
2095
      return SEQ_UI_Button_ToggleGate(depressed);
2096
    case 0x47: // B-4
2097
      return SEQ_UI_Button_Right(depressed);
2098
 
2099
    case 0x48: // C-5
2100
      return SEQ_UI_Button_Edit(depressed);
2101
    case 0x49: // C#5
2102
      return SEQ_UI_Button_Solo(depressed);
2103
    case 0x4a: // D-5
2104
      return SEQ_UI_Button_Mute(depressed);
2105
    case 0x4b: // D#5
2106
      return SEQ_UI_Button_All(depressed);
2107
    case 0x4c: // E-5
2108
      return SEQ_UI_Button_Pattern(depressed);
2109
    case 0x4d: // F-5
2110
      return SEQ_UI_Button_Song(depressed);
2111
    case 0x4e: // F#5
2112
      return SEQ_UI_Button_Fast(depressed);
2113
    case 0x4f: // G-5
2114
      return SEQ_UI_Button_Metronome(depressed);
2115
    case 0x50: // G#5
2116
      return SEQ_UI_Button_ExtRestart(depressed);
2117
    case 0x51: // A-5
2118
      return SEQ_UI_Button_ParLayerSel(depressed);
2119
    case 0x52: // A#5
2120
      return SEQ_UI_Button_TrackSel(depressed);
2121
    case 0x53: // B-5
2122
      return SEQ_UI_Button_Stop(depressed);
2123
 
2124
    case 0x54: // C-6
2125
      return SEQ_UI_Button_Play(depressed);
2126
    case 0x55: // C#6
2127
      return SEQ_UI_Button_Pause(depressed);
2128
    case 0x56: // D-6
2129
      return SEQ_UI_Button_Rew(depressed);
2130
    case 0x57: // D#6
2131
      return SEQ_UI_Button_Fwd(depressed);
2132
    case 0x58: // E-6
2133
      return SEQ_UI_Button_Utility(depressed);
2134
    case 0x59: // F-6
2135
      return SEQ_UI_Button_TempoPreset(depressed);
2136
    case 0x5a: // F#6
2137
      return 0; // ignore
2138
    case 0x5b: // G-6
2139
      return SEQ_UI_Button_Menu(depressed);
2140
    case 0x5c: // G#6
2141
      return SEQ_UI_Button_Select(depressed);
2142
    case 0x5d: // A-6
2143
      return SEQ_UI_Button_Exit(depressed);
2144
    case 0x5e: // A#6
2145
      return SEQ_UI_Button_Down(depressed);
2146
    case 0x5f: // B-6
2147
      return SEQ_UI_Button_Up(depressed);
2148
  }
2149
 
741 tk 2150
  return 0; // no error
2151
}
2152
 
2153
 
2154
/////////////////////////////////////////////////////////////////////////////
134 tk 2155
// Update LCD messages
2156
// Usually called from background task
2157
/////////////////////////////////////////////////////////////////////////////
2158
s32 SEQ_UI_LCD_Handler(void)
2159
{
728 tk 2160
  static u8 boot_animation_wait_ctr = 0;
2161
  static u8 boot_animation_lcd_pos = 0;
2162
 
625 tk 2163
  // special handling in remote client mode
1316 tk 2164
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2165
    return SEQ_UI_LCD_Update();
2166
 
159 tk 2167
  if( seq_ui_display_init_req ) {
2168
    seq_ui_display_init_req = 0; // clear request
134 tk 2169
 
278 tk 2170
    // clear force update of LCD
2171
    SEQ_LCD_Clear();
2172
    SEQ_LCD_Update(1);
134 tk 2173
 
168 tk 2174
    // select first menu item
2175
    ui_selected_item = 0;
2176
 
167 tk 2177
    // call init function of current page
272 tk 2178
    if( ui_menu_pages[ui_page].init_callback != NULL )
2179
      ui_menu_pages[ui_page].init_callback(0); // mode
134 tk 2180
 
2181
    // request display update
159 tk 2182
    seq_ui_display_update_req = 1;
134 tk 2183
  }
2184
 
1044 tk 2185
  // print boot screen as long as hardware config hasn't been read
496 tk 2186
  if( !SEQ_FILE_HW_ConfigLocked() ) {
728 tk 2187
    if( boot_animation_lcd_pos < (40-3) ) {
2188
      if( ++boot_animation_wait_ctr >= 75 ) {
2189
    boot_animation_wait_ctr = 0;
637 tk 2190
 
728 tk 2191
    if( boot_animation_lcd_pos == 0 ) {
2192
      SEQ_LCD_Clear();
2193
      SEQ_LCD_CursorSet(0, 0);
2194
      SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE1 " " MIOS32_LCD_BOOT_MSG_LINE2);
2195
      SEQ_LCD_CursorSet(0, 1);
2196
      SEQ_LCD_PrintString("Searching for SD Card...");
2197
    }
2198
 
2199
    // logo is print on second LCD
2200
    SEQ_LCD_LOGO_Print(boot_animation_lcd_pos++);
2201
      }
2202
    }
740 tk 2203
  } else if( seq_ui_backup_req || seq_ui_format_req ) {
634 tk 2204
    SEQ_LCD_Clear();
2205
    SEQ_LCD_CursorSet(0, 0);
740 tk 2206
    //                     <-------------------------------------->
2207
    //                     0123456789012345678901234567890123456789
2208
    if( seq_ui_backup_req )
959 tk 2209
      SEQ_LCD_PrintString("Copy Files - be patient!!!");
740 tk 2210
    else if( seq_ui_format_req )
959 tk 2211
      SEQ_LCD_PrintString("Creating Files - be patient!!!");
740 tk 2212
    else
2213
      SEQ_LCD_PrintString("Don't know what I'm doing! :-/");
637 tk 2214
 
2215
    if( seq_file_backup_notification != NULL ) {
2216
      int i;
2217
 
2218
      SEQ_LCD_CursorSet(0, 1);
959 tk 2219
      SEQ_LCD_PrintFormattedString("Creating %s", seq_file_backup_notification);
637 tk 2220
 
2221
      SEQ_LCD_CursorSet(40+3, 0);
2222
      SEQ_LCD_PrintString("Total: [");
2223
      for(i=0; i<20; ++i)
2224
    SEQ_LCD_PrintChar((i>(seq_file_backup_percentage/5)) ? ' ' : '#');
2225
      SEQ_LCD_PrintFormattedString("] %3d%%", seq_file_backup_percentage);
2226
 
2227
      SEQ_LCD_CursorSet(40+3, 1);
2228
      SEQ_LCD_PrintString("File:  [");
2229
      for(i=0; i<20; ++i)
1261 tk 2230
    SEQ_LCD_PrintChar((i>(file_copy_percentage/5)) ? ' ' : '#');
2231
      SEQ_LCD_PrintFormattedString("] %3d%%", file_copy_percentage);
637 tk 2232
    }
2233
 
496 tk 2234
  } else if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
2235
    SEQ_LCD_CursorSet(0, 0);
2236
    //                   <-------------------------------------->
2237
    //                   0123456789012345678901234567890123456789
306 tk 2238
    SEQ_LCD_PrintString("Menu Shortcuts:");
2239
    SEQ_LCD_PrintSpaces(25 + 40);
2240
    SEQ_LCD_CursorSet(0, 1);
2241
    SEQ_LCD_PrintString(UI_SHORTCUT_STR); // defined in seq_ui_pages.inc
2242
  } else {
2243
    // perform high priority LCD update request
2244
    if( ui_lcd_callback != NULL )
2245
      ui_lcd_callback(1); // high_prio
167 tk 2246
 
306 tk 2247
    // perform low priority LCD update request if requested
2248
    if( seq_ui_display_update_req ) {
2249
      seq_ui_display_update_req = 0; // clear request
328 tk 2250
 
2251
      // ensure that selections are matching with track constraints
2252
      SEQ_UI_CheckSelections();
2253
 
306 tk 2254
      if( ui_lcd_callback != NULL )
2255
    ui_lcd_callback(0); // no high_prio
2256
    }
134 tk 2257
  }
2258
 
353 tk 2259
  // transfer all changed characters to LCD
2260
  SEQ_UI_LCD_Update();
2261
 
2262
  return 0; // no error
2263
}
2264
 
2265
 
2266
/////////////////////////////////////////////////////////////////////////////
2267
// Called from SEQ_UI_LCD_Handler(), but optionally also from other tasks
2268
// to update the LCD screen immediately
2269
/////////////////////////////////////////////////////////////////////////////
1117 tk 2270
// for newer GCC versions it's important to declare constant arrays outside a function
2271
//                                             00112233
2272
static const char animation_l_arrows[2*4+1] = "   >>>> ";
2273
//                                             00112233
2274
static const char animation_r_arrows[2*4+1] = "  < << <";
2275
//                                               00112233
2276
static const char animation_l_brackets[2*4+1] = "   )))) ";
2277
//                                               00112233
2278
static const char animation_r_brackets[2*4+1] = "  ( (( (";
2279
//                                            00112233
2280
static const char animation_l_stars[2*4+1] = "   **** ";
2281
//                                            00112233
2282
static const char animation_r_stars[2*4+1] = "  * ** *";
353 tk 2283
s32 SEQ_UI_LCD_Update(void)
2284
{
625 tk 2285
  // special handling in remote client mode
1316 tk 2286
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT ) {
626 tk 2287
    MIOS32_IRQ_Disable();
1316 tk 2288
    u8 force = seq_midi_sysex_remote_force_lcd_update;
2289
    seq_midi_sysex_remote_force_lcd_update = 0;
626 tk 2290
    MIOS32_IRQ_Enable();
2291
    return SEQ_LCD_Update(force);
625 tk 2292
  }
2293
 
596 tk 2294
  // if UI message active: copy over the text
2295
  if( ui_msg_ctr ) {
774 tk 2296
    char *animation_l_ptr;
2297
    char *animation_r_ptr;
596 tk 2298
    u8 msg_x = 0;
2299
    u8 right_aligned = 0;
740 tk 2300
    u8 disable_message = 0;
299 tk 2301
 
596 tk 2302
    switch( ui_msg_type ) {
2303
      case SEQ_UI_MSG_SDCARD: {
1117 tk 2304
    animation_l_ptr = (char *)animation_l_arrows;
2305
    animation_r_ptr = (char *)animation_r_arrows;
596 tk 2306
    msg_x = 0; // MEMO: print such important information at first LCD for the case the user hasn't connected the second LCD yet
2307
    right_aligned = 0;
2308
      } break;
2309
 
756 tk 2310
      case SEQ_UI_MSG_DELAYED_ACTION:
2311
      case SEQ_UI_MSG_DELAYED_ACTION_R: {
1117 tk 2312
    animation_l_ptr = (char *)animation_l_brackets;
2313
    animation_r_ptr = (char *)animation_r_brackets;
756 tk 2314
    if( ui_msg_type == SEQ_UI_MSG_DELAYED_ACTION_R ) {
2315
      msg_x = 40; // right LCD
2316
      right_aligned = 0;
2317
    } else {
2318
      msg_x = 39; // left LCD
2319
      right_aligned = 1;
2320
    }
740 tk 2321
 
2322
    if( ui_delayed_action_callback == NULL ) {
2323
      disable_message = 1; // button has been depressed before delay
2324
    } else {
2325
      int seconds = (ui_delayed_action_ctr / 1000) + 1;
2326
      if( seconds == 1 )
2327
        sprintf(ui_msg[0], "Hold for 1 second ");
2328
      else
2329
        sprintf(ui_msg[0], "Hold for %d seconds", seconds);
2330
    }
2331
      } break;
2332
 
741 tk 2333
      case SEQ_UI_MSG_USER_R: {
1117 tk 2334
    animation_l_ptr = (char *)animation_l_stars;
2335
    animation_r_ptr = (char *)animation_r_stars;
741 tk 2336
    msg_x = 40; // right display
2337
    right_aligned = 0;
2338
      } break;
2339
 
596 tk 2340
      default: {
1117 tk 2341
    animation_l_ptr = (char *)animation_l_stars;
2342
    animation_r_ptr = (char *)animation_r_stars;
596 tk 2343
    msg_x = 39;
2344
    right_aligned = 1;
2345
      } break;
2346
 
2347
    }
2348
 
740 tk 2349
    if( !disable_message ) {
2350
      int anum = (ui_msg_ctr % 1000) / 250;
596 tk 2351
 
740 tk 2352
      int len[2];
2353
      len[0] = strlen((char *)ui_msg[0]);
2354
      len[1] = strlen((char *)ui_msg[1]);
2355
      int len_max = len[0];
2356
      if( len[1] > len_max )
2357
    len_max = len[1];
596 tk 2358
 
740 tk 2359
      if( right_aligned )
2360
    msg_x -= (9 + len_max);
596 tk 2361
 
740 tk 2362
      int line;
2363
      for(line=0; line<2; ++line) {
2364
    SEQ_LCD_CursorSet(msg_x, line);
596 tk 2365
 
740 tk 2366
    // ensure that both lines are padded with same number of spaces
2367
    int end_pos = len[line];
2368
    while( end_pos < len_max )
2369
      ui_msg[line][end_pos++] = ' ';
2370
    ui_msg[line][end_pos] = 0;
2371
 
2372
    SEQ_LCD_PrintFormattedString(" %c%c| %s |%c%c ",
2373
                     *(animation_l_ptr + 2*anum + 0), *(animation_l_ptr + 2*anum + 1),
2374
                     (char *)ui_msg[line],
2375
                     *(animation_r_ptr + 2*anum + 0), *(animation_r_ptr + 2*anum + 1));
2376
      }
299 tk 2377
    }
2378
  }
2379
 
637 tk 2380
  // MSD USB notification at right corner if not in Disk page
2381
  // to warn user that USB MIDI is disabled and seq performance is bad now!
638 tk 2382
  if( (TASK_MSD_EnableGet() > 0) && ui_page != SEQ_UI_PAGE_DISK ) {
637 tk 2383
    SEQ_LCD_CursorSet(80-11, 0);
2384
    if( ui_cursor_flash ) SEQ_LCD_PrintSpaces(13); else SEQ_LCD_PrintString(" [MSD USB] ");
2385
    SEQ_LCD_CursorSet(80-11, 1);
2386
    char str[5];
2387
    TASK_MSD_FlagStrGet(str);
2388
    if( ui_cursor_flash ) SEQ_LCD_PrintSpaces(13); else SEQ_LCD_PrintFormattedString(" [ %s  ] ", str);
2389
  }
596 tk 2390
 
278 tk 2391
  // transfer all changed characters to LCD
353 tk 2392
  // SEQ_LCD_Update provides a MUTEX handling to allow updates from different tasks
2393
  return SEQ_LCD_Update(0);
134 tk 2394
}
2395
 
2396
 
2397
/////////////////////////////////////////////////////////////////////////////
2398
// Update all LEDs
2399
// Usually called from background task
2400
/////////////////////////////////////////////////////////////////////////////
2401
s32 SEQ_UI_LED_Handler(void)
2402
{
626 tk 2403
  static u8 remote_led_sr[SEQ_LED_NUM_SR];
2404
 
625 tk 2405
  // ignore in remote client mode
1316 tk 2406
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2407
    return 0; // no error
2408
 
1044 tk 2409
  // ignore as long as hardware config hasn't been read
496 tk 2410
  if( !SEQ_FILE_HW_ConfigLocked() )
2411
    return -1;
2412
 
134 tk 2413
  // track LEDs
987 tk 2414
  // in pattern page: track buttons are used as group buttons
2415
  if( ui_page == SEQ_UI_PAGE_PATTERN ) {
2416
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (ui_selected_group == 0));
2417
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (ui_selected_group == 1));
2418
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (ui_selected_group == 2));
2419
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (ui_selected_group == 3));
2420
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
2421
    // in song page: track and group buttons are used to select the cursor position
2422
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (ui_selected_item == 3));
2423
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (ui_selected_item == 4));
2424
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (ui_selected_item == 5));
2425
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (ui_selected_item == 6));
2426
  } else {
2427
    u8 selected_tracks = ui_selected_tracks >> (4*ui_selected_group);
2428
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (selected_tracks & (1 << 0)));
2429
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (selected_tracks & (1 << 1)));
2430
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (selected_tracks & (1 << 2)));
2431
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (selected_tracks & (1 << 3)));
2432
  }
2433
 
678 tk 2434
  SEQ_LED_PinSet(seq_hwcfg_led.track_sel, ui_page == SEQ_UI_PAGE_TRACKSEL);
134 tk 2435
 
2436
  // parameter layer LEDs
987 tk 2437
  // in song page: layer buttons are used to select the cursor position
2438
  if( ui_page == SEQ_UI_PAGE_SONG ) {
2439
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], ui_selected_item == 0);
2440
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], ui_selected_item == 1);
2441
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], ui_selected_item == 2);
2442
  } else {
2443
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], (ui_selected_par_layer == 0));
2444
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], (ui_selected_par_layer == 1));
2445
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], (ui_selected_par_layer >= 2) || seq_ui_button_state.PAR_LAYER_SEL);
2446
  }
678 tk 2447
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer_sel, ui_page == SEQ_UI_PAGE_PARSEL);
134 tk 2448
 
2449
  // group LEDs
987 tk 2450
  // in song page: track and group buttons are used to select the cursor position
2451
  if( ui_page == SEQ_UI_PAGE_SONG ) {
2452
    SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_item == 3));
2453
    SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_item == 4));
2454
    SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_item == 5));
2455
    SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_item == 6));
2456
  } else {
2457
    SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_group == 0));
2458
    SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_group == 1));
2459
    SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_group == 2));
2460
    SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_group == 3));
2461
  }
134 tk 2462
 
2463
  // trigger layer LEDs
492 tk 2464
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[0], (ui_selected_trg_layer == 0));
2465
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[1], (ui_selected_trg_layer == 1));
2466
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[2], (ui_selected_trg_layer >= 2) || seq_ui_button_state.TRG_LAYER_SEL);
678 tk 2467
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer_sel, ui_page == SEQ_UI_PAGE_TRGSEL);
134 tk 2468
 
2469
  // remaining LEDs
492 tk 2470
  SEQ_LED_PinSet(seq_hwcfg_led.edit, ui_page == SEQ_UI_PAGE_EDIT);
2471
  SEQ_LED_PinSet(seq_hwcfg_led.mute, ui_page == SEQ_UI_PAGE_MUTE);
2472
  SEQ_LED_PinSet(seq_hwcfg_led.pattern, ui_page == SEQ_UI_PAGE_PATTERN);
399 tk 2473
  if( SEQ_SONG_ActiveGet() )
492 tk 2474
    SEQ_LED_PinSet(seq_hwcfg_led.song, 1);
399 tk 2475
  else
492 tk 2476
    SEQ_LED_PinSet(seq_hwcfg_led.song, ui_cursor_flash ? 0 : (ui_page == SEQ_UI_PAGE_SONG));
743 tk 2477
  SEQ_LED_PinSet(seq_hwcfg_led.mixer, ui_page == SEQ_UI_PAGE_MIXER);
1119 tk 2478
 
2479
  SEQ_LED_PinSet(seq_hwcfg_led.track_mode, ui_page == SEQ_UI_PAGE_TRKMODE);
2480
  SEQ_LED_PinSet(seq_hwcfg_led.track_groove, ui_page == SEQ_UI_PAGE_TRKGRV);
2481
  SEQ_LED_PinSet(seq_hwcfg_led.track_length, ui_page == SEQ_UI_PAGE_TRKLEN);
2482
  SEQ_LED_PinSet(seq_hwcfg_led.track_direction, ui_page == SEQ_UI_PAGE_TRKDIR);
2483
  SEQ_LED_PinSet(seq_hwcfg_led.track_morph, ui_page == SEQ_UI_PAGE_TRKMORPH);
2484
  SEQ_LED_PinSet(seq_hwcfg_led.track_transpose, ui_page == SEQ_UI_PAGE_TRKTRAN);
134 tk 2485
 
492 tk 2486
  SEQ_LED_PinSet(seq_hwcfg_led.solo, seq_ui_button_state.SOLO);
2487
  SEQ_LED_PinSet(seq_hwcfg_led.fast, seq_ui_button_state.FAST_ENCODERS);
1121 tk 2488
  SEQ_LED_PinSet(seq_hwcfg_led.fast2, seq_ui_button_state.FAST2_ENCODERS);
492 tk 2489
  SEQ_LED_PinSet(seq_hwcfg_led.all, seq_ui_button_state.CHANGE_ALL_STEPS);
134 tk 2490
 
1206 tk 2491
  u8 seq_running = SEQ_BPM_IsRunning() && (!seq_core_slaveclk_mute || ((seq_core_state.ref_step & 3) == 0));
2492
  // 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
2493
  SEQ_LED_PinSet(seq_hwcfg_led.play, seq_running);
2494
  SEQ_LED_PinSet(seq_hwcfg_led.stop, !seq_running && !ui_seq_pause);
2495
  SEQ_LED_PinSet(seq_hwcfg_led.pause, ui_seq_pause && (!seq_core_slaveclk_mute || ui_cursor_flash));
240 tk 2496
 
492 tk 2497
  SEQ_LED_PinSet(seq_hwcfg_led.rew, seq_ui_button_state.REW);
2498
  SEQ_LED_PinSet(seq_hwcfg_led.fwd, seq_ui_button_state.FWD);
596 tk 2499
 
2500
  SEQ_LED_PinSet(seq_hwcfg_led.loop, seq_core_state.LOOP);
951 tk 2501
  SEQ_LED_PinSet(seq_hwcfg_led.follow, seq_core_state.FOLLOW);
134 tk 2502
 
678 tk 2503
  SEQ_LED_PinSet(seq_hwcfg_led.step_view, ui_page == SEQ_UI_PAGE_STEPSEL);
134 tk 2504
 
591 tk 2505
  SEQ_LED_PinSet(seq_hwcfg_led.select, seq_ui_button_state.SELECT_PRESSED);
492 tk 2506
  SEQ_LED_PinSet(seq_hwcfg_led.menu, seq_ui_button_state.MENU_PRESSED);
1203 tk 2507
  SEQ_LED_PinSet(seq_hwcfg_led.bookmark, ui_page == SEQ_UI_PAGE_BOOKMARKS);
134 tk 2508
 
596 tk 2509
  // handle double functions
2510
  if( seq_ui_button_state.MENU_PRESSED ) {
2511
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_core_state.LOOP);
951 tk 2512
    SEQ_LED_PinSet(seq_hwcfg_led.exit, seq_core_state.FOLLOW);
596 tk 2513
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.EXT_RESTART_REQ);
2514
  } else {
2515
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_ui_button_state.SCRUB);
951 tk 2516
    SEQ_LED_PinSet(seq_hwcfg_led.exit, ui_page == SEQ_UI_PAGE_MENU);
596 tk 2517
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.METRONOME);
2518
  }
2519
 
1313 tk 2520
  SEQ_LED_PinSet(seq_hwcfg_led.record, seq_record_state.ENABLED);
1219 tk 2521
  SEQ_LED_PinSet(seq_hwcfg_led.live, ui_page == SEQ_UI_PAGE_TRKLIVE);
630 tk 2522
 
492 tk 2523
  SEQ_LED_PinSet(seq_hwcfg_led.utility, ui_page == SEQ_UI_PAGE_UTIL);
2524
  SEQ_LED_PinSet(seq_hwcfg_led.copy, seq_ui_button_state.COPY);
2525
  SEQ_LED_PinSet(seq_hwcfg_led.paste, seq_ui_button_state.PASTE);
1014 tk 2526
  SEQ_LED_PinSet(seq_hwcfg_led.undo, seq_ui_button_state.UNDO);
492 tk 2527
  SEQ_LED_PinSet(seq_hwcfg_led.clear, seq_ui_button_state.CLEAR);
240 tk 2528
 
513 tk 2529
  SEQ_LED_PinSet(seq_hwcfg_led.tap_tempo, seq_ui_button_state.TAP_TEMPO);
678 tk 2530
  SEQ_LED_PinSet(seq_hwcfg_led.tempo_preset, ui_page == SEQ_UI_PAGE_BPM_PRESETS);
524 tk 2531
  SEQ_LED_PinSet(seq_hwcfg_led.ext_restart, seq_core_state.EXT_RESTART_REQ);
240 tk 2532
 
492 tk 2533
  SEQ_LED_PinSet(seq_hwcfg_led.down, seq_ui_button_state.DOWN);
2534
  SEQ_LED_PinSet(seq_hwcfg_led.up, seq_ui_button_state.UP);
240 tk 2535
 
167 tk 2536
 
1044 tk 2537
  // in MENU page: overrule GP LEDs as long as MENU button is pressed/active
306 tk 2538
  if( seq_ui_button_state.MENU_PRESSED ) {
2539
    if( ui_cursor_flash ) // if flashing flag active: no LED flag set
2540
      ui_gp_leds = 0x0000;
2541
    else {
2542
      int i;
2543
      u16 new_ui_gp_leds = 0x0000;
2544
      for(i=0; i<16; ++i)
2545
    if( ui_page == ui_shortcut_menu_pages[i] )
2546
      new_ui_gp_leds |= (1 << i);
2547
      ui_gp_leds = new_ui_gp_leds;
2548
    }
2549
  } else {
2550
    // note: the background function is permanently interrupted - therefore we write the GP pattern
2551
    // into a temporary variable, and take it over once completed
2552
    u16 new_ui_gp_leds = 0x0000;
2553
    // request GP LED values from current menu page
2554
    // will be transfered to DOUT registers in SEQ_UI_LED_Handler_Periodic
2555
    new_ui_gp_leds = 0x0000;
206 tk 2556
 
306 tk 2557
    if( ui_led_callback != NULL )
2558
      ui_led_callback(&new_ui_gp_leds);
167 tk 2559
 
306 tk 2560
    ui_gp_leds = new_ui_gp_leds;
2561
  }
2562
 
1020 tk 2563
  // update BLM LEDs
2564
  SEQ_BLM_LED_Update();
524 tk 2565
 
626 tk 2566
  // send LED changes in remote server mode
1316 tk 2567
  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 2568
    int first_sr = -1;
2569
    int last_sr = -1;
2570
    int sr;
2571
    for(sr=0; sr<SEQ_LED_NUM_SR; ++sr) {
2572
      u8 value = SEQ_LED_SRGet(sr);
2573
      if( value != remote_led_sr[sr] ) {
2574
    if( first_sr == -1 )
2575
      first_sr = sr;
2576
    last_sr = sr;
2577
    remote_led_sr[sr] = value;
2578
      }
2579
    }
2580
 
2581
    MIOS32_IRQ_Disable();
1316 tk 2582
    if( seq_midi_sysex_remote_force_led_update ) {
626 tk 2583
      first_sr = 0;
2584
      last_sr = SEQ_LED_NUM_SR-1;
2585
    }
1316 tk 2586
    seq_midi_sysex_remote_force_led_update = 0;
626 tk 2587
    MIOS32_IRQ_Enable();
2588
 
2589
    if( first_sr >= 0 )
2590
      SEQ_MIDI_SYSEX_REMOTE_Server_SendLED(first_sr, (u8 *)&remote_led_sr[first_sr], last_sr-first_sr+1);
2591
  }
2592
 
2593
 
134 tk 2594
  return 0; // no error
2595
}
2596
 
2597
 
2598
/////////////////////////////////////////////////////////////////////////////
2599
// updates high-prio LED functions (GP LEDs and Beat LED)
168 tk 2600
// called each mS
134 tk 2601
/////////////////////////////////////////////////////////////////////////////
2602
s32 SEQ_UI_LED_Handler_Periodic()
2603
{
625 tk 2604
  // ignore in remote client mode
1316 tk 2605
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2606
    return 0; // no error
2607
 
1044 tk 2608
  // ignore as long as hardware config hasn't been read
496 tk 2609
  if( !SEQ_FILE_HW_ConfigLocked() )
2610
    return -1;
2611
 
752 tk 2612
  // GP LEDs are updated when ui_gp_leds has changed
134 tk 2613
  static u16 prev_ui_gp_leds = 0x0000;
2614
 
755 tk 2615
  // beat LED
193 tk 2616
  u8 sequencer_running = SEQ_BPM_IsRunning();
1068 tk 2617
  u8 beat_led_on = sequencer_running && ((seq_core_state.ref_step & 3) == 0);
2618
  SEQ_LED_PinSet(seq_hwcfg_led.beat, beat_led_on);
134 tk 2619
 
1068 tk 2620
  // mirror to status LED (inverted, so that LED is normaly on)
2621
  MIOS32_BOARD_LED_Set(0xffffffff, beat_led_on ? 0 : 1);
755 tk 2622
 
1336 tk 2623
  // MIDI IN/OUT LEDs
2624
  SEQ_LED_PinSet(seq_hwcfg_led.midi_in_combined, seq_midi_port_in_combined_ctr);
2625
  SEQ_LED_PinSet(seq_hwcfg_led.midi_out_combined, seq_midi_port_out_combined_ctr);  
1068 tk 2626
 
755 tk 2627
  // don't continue if no new step has been generated and GP LEDs haven't changed
1044 tk 2628
  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 2629
    return 0;
2630
  seq_core_step_update_req = 0; // requested from SEQ_CORE if any step has been changed
2631
  prev_ui_gp_leds = ui_gp_leds; // take over new GP pattern
2632
 
134 tk 2633
  // for song position marker (supports 16 LEDs, check for selected step view)
2634
  u16 pos_marker_mask = 0x0000;
325 tk 2635
  u8 visible_track = SEQ_UI_VisibleTrackGet();
2636
  u8 played_step = seq_core_trk[visible_track].step;
754 tk 2637
 
1206 tk 2638
  if( seq_core_slaveclk_mute != SEQ_CORE_SLAVECLK_MUTE_Enabled ) { // Off and OffOnNextMeasure
2639
    if( seq_ui_button_state.STEP_VIEW ) {
2640
      // if STEP_VIEW button pressed: pos marker correlated to zoom ratio
2641
      if( sequencer_running )
2642
    pos_marker_mask = 1 << (played_step / (SEQ_TRG_NumStepsGet(visible_track)/16));
2643
    } else {
2644