Subversion Repositories svn.mios32

Rev

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