Subversion Repositories svn.mios32

Rev

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