Subversion Repositories svn.mios32

Rev

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