Subversion Repositories svn.mios32

Rev

Rev 1713 | Rev 1787 | 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 1751 2013-04-16 19:55:51Z 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
 
1119 tk 1694
static s32 SEQ_UI_Button_TrackMode(s32 depressed)
544 tk 1695
{
1696
  if( depressed ) return -1; // ignore when button depressed
1697
 
1119 tk 1698
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMODE);
544 tk 1699
 
1700
  return 0; // no error
1701
}
1702
 
1119 tk 1703
static s32 SEQ_UI_Button_TrackGroove(s32 depressed)
544 tk 1704
{
1705
  if( depressed ) return -1; // ignore when button depressed
1706
 
1119 tk 1707
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKGRV);
1708
 
1709
  return 0; // no error
1710
}
1711
 
1712
static s32 SEQ_UI_Button_TrackLength(s32 depressed)
1713
{
1714
  if( depressed ) return -1; // ignore when button depressed
1715
 
1716
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKLEN);
1717
 
1718
  return 0; // no error
1719
}
1720
 
1721
static s32 SEQ_UI_Button_TrackDirection(s32 depressed)
1722
{
1723
  if( depressed ) return -1; // ignore when button depressed
1724
 
1725
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKDIR);
1726
 
1727
  return 0; // no error
1728
}
1729
 
1730
static s32 SEQ_UI_Button_TrackMorph(s32 depressed)
1731
{
1732
  if( depressed ) return -1; // ignore when button depressed
1733
 
1734
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMORPH);
1735
 
1736
  return 0; // no error
1737
}
1738
 
1739
static s32 SEQ_UI_Button_TrackTranspose(s32 depressed)
1740
{
1741
  if( depressed ) return -1; // ignore when button depressed
1742
 
544 tk 1743
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKTRAN);
1744
 
1745
  return 0; // no error
1746
}
1747
 
1748
 
742 tk 1749
// only used by keyboard remote function
1750
static s32 SEQ_UI_Button_ToggleGate(s32 depressed)
1751
{
1752
  if( depressed ) return -1; // ignore when button depressed
544 tk 1753
 
742 tk 1754
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1755
  u8 gate = SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? 0 : 1;
1756
  SEQ_TRG_GateSet(visible_track, ui_selected_step, ui_selected_instrument, gate);
544 tk 1757
 
742 tk 1758
  return 0; // no error
1759
}
1760
 
1349 tk 1761
static s32 SEQ_UI_Button_FootSwitch(s32 depressed)
1762
{
1763
  // static variables (only used here, therefore local)
1764
  static u32 fs_time_control = 0; // timestamp of last operation
1765
  static u8  fs_mode = 0; // mode
742 tk 1766
 
1349 tk 1767
  // this is used as a constant value
1768
  u32 fs_time_delay = 1000; // mS - should this be configurable?
742 tk 1769
 
1349 tk 1770
 
1771
  // PUNCH_IN, PUNCH_OUT and Delete track data control
1772
  if( !depressed ) {
1773
    if( ( fs_time_control > (seq_core_timestamp_ms - fs_time_delay) ) && ( fs_time_control != 0 ) )
1774
    {
1775
      // that confirms the delete function
1776
      fs_mode = 1; // delete
1777
    } else {
1778
      // start time in count
1779
      fs_time_control = seq_core_timestamp_ms;
1780
    }
1781
  } else {
1782
    // if time pressed is less than fs_time_delay miliseconds, we got a possible delete function activation
1783
    if( fs_time_control > (seq_core_timestamp_ms - fs_time_delay) )
1784
    {
1785
      switch( fs_mode ) {
1786
      case 1: { // delete
1787
        SEQ_UI_Button_Clear_Track(0);
1788
        fs_mode = 0; // back to normal mode, later we would increment the value
1789
      } break;
1790
      default:
1791
        fs_mode = 0; // for the case that an invalid mode is selected
1792
      }
1793
 
1794
      fs_time_control = seq_core_timestamp_ms;
1795
    }
1796
  }
1797
 
1798
  if( depressed ) {
1799
    // disable recording
1800
    seq_record_state.ENABLED = 0;
1801
  } else {
1802
    // enable recording
1803
    seq_record_state.ENABLED = 1;
1804
    seq_record_state.ARMED_TRACKS = ui_selected_tracks; // not used yet, just preparation for future changes
1805
  }
1806
 
1807
  return 0; // no error
1808
}
1809
 
1810
 
134 tk 1811
/////////////////////////////////////////////////////////////////////////////
1812
// Button handler
1813
/////////////////////////////////////////////////////////////////////////////
1814
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
1815
{
492 tk 1816
  int i;
1817
 
625 tk 1818
  // send MIDI event in remote mode and exit
1316 tk 1819
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 1820
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendButton(pin, pin_value);
1821
 
1044 tk 1822
  // ignore as long as hardware config hasn't been read
496 tk 1823
  if( !SEQ_FILE_HW_ConfigLocked() )
1824
    return -1;
1825
 
740 tk 1826
  // ignore during a backup or format is created
1827
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1828
    return -1;
1829
 
328 tk 1830
  // ensure that selections are matching with track constraints
1831
  SEQ_UI_CheckSelections();
1832
 
492 tk 1833
  // request display update
1834
  seq_ui_display_update_req = 1;
134 tk 1835
 
596 tk 1836
  // stop current message if (new) button has been pressed
1837
  if( pin_value == 0 )
1838
    SEQ_UI_MsgStop();
134 tk 1839
 
596 tk 1840
 
492 tk 1841
  // MEMO: we could also use a jump table with references to the functions
1842
  // here, but this "spagetthi code" simplifies the configuration and
1843
  // the resulting ASM doesn't look that bad!
168 tk 1844
 
492 tk 1845
  for(i=0; i<SEQ_HWCFG_NUM_GP; ++i)
1846
    if( pin == seq_hwcfg_button.gp[i] )
1847
      return SEQ_UI_Button_GP(pin_value, i);
134 tk 1848
 
492 tk 1849
  for(i=0; i<SEQ_HWCFG_NUM_TRACK; ++i)
1850
    if( pin == seq_hwcfg_button.track[i] )
1851
      return SEQ_UI_Button_Track(pin_value, i);
1146 tk 1852
 
1853
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_TRACK; ++i)
1854
    if( pin == seq_hwcfg_button.direct_track[i] )
