Subversion Repositories svn.mios32

Rev

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