Subversion Repositories svn.mios32

Rev

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