1855
      return SEQ_UI_Button_DirectTrack(pin_value, i);
1856
 
1205 tk 1857
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_BOOKMARK; ++i)
1858
    if( pin == seq_hwcfg_button.direct_bookmark[i] )
1859
      return SEQ_UI_Button_DirectBookmark(pin_value, i);
1860
 
513 tk 1861
  if( pin == seq_hwcfg_button.track_sel )
1862
    return SEQ_UI_Button_TrackSel(pin_value);
134 tk 1863
 
492 tk 1864
  for(i=0; i<SEQ_HWCFG_NUM_GROUP; ++i)
1865
    if( pin == seq_hwcfg_button.group[i] )
1866
      return SEQ_UI_Button_Group(pin_value, i);
134 tk 1867
 
492 tk 1868
  for(i=0; i<SEQ_HWCFG_NUM_PAR_LAYER; ++i)
1869
    if( pin == seq_hwcfg_button.par_layer[i] )
1870
      return SEQ_UI_Button_ParLayer(pin_value, i);
513 tk 1871
  if( pin == seq_hwcfg_button.par_layer_sel )
1872
    return SEQ_UI_Button_ParLayerSel(pin_value);
134 tk 1873
 
492 tk 1874
  for(i=0; i<SEQ_HWCFG_NUM_TRG_LAYER; ++i)
1875
    if( pin == seq_hwcfg_button.trg_layer[i] )
1876
      return SEQ_UI_Button_TrgLayer(pin_value, i);
513 tk 1877
  if( pin == seq_hwcfg_button.trg_layer_sel )
1878
    return SEQ_UI_Button_TrgLayerSel(pin_value);
134 tk 1879
 
492 tk 1880
  if( pin == seq_hwcfg_button.left )
1881
    return SEQ_UI_Button_Left(pin_value);
1882
  if( pin == seq_hwcfg_button.right )
1883
    return SEQ_UI_Button_Right(pin_value);
1884
  if( pin == seq_hwcfg_button.down )
1885
    return SEQ_UI_Button_Down(pin_value);
1886
  if( pin == seq_hwcfg_button.up )
1887
    return SEQ_UI_Button_Up(pin_value);
134 tk 1888
 
492 tk 1889
  if( pin == seq_hwcfg_button.scrub )
1890
    return SEQ_UI_Button_Scrub(pin_value);
1891
  if( pin == seq_hwcfg_button.metronome )
1892
    return SEQ_UI_Button_Metronome(pin_value);
134 tk 1893
 
630 tk 1894
  if( pin == seq_hwcfg_button.record )
1895
    return SEQ_UI_Button_Record(pin_value);
1219 tk 1896
  if( pin == seq_hwcfg_button.live )
1897
    return SEQ_UI_Button_Live(pin_value);
630 tk 1898
 
492 tk 1899
  if( pin == seq_hwcfg_button.stop )
1900
    return SEQ_UI_Button_Stop(pin_value);
1901
  if( pin == seq_hwcfg_button.pause )
1902
    return SEQ_UI_Button_Pause(pin_value);
1903
  if( pin == seq_hwcfg_button.play )
1904
    return SEQ_UI_Button_Play(pin_value);
1905
  if( pin == seq_hwcfg_button.rew )
1906
    return SEQ_UI_Button_Rew(pin_value);
1907
  if( pin == seq_hwcfg_button.fwd )
1908
    return SEQ_UI_Button_Fwd(pin_value);
596 tk 1909
  if( pin == seq_hwcfg_button.loop )
1910
    return SEQ_UI_Button_Loop(pin_value);
973 tk 1911
  if( pin == seq_hwcfg_button.follow )
1912
    return SEQ_UI_Button_Follow(pin_value);
134 tk 1913
 
492 tk 1914
  if( pin == seq_hwcfg_button.utility )
1915
    return SEQ_UI_Button_Utility(pin_value);
1916
  if( pin == seq_hwcfg_button.copy )
1917
    return SEQ_UI_Button_Copy(pin_value);
1918
  if( pin == seq_hwcfg_button.paste )
1919
    return SEQ_UI_Button_Paste(pin_value);
1920
  if( pin == seq_hwcfg_button.clear )
1921
    return SEQ_UI_Button_Clear(pin_value);
1014 tk 1922
  if( pin == seq_hwcfg_button.undo )
1923
    return SEQ_UI_Button_Undo(pin_value);
134 tk 1924
 
492 tk 1925
  if( pin == seq_hwcfg_button.menu )
1926
    return SEQ_UI_Button_Menu(pin_value);
1203 tk 1927
  if( pin == seq_hwcfg_button.bookmark )
1928
    return SEQ_UI_Button_Bookmark(pin_value);
492 tk 1929
  if( pin == seq_hwcfg_button.select )
1930
    return SEQ_UI_Button_Select(pin_value);
1931
  if( pin == seq_hwcfg_button.exit )
1932
    return SEQ_UI_Button_Exit(pin_value);
134 tk 1933
 
513 tk 1934
  if( pin == seq_hwcfg_button.tap_tempo )
1935
    return SEQ_UI_Button_TapTempo(pin_value);
1936
  if( pin == seq_hwcfg_button.tempo_preset )
1937
    return SEQ_UI_Button_TempoPreset(pin_value);
524 tk 1938
  if( pin == seq_hwcfg_button.ext_restart )
1939
    return SEQ_UI_Button_ExtRestart(pin_value);
134 tk 1940
 
492 tk 1941
  if( pin == seq_hwcfg_button.edit )
1942
    return SEQ_UI_Button_Edit(pin_value);
1943
  if( pin == seq_hwcfg_button.mute )
1944
    return SEQ_UI_Button_Mute(pin_value);
1945
  if( pin == seq_hwcfg_button.pattern )
1946
    return SEQ_UI_Button_Pattern(pin_value);
1947
  if( pin == seq_hwcfg_button.song )
1948
    return SEQ_UI_Button_Song(pin_value);
134 tk 1949
 
492 tk 1950
  if( pin == seq_hwcfg_button.solo )
1951
    return SEQ_UI_Button_Solo(pin_value);
