Subversion Repositories svn.mios32

Rev

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