Subversion Repositories svn.mios32

Rev

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