Subversion Repositories svn.mios32

Rev

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