1952
  if( pin == seq_hwcfg_button.fast )
1953
    return SEQ_UI_Button_Fast(pin_value);
1121 tk 1954
  if( pin == seq_hwcfg_button.fast2 )
1955
    return SEQ_UI_Button_Fast2(pin_value);
492 tk 1956
  if( pin == seq_hwcfg_button.all )
1957
    return SEQ_UI_Button_All(pin_value);
134 tk 1958
 
492 tk 1959
  if( pin == seq_hwcfg_button.step_view )
1960
    return SEQ_UI_Button_StepView(pin_value);
134 tk 1961
 
544 tk 1962
  if( pin == seq_hwcfg_button.mixer )
1963
    return SEQ_UI_Button_Mixer(pin_value);
1964
 
1119 tk 1965
  if( pin == seq_hwcfg_button.track_mode )
1966
    return SEQ_UI_Button_TrackMode(pin_value);
1967
  if( pin == seq_hwcfg_button.track_groove )
1968
    return SEQ_UI_Button_TrackGroove(pin_value);
1969
  if( pin == seq_hwcfg_button.track_length )
1970
    return SEQ_UI_Button_TrackLength(pin_value);
1971
  if( pin == seq_hwcfg_button.track_direction )
1972
    return SEQ_UI_Button_TrackDirection(pin_value);
1973
  if( pin == seq_hwcfg_button.track_morph )
1974
    return SEQ_UI_Button_TrackMorph(pin_value);
1975
  if( pin == seq_hwcfg_button.track_transpose )
1976
    return SEQ_UI_Button_TrackTranspose(pin_value);
1349 tk 1977
  if( pin == seq_hwcfg_button.footswitch )
1978
    return SEQ_UI_Button_FootSwitch(pin_value);
1454 midilab 1979
  if( pin == seq_hwcfg_button.pattern_remix )
1980
    return SEQ_UI_Button_Pattern_Remix(pin_value);
625 tk 1981
  // always print debugging message
1982
#if 1
1081 tk 1983
  MUTEX_MIDIOUT_TAKE;
1984
  DEBUG_MSG("[SEQ_UI_Button_Handler] Button SR:%d, Pin:%d not mapped, it has been %s.\n",
1985
        (pin >> 3) + 1,
1986
        pin & 7,
1987
        pin_value ? "depressed" : "pressed");
1988
  MUTEX_MIDIOUT_GIVE;
625 tk 1989
#endif
1990
 
492 tk 1991
  return -1; // button not mapped
134 tk 1992
}
1993
 
1994
 
1995
/////////////////////////////////////////////////////////////////////////////
524 tk 1996
// BLM Button handler
1997
/////////////////////////////////////////////////////////////////////////////
1998
s32 SEQ_UI_BLM_Button_Handler(u32 row, u32 pin, u32 pin_value)
1999
{
625 tk 2000
  // send MIDI event in remote mode and exit
1316 tk 2001
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2002
    return SEQ_MIDI_SYSEX_REMOTE_Client_Send_BLM_Button(row, pin, pin_value);
2003
 
1044 tk 2004
  // ignore as long as hardware config hasn't been read
524 tk 2005
  if( !SEQ_FILE_HW_ConfigLocked() )
2006
    return -1;
2007
 
740 tk 2008
  // ignore during a backup or format is created
2009
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 2010
    return -1;
2011
 
524 tk 2012
  if( row >= SEQ_CORE_NUM_TRACKS_PER_GROUP )
2013
    return -1; // more than 4 tracks not supported (yet) - could be done in this function w/o much effort
2014
 
2015
  if( pin >= 16 )
2016
    return -1; // more than 16 step buttons not supported (yet) - could be done by selecting the step view
2017
 
2018
  // select track depending on row
2019
  ui_selected_tracks = 1 << (row + 4*ui_selected_group);
2020
 
2021
  // ensure that selections are matching with track constraints
2022
  SEQ_UI_CheckSelections();
2023
 
2024
  // request display update
2025
  seq_ui_display_update_req = 1;
2026
 
2027
  // emulate general purpose button
758 tk 2028
  if( seq_hwcfg_blm.buttons_no_ui ) {
763 tk 2029
    s32 status = SEQ_UI_EDIT_Button_Handler(pin, pin_value);
758 tk 2030
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
2031
    return status;
763 tk 2032
  }
2033
 
2034
  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 2035
}
2036
 
2037
 
2038
/////////////////////////////////////////////////////////////////////////////
134 tk 2039
// Encoder handler
2040
/////////////////////////////////////////////////////////////////////////////
2041
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
2042
{
625 tk 2043
  // send MIDI event in remote mode and exit
1316 tk 2044
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2045
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendEncoder(encoder, incrementer);
2046
 
1044 tk 2047
  // ignore as long as hardware config hasn't been read
496 tk 2048
  if( !SEQ_FILE_HW_ConfigLocked() )
2049
    return -1;
2050
 
740 tk 2051
  // ignore during a backup or format is created
2052
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 2053
    return -1;
2054
 
1341 tk 2055
  if( encoder >= SEQ_HWCFG_NUM_ENCODERS )
134 tk 2056
    return -1; // encoder doesn't exist
2057
 
328 tk 2058
  // ensure that selections are matching with track constraints
2059
  SEQ_UI_CheckSelections();
2060
 
596 tk 2061
  // stop current message
2062
  SEQ_UI_MsgStop();
2063
 
134 tk 2064
  // limit incrementer
2065
  if( incrementer > 3 )
2066
    incrementer = 3;
2067
  else if( incrementer < -3 )
2068
    incrementer = -3;
2069
 
1341 tk 2070
  // encoder 17 increments BPM
2071
  if( encoder == 17 ) {
2072
    u16 value = (u16)(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num]*10);
2073
    if( SEQ_UI_Var16_Inc(&value, 25, 3000, incrementer) ) { // at 384ppqn, the minimum BPM rate is ca. 2.5
2074
      // set new BPM
2075
      seq_core_bpm_preset_tempo[seq_core_bpm_preset_num] = (float)value/10.0;
2076
      SEQ_CORE_BPM_Update(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num], seq_core_bpm_preset_ramp[seq_core_bpm_preset_num]);
2077
      //store_file_required = 1;
2078
      seq_ui_display_update_req = 1;      
2079
    }
