Subversion Repositories svn.mios32

Rev

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