Subversion Repositories svn.mios32

Rev

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