2080
    return 0;
2081
  }
2082
 
607 tk 2083
  if( seq_ui_button_state.SCRUB && encoder == 0 ) {
2084
    // if sequencer isn't already running, continue it (don't restart)
2085
    if( !SEQ_BPM_IsRunning() )
2086
      SEQ_BPM_Cont();
2087
    ui_seq_pause = 0; // clear pause mode
1278 tk 2088
 
607 tk 2089
    // Scrub sequence back or forth
2090
    portENTER_CRITICAL(); // should be atomic
2091
    SEQ_CORE_Scrub(incrementer);
2092
    portEXIT_CRITICAL();
2093
  } else if( !seq_ui_button_state.MENU_PRESSED && ui_encoder_callback != NULL ) {
173 tk 2094
    ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
740 tk 2095
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0; // ensure that value is visible when it has been changed
134 tk 2096
  }
2097
 
2098
  // request display update
159 tk 2099
  seq_ui_display_update_req = 1;
134 tk 2100
 
2101
  return 0; // no error
2102
}
2103
 
2104
 
353 tk 2105
 
134 tk 2106
/////////////////////////////////////////////////////////////////////////////
626 tk 2107
// Receives a MIDI package from APP_NotifyReceivedEvent (-> app.c)
2108
/////////////////////////////////////////////////////////////////////////////
2109
s32 SEQ_UI_REMOTE_MIDI_Receive(mios32_midi_port_t port, mios32_midi_package_t midi_package)
2110
{
2111
#if 1
2112
  // check for active remote mode
1316 tk 2113
  if( seq_midi_sysex_remote_active_mode != SEQ_MIDI_SYSEX_REMOTE_MODE_SERVER )
626 tk 2114
    return 0; // no error
2115
#endif
2116
 
1316 tk 2117
  if( (seq_midi_sysex_remote_port == DEFAULT && seq_midi_sysex_remote_active_port != port) ||
2118
      (seq_midi_sysex_remote_port != DEFAULT && port != seq_midi_sysex_remote_port) )
626 tk 2119
    return 0; // wrong port
2120
 
2121
  // for easier parsing: convert Note Off -> Note On with velocity 0
2122
  if( midi_package.event == NoteOff ) {
2123
    midi_package.event = NoteOn;
2124
    midi_package.velocity = 0;
2125
  }
2126
 
2127
  switch( midi_package.event ) {
2128
    case NoteOn: {
2129
      switch( midi_package.chn ) {
2130
        case Chn1:
2131
      SEQ_UI_Button_Handler(midi_package.note + 0x00, midi_package.velocity ? 0 : 1);
2132
      break;
2133
        case Chn2:
2134
      SEQ_UI_Button_Handler(midi_package.note + 0x80, midi_package.velocity ? 0 : 1);
2135
      break;
2136
        case Chn3:
2137
      SEQ_UI_BLM_Button_Handler(midi_package.note >> 5, midi_package.note & 0x1f, midi_package.velocity ? 0 : 1);
2138
      break;
2139
      }
2140
    } break;
2141
 
2142
    case CC: {
2143
      if( midi_package.cc_number >= 15 && midi_package.cc_number <= 31 )
2144
    SEQ_UI_Encoder_Handler(midi_package.cc_number-15, (int)midi_package.value - 0x40);
2145
    } break;
2146
  }
2147
 
632 tk 2148
  return 1; // MIDI event has been taken for remote function -> don't forward to router/MIDI event parser
626 tk 2149
}
2150
 
2151
 
