Subversion Repositories svn.mios32

Rev

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