Subversion Repositories svn.mios32

Rev

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