2152
/////////////////////////////////////////////////////////////////////////////
741 tk 2153
// MIDI Remote Keyboard Function (called from SEQ_MIDI_IN)
2154
/////////////////////////////////////////////////////////////////////////////
742 tk 2155
s32 SEQ_UI_REMOTE_MIDI_Keyboard(u8 key, u8 depressed)
741 tk 2156
{
742 tk 2157
#if 0
1316 tk 2158
  MIOS32_MIDI_SendDebugMessage("SEQ_MIDI_SYSEX_REMOTE_MIDI_Keyboard(%d, %d)\n", key, depressed);
741 tk 2159
#endif
742 tk 2160
 
2161
  switch( key ) {
2162
    case 0x24: // C-2
2163
      return SEQ_UI_Button_GP(depressed, 0);
2164
    case 0x25: // C#2
2165
      return SEQ_UI_Button_Track(depressed, 0);
2166
    case 0x26: // D-2
2167
      return SEQ_UI_Button_GP(depressed, 1);
2168
    case 0x27: // D#2
2169
      return SEQ_UI_Button_Track(depressed, 1);
2170
    case 0x28: // E-2
2171
      return SEQ_UI_Button_GP(depressed, 2);
2172
    case 0x29: // F-2
2173
      return SEQ_UI_Button_GP(depressed, 3);
2174
    case 0x2a: // F#2
2175
      return SEQ_UI_Button_Track(depressed, 2);
2176
    case 0x2b: // G-2
2177
      return SEQ_UI_Button_GP(depressed, 4);
2178
    case 0x2c: // G#2
2179
      return SEQ_UI_Button_Track(depressed, 3);
2180
    case 0x2d: // A-2
2181
      return SEQ_UI_Button_GP(depressed, 5);
2182
    case 0x2e: // A#2
2183
      return SEQ_UI_Button_ParLayer(depressed, 0);
2184
    case 0x2f: // B-2
2185
      return SEQ_UI_Button_GP(depressed, 6);
2186
 
2187
    case 0x30: // C-3
2188
      return SEQ_UI_Button_GP(depressed, 7);
2189
    case 0x31: // C#3
2190
      return SEQ_UI_Button_ParLayer(depressed, 1);
2191
    case 0x32: // D-3
2192
      return SEQ_UI_Button_GP(depressed, 8);
2193
    case 0x33: // D#3
2194
      return SEQ_UI_Button_ParLayer(depressed, 2);
2195
    case 0x34: // E-3
2196
      return SEQ_UI_Button_GP(depressed, 9);
2197
    case 0x35: // F-3
2198
      return SEQ_UI_Button_GP(depressed, 10);
2199
    case 0x36: // F#3
2200
      return SEQ_UI_Button_TrgLayer(depressed, 0);
2201
    case 0x37: // G-3
2202
      return SEQ_UI_Button_GP(depressed, 11);
2203
    case 0x38: // G#3
2204
      return SEQ_UI_Button_TrgLayer(depressed, 1);
2205
    case 0x39: // A-3
2206
      return SEQ_UI_Button_GP(depressed, 12);
2207
    case 0x3a: // A#3
2208
      return SEQ_UI_Button_TrgLayer(depressed, 2);
2209
    case 0x3b: // B-3
2210
      return SEQ_UI_Button_GP(depressed, 13);
2211
 
2212
    case 0x3c: // C-4
2213
      return SEQ_UI_Button_GP(depressed, 14);
2214
    case 0x3d: // C#4
2215
      return SEQ_UI_Button_Group(depressed, 0);
2216
    case 0x3e: // D-4
2217
      return SEQ_UI_Button_GP(depressed, 15);
2218
    case 0x3f: // D#4
2219
      return SEQ_UI_Button_Group(depressed, 1);
2220
    case 0x40: // E-4
2221
      return 0; // ignore
2222
    case 0x41: // F-4
2223
      return SEQ_UI_Button_StepView(depressed);
2224
    case 0x42: // F#4
2225
      return SEQ_UI_Button_Group(depressed, 1);
2226
    case 0x43: // G-4
2227
      return 0; // ignore
2228
    case 0x44: // G#4
2229
      return SEQ_UI_Button_Group(depressed, 2);
2230
    case 0x45: // A-4
2231
      return SEQ_UI_Button_Left(depressed);
2232
    case 0x46: // A#4
2233
      return SEQ_UI_Button_ToggleGate(depressed);
2234
    case 0x47: // B-4
2235
      return SEQ_UI_Button_Right(depressed);
2236
 
2237
    case 0x48: // C-5
2238
      return SEQ_UI_Button_Edit(depressed);
2239
    case 0x49: // C#5
2240
      return SEQ_UI_Button_Solo(depressed);
2241
    case 0x4a: // D-5
2242
      return SEQ_UI_Button_Mute(depressed);
2243
    case 0x4b: // D#5
2244
      return SEQ_UI_Button_All(depressed);
2245
    case 0x4c: // E-5
2246
      return SEQ_UI_Button_Pattern(depressed);
2247
    case 0x4d: // F-5
2248
      return SEQ_UI_Button_Song(depressed);
2249
    case 0x4e: // F#5
2250
      return SEQ_UI_Button_Fast(depressed);
2251
    case 0x4f: // G-5
2252
      return SEQ_UI_Button_Metronome(depressed);
2253
    case 0x50: // G#5
2254
      return SEQ_UI_Button_ExtRestart(depressed);
2255
    case 0x51: // A-5
2256
      return SEQ_UI_Button_ParLayerSel(depressed);
2257
    case 0x52: // A#5
2258
      return SEQ_UI_Button_TrackSel(depressed);
2259
    case 0x53: // B-5
2260
      return SEQ_UI_Button_Stop(depressed);
2261
 
2262
    case 0x54: // C-6
2263
      return SEQ_UI_Button_Play(depressed);
2264
    case 0x55: // C#6
2265
      return SEQ_UI_Button_Pause(depressed);
2266
    case 0x56: // D-6
2267
      return SEQ_UI_Button_Rew(depressed);
2268
    case 0x57: // D#6
2269
      return SEQ_UI_Button_Fwd(depressed);
2270
    case 0x58: // E-6
2271
      return SEQ_UI_Button_Utility(depressed);
2272
    case 0x59: // F-6
2273
      return SEQ_UI_Button_TempoPreset(depressed);
2274
    case 0x5a: // F#6
2275
      return 0; // ignore
2276
    case 0x5b: // G-6
2277
      return SEQ_UI_Button_Menu(depressed);
2278
    case 0x5c: // G#6
2279
      return SEQ_UI_Button_Select(depressed);
2280
    case 0x5d: // A-6
2281
      return SEQ_UI_Button_Exit(depressed);
2282
    case 0x5e: // A#6
2283
      return SEQ_UI_Button_Down(depressed);
2284
    case 0x5f: // B-6
2285
      return SEQ_UI_Button_Up(depressed);
2286
  }
2287
 
741 tk 2288
  return 0; // no error
2289
}
2290
 
2291
 
