Subversion Repositories svn.mios32

Rev

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