Subversion Repositories svn.mios32

Rev

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