2292
/////////////////////////////////////////////////////////////////////////////
134 tk 2293
// Update LCD messages
2294
// Usually called from background task
2295
/////////////////////////////////////////////////////////////////////////////
2296
s32 SEQ_UI_LCD_Handler(void)
2297
{
728 tk 2298
  static u8 boot_animation_wait_ctr = 0;
2299
  static u8 boot_animation_lcd_pos = 0;
2300
 
625 tk 2301
  // special handling in remote client mode
1316 tk 2302
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2303
    return SEQ_UI_LCD_Update();
2304
 
159 tk 2305
  if( seq_ui_display_init_req ) {
2306
    seq_ui_display_init_req = 0; // clear request
134 tk 2307
 
278 tk 2308
    // clear force update of LCD
2309
    SEQ_LCD_Clear();
2310
    SEQ_LCD_Update(1);
134 tk 2311
 
168 tk 2312
    // select first menu item
2313
    ui_selected_item = 0;
2314
 
167 tk 2315
    // call init function of current page
272 tk 2316
    if( ui_menu_pages[ui_page].init_callback != NULL )
2317
      ui_menu_pages[ui_page].init_callback(0); // mode
134 tk 2318
 
2319
    // request display update
159 tk 2320
    seq_ui_display_update_req = 1;
134 tk 2321
  }
2322
 
1044 tk 2323
  // print boot screen as long as hardware config hasn't been read
496 tk 2324
  if( !SEQ_FILE_HW_ConfigLocked() ) {
728 tk 2325
    if( boot_animation_lcd_pos < (40-3) ) {
2326
      if( ++boot_animation_wait_ctr >= 75 ) {
2327
    boot_animation_wait_ctr = 0;
637 tk 2328
 
728 tk 2329
    if( boot_animation_lcd_pos == 0 ) {
2330
      SEQ_LCD_Clear();
2331
      SEQ_LCD_CursorSet(0, 0);
2332
      SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE1 " " MIOS32_LCD_BOOT_MSG_LINE2);
2333
      SEQ_LCD_CursorSet(0, 1);
2334
      SEQ_LCD_PrintString("Searching for SD Card...");
2335
    }
2336
 
2337
    // logo is print on second LCD
2338
    SEQ_LCD_LOGO_Print(boot_animation_lcd_pos++);
2339
      }
2340
    }
740 tk 2341
  } else if( seq_ui_backup_req || seq_ui_format_req ) {
634 tk 2342
    SEQ_LCD_Clear();
2343
    SEQ_LCD_CursorSet(0, 0);
740 tk 2344
    //                     <-------------------------------------->
2345
    //                     0123456789012345678901234567890123456789
2346
    if( seq_ui_backup_req )
959 tk 2347
      SEQ_LCD_PrintString("Copy Files - be patient!!!");
740 tk 2348
    else if( seq_ui_format_req )
959 tk 2349
      SEQ_LCD_PrintString("Creating Files - be patient!!!");
740 tk 2350
    else
2351
      SEQ_LCD_PrintString("Don't know what I'm doing! :-/");
637 tk 2352
 
2353
    if( seq_file_backup_notification != NULL ) {
2354
      int i;
2355
 
2356
      SEQ_LCD_CursorSet(0, 1);
959 tk 2357
      SEQ_LCD_PrintFormattedString("Creating %s", seq_file_backup_notification);
637 tk 2358
 
2359
      SEQ_LCD_CursorSet(40+3, 0);
2360
      SEQ_LCD_PrintString("Total: [");
2361
      for(i=0; i<20; ++i)
2362
    SEQ_LCD_PrintChar((i>(seq_file_backup_percentage/5)) ? ' ' : '#');
2363
      SEQ_LCD_PrintFormattedString("] %3d%%", seq_file_backup_percentage);
2364
 
2365
      SEQ_LCD_CursorSet(40+3, 1);
2366
      SEQ_LCD_PrintString("File:  [");
2367
      for(i=0; i<20; ++i)
1261 tk 2368
    SEQ_LCD_PrintChar((i>(file_copy_percentage/5)) ? ' ' : '#');
2369
      SEQ_LCD_PrintFormattedString("] %3d%%", file_copy_percentage);
637 tk 2370
    }
2371
 
496 tk 2372
  } else if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
2373
    SEQ_LCD_CursorSet(0, 0);
2374
    //                   <-------------------------------------->
2375
    //                   0123456789012345678901234567890123456789
306 tk 2376
    SEQ_LCD_PrintString("Menu Shortcuts:");
2377
    SEQ_LCD_PrintSpaces(25 + 40);
2378
    SEQ_LCD_CursorSet(0, 1);
2379
    SEQ_LCD_PrintString(UI_SHORTCUT_STR); // defined in seq_ui_pages.inc
2380
  } else {
2381
    // perform high priority LCD update request
2382
    if( ui_lcd_callback != NULL )
2383
      ui_lcd_callback(1); // high_prio
167 tk 2384
 
306 tk 2385
    // perform low priority LCD update request if requested
2386
    if( seq_ui_display_update_req ) {
2387
      seq_ui_display_update_req = 0; // clear request
328 tk 2388
 
2389
      // ensure that selections are matching with track constraints
2390
      SEQ_UI_CheckSelections();
2391
 
306 tk 2392
      if( ui_lcd_callback != NULL )
2393
    ui_lcd_callback(0); // no high_prio
2394
    }
134 tk 2395
  }
2396
 
353 tk 2397
  // transfer all changed characters to LCD
2398
  SEQ_UI_LCD_Update();
2399
 
2400
  return 0; // no error
2401
}
2402
 
2403
 
2404
/////////////////////////////////////////////////////////////////////////////
2405
// Called from SEQ_UI_LCD_Handler(), but optionally also from other tasks
2406
// to update the LCD screen immediately
2407
/////////////////////////////////////////////////////////////////////////////
1117 tk 2408
// for newer GCC versions it's important to declare constant arrays outside a function
2409
//                                             00112233
2410
static const char animation_l_arrows[2*4+1] = "   >>>> ";
2411
//                                             00112233
2412
static const char animation_r_arrows[2*4+1] = "  < << <";
2413
//                                               00112233
2414
static const char animation_l_brackets[2*4+1] = "   )))) ";
2415
//                                               00112233
2416
static const char animation_r_brackets[2*4+1] = "  ( (( (";
2417
//                                            00112233
2418
static const char animation_l_stars[2*4+1] = "   **** ";
2419
//                                            00112233
2420
static const char animation_r_stars[2*4+1] = "  * ** *";
353 tk 2421
s32 SEQ_UI_LCD_Update(void)
2422
{
625 tk 2423
  // special handling in remote client mode
1316 tk 2424
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT ) {
626 tk 2425
    MIOS32_IRQ_Disable();
1316 tk 2426
    u8 force = seq_midi_sysex_remote_force_lcd_update;
2427
    seq_midi_sysex_remote_force_lcd_update = 0;
626 tk 2428
    MIOS32_IRQ_Enable();
2429
    return SEQ_LCD_Update(force);
625 tk 2430
  }
2431
 
596 tk 2432
  // if UI message active: copy over the text
2433
  if( ui_msg_ctr ) {
774 tk 2434
    char *animation_l_ptr;
2435
    char *animation_r_ptr;
596 tk 2436
    u8 msg_x = 0;
2437
    u8 right_aligned = 0;
740 tk 2438
    u8 disable_message = 0;
299 tk 2439
 
596 tk 2440
    switch( ui_msg_type ) {
2441
      case SEQ_UI_MSG_SDCARD: {
1117 tk 2442
    animation_l_ptr = (char *)animation_l_arrows;
2443
    animation_r_ptr = (char *)animation_r_arrows;
596 tk 2444
    msg_x = 0; // MEMO: print such important information at first LCD for the case the user hasn't connected the second LCD yet
2445
    right_aligned = 0;
2446
      } break;
2447
 
756 tk 2448
      case SEQ_UI_MSG_DELAYED_ACTION:
2449
      case SEQ_UI_MSG_DELAYED_ACTION_R: {
1117 tk 2450
    animation_l_ptr = (char *)animation_l_brackets;
2451
    animation_r_ptr = (char *)animation_r_brackets;
756 tk 2452
    if( ui_msg_type == SEQ_UI_MSG_DELAYED_ACTION_R ) {
2453
      msg_x = 40; // right LCD
2454
      right_aligned = 0;
2455
    } else {
2456
      msg_x = 39; // left LCD
2457
      right_aligned = 1;
2458
    }
740 tk 2459
 
2460
    if( ui_delayed_action_callback == NULL ) {
2461
      disable_message = 1; // button has been depressed before delay
2462
    } else {
2463
      int seconds = (ui_delayed_action_ctr / 1000) + 1;
2464
      if( seconds == 1 )
2465
        sprintf(ui_msg[0], "Hold for 1 second ");
2466
      else
2467
        sprintf(ui_msg[0], "Hold for %d seconds", seconds);
2468
    }
2469
      } break;
2470
 
741 tk 2471
      case SEQ_UI_MSG_USER_R: {
1117 tk 2472
    animation_l_ptr = (char *)animation_l_stars;
2473
    animation_r_ptr = (char *)animation_r_stars;
741 tk 2474
    msg_x = 40; // right display
2475
    right_aligned = 0;
2476
      } break;
2477
 
596 tk 2478
      default: {
1117 tk 2479
    animation_l_ptr = (char *)animation_l_stars;
2480
    animation_r_ptr = (char *)animation_r_stars;
596 tk 2481
    msg_x = 39;
2482
    right_aligned = 1;
2483
      } break;
2484
 
2485
    }
2486
 
740 tk 2487
    if( !disable_message ) {
2488
      int anum = (ui_msg_ctr % 1000) / 250;
596 tk 2489
 
740 tk 2490
      int len[2];
2491
      len[0] = strlen((char *)ui_msg[0]);
2492
      len[1] = strlen((char *)ui_msg[1]);
2493
      int len_max = len[0];
2494
      if( len[1] > len_max )
2495
    len_max = len[1];
596 tk 2496
 
740 tk 2497
      if( right_aligned )
2498
    msg_x -= (9 + len_max);
596 tk 2499
 
740 tk 2500
      int line;
2501
      for(line=0; line<2; ++line) {
2502
    SEQ_LCD_CursorSet(msg_x, line);
596 tk 2503
 
740 tk 2504
    // ensure that both lines are padded with same number of spaces
2505
    int end_pos = len[line];
2506
    while( end_pos < len_max )
2507
      ui_msg[line][end_pos++] = ' ';
2508
    ui_msg[line][end_pos] = 0;
2509
 
2510
    SEQ_LCD_PrintFormattedString(" %c%c| %s |%c%c ",
2511
                     *(animation_l_ptr + 2*anum + 0), *(animation_l_ptr + 2*anum + 1),
2512
                     (char *)ui_msg[line],
2513
                     *(animation_r_ptr + 2*anum + 0), *(animation_r_ptr + 2*anum + 1));
2514
      }
299 tk 2515
    }
2516
  }
2517
 
637 tk 2518
  // MSD USB notification at right corner if not in Disk page
2519
  // to warn user that USB MIDI is disabled and seq performance is bad now!
638 tk 2520
  if( (TASK_MSD_EnableGet() > 0) && ui_page != SEQ_UI_PAGE_DISK ) {
637 tk 2521
    SEQ_LCD_CursorSet(80-11, 0);
2522
    if( ui_cursor_flash ) SEQ_LCD_PrintSpaces(13); else SEQ_LCD_PrintString(" [MSD USB] ");
2523
    SEQ_LCD_CursorSet(80-11, 1);
2524
    char str[5];
2525
    TASK_MSD_FlagStrGet(str);
2526
    if( ui_cursor_flash ) SEQ_LCD_PrintSpaces(13); else SEQ_LCD_PrintFormattedString(" [ %s  ] ", str);
2527
  }
596 tk 2528
 
278 tk 2529
  // transfer all changed characters to LCD
353 tk 2530
  // SEQ_LCD_Update provides a MUTEX handling to allow updates from different tasks
2531
  return SEQ_LCD_Update(0);
134 tk 2532
}
2533
 
2534
 
2535
/////////////////////////////////////////////////////////////////////////////
2536
// Update all LEDs
2537
// Usually called from background task
2538
/////////////////////////////////////////////////////////////////////////////
2539
s32 SEQ_UI_LED_Handler(void)
2540
{
626 tk 2541
  static u8 remote_led_sr[SEQ_LED_NUM_SR];
2542
 
625 tk 2543
  // ignore in remote client mode
1316 tk 2544
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2545
    return 0; // no error
2546
 
1044 tk 2547
  // ignore as long as hardware config hasn't been read
496 tk 2548
  if( !SEQ_FILE_HW_ConfigLocked() )
2549
    return -1;
2550
 
134 tk 2551
  // track LEDs
987 tk 2552
  // in pattern page: track buttons are used as group buttons
2553
  if( ui_page == SEQ_UI_PAGE_PATTERN ) {
2554
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (ui_selected_group == 0));
2555
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (ui_selected_group == 1));
2556
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (ui_selected_group == 2));
2557
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (ui_selected_group == 3));
2558
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
2559
    // in song page: track and group buttons are used to select the cursor position
2560
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (ui_selected_item == 3));
2561
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (ui_selected_item == 4));
2562
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (ui_selected_item == 5));
2563
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (ui_selected_item == 6));
2564
  } else {
2565
    u8 selected_tracks = ui_selected_tracks >> (4*ui_selected_group);
2566
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (selected_tracks & (1 << 0)));
2567
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (selected_tracks & (1 << 1)));
2568
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (selected_tracks & (1 << 2)));
2569
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (selected_tracks & (1 << 3)));
2570
  }
2571
 
678 tk 2572
  SEQ_LED_PinSet(seq_hwcfg_led.track_sel, ui_page == SEQ_UI_PAGE_TRACKSEL);
134 tk 2573
 
2574
  // parameter layer LEDs
987 tk 2575
  // in song page: layer buttons are used to select the cursor position
2576
  if( ui_page == SEQ_UI_PAGE_SONG ) {
2577
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], ui_selected_item == 0);
2578
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], ui_selected_item == 1);
2579
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], ui_selected_item == 2);
2580
  } else {
2581
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], (ui_selected_par_layer == 0));
2582
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], (ui_selected_par_layer == 1));
2583
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], (ui_selected_par_layer >= 2) || seq_ui_button_state.PAR_LAYER_SEL);
2584
  }
678 tk 2585
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer_sel, ui_page == SEQ_UI_PAGE_PARSEL);
134 tk 2586
 
2587
  // group LEDs
987 tk 2588
  // in song page: track and group buttons are used to select the cursor position
2589
  if( ui_page == SEQ_UI_PAGE_SONG ) {
2590
    SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_item == 3));
2591
    SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_item == 4));
2592
    SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_item == 5));
2593
    SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_item == 6));
2594
  } else {
2595
    SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_group == 0));
2596
    SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_group == 1));
2597
    SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_group == 2));
2598
    SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_group == 3));
2599
  }
134 tk 2600
 
2601
  // trigger layer LEDs
492 tk 2602
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[0], (ui_selected_trg_layer == 0));
2603
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[1], (ui_selected_trg_layer == 1));
2604
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[2], (ui_selected_trg_layer >= 2) || seq_ui_button_state.TRG_LAYER_SEL);
678 tk 2605
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer_sel, ui_page == SEQ_UI_PAGE_TRGSEL);
134 tk 2606
 
2607
  // remaining LEDs
492 tk 2608
  SEQ_LED_PinSet(seq_hwcfg_led.edit, ui_page == SEQ_UI_PAGE_EDIT);
2609
  SEQ_LED_PinSet(seq_hwcfg_led.mute, ui_page == SEQ_UI_PAGE_MUTE);
2610
  SEQ_LED_PinSet(seq_hwcfg_led.pattern, ui_page == SEQ_UI_PAGE_PATTERN);
399 tk 2611
  if( SEQ_SONG_ActiveGet() )
492 tk 2612
    SEQ_LED_PinSet(seq_hwcfg_led.song, 1);
399 tk 2613
  else
492 tk 2614
    SEQ_LED_PinSet(seq_hwcfg_led.song, ui_cursor_flash ? 0 : (ui_page == SEQ_UI_PAGE_SONG));
743 tk 2615
  SEQ_LED_PinSet(seq_hwcfg_led.mixer, ui_page == SEQ_UI_PAGE_MIXER);
1119 tk 2616
 
2617
  SEQ_LED_PinSet(seq_hwcfg_led.track_mode, ui_page == SEQ_UI_PAGE_TRKMODE);
2618
  SEQ_LED_PinSet(seq_hwcfg_led.track_groove, ui_page == SEQ_UI_PAGE_TRKGRV);
2619
  SEQ_LED_PinSet(seq_hwcfg_led.track_length, ui_page == SEQ_UI_PAGE_TRKLEN);
2620
  SEQ_LED_PinSet(seq_hwcfg_led.track_direction, ui_page == SEQ_UI_PAGE_TRKDIR);
2621
  SEQ_LED_PinSet(seq_hwcfg_led.track_morph, ui_page == SEQ_UI_PAGE_TRKMORPH);
2622
  SEQ_LED_PinSet(seq_hwcfg_led.track_transpose, ui_page == SEQ_UI_PAGE_TRKTRAN);
134 tk 2623
 
492 tk 2624
  SEQ_LED_PinSet(seq_hwcfg_led.solo, seq_ui_button_state.SOLO);
2625
  SEQ_LED_PinSet(seq_hwcfg_led.fast, seq_ui_button_state.FAST_ENCODERS);
1121 tk 2626
  SEQ_LED_PinSet(seq_hwcfg_led.fast2, seq_ui_button_state.FAST2_ENCODERS);
492 tk 2627
  SEQ_LED_PinSet(seq_hwcfg_led.all, seq_ui_button_state.CHANGE_ALL_STEPS);
134 tk 2628
 
1206 tk 2629
  u8 seq_running = SEQ_BPM_IsRunning() && (!seq_core_slaveclk_mute || ((seq_core_state.ref_step & 3) == 0));
2630
  // note: no bug: we added check for ref_step&3 for flashing the LEDs to give a sign of activity in slave mode with slaveclk_muted
2631
  SEQ_LED_PinSet(seq_hwcfg_led.play, seq_running);
2632
  SEQ_LED_PinSet(seq_hwcfg_led.stop, !seq_running && !ui_seq_pause);
2633
  SEQ_LED_PinSet(seq_hwcfg_led.pause, ui_seq_pause && (!seq_core_slaveclk_mute || ui_cursor_flash));
240 tk 2634
 
492 tk 2635
  SEQ_LED_PinSet(seq_hwcfg_led.rew, seq_ui_button_state.REW);
2636
  SEQ_LED_PinSet(seq_hwcfg_led.fwd, seq_ui_button_state.FWD);
596 tk 2637
 
2638
  SEQ_LED_PinSet(seq_hwcfg_led.loop, seq_core_state.LOOP);
951 tk 2639
  SEQ_LED_PinSet(seq_hwcfg_led.follow, seq_core_state.FOLLOW);
134 tk 2640
 
678 tk 2641
  SEQ_LED_PinSet(seq_hwcfg_led.step_view, ui_page == SEQ_UI_PAGE_STEPSEL);
134 tk 2642
 
591 tk 2643
  SEQ_LED_PinSet(seq_hwcfg_led.select, seq_ui_button_state.SELECT_PRESSED);
492 tk 2644
  SEQ_LED_PinSet(seq_hwcfg_led.menu, seq_ui_button_state.MENU_PRESSED);
1203 tk 2645
  SEQ_LED_PinSet(seq_hwcfg_led.bookmark, ui_page == SEQ_UI_PAGE_BOOKMARKS);
134 tk 2646
 
596 tk 2647
  // handle double functions
2648
  if( seq_ui_button_state.MENU_PRESSED ) {
2649
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_core_state.LOOP);
951 tk 2650
    SEQ_LED_PinSet(seq_hwcfg_led.exit, seq_core_state.FOLLOW);
596 tk 2651
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.EXT_RESTART_REQ);
2652
  } else {
2653
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_ui_button_state.SCRUB);