Subversion Repositories svn.mios32

Rev

Rev 328 | Rev 334 | 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 333 2009-01-31 17:22:37Z tk $
2
/*
3
 * User Interface Routines
4
 *
5
 * ==========================================================================
6
 *
7
 *  Copyright (C) 2008 Thorsten Klose (tk@midibox.org)
8
 *  Licensed for personal non-commercial use only.
9
 *  All other rights reserved.
10
 *
11
 * ==========================================================================
12
 */
13
 
14
/////////////////////////////////////////////////////////////////////////////
15
// Include files
16
/////////////////////////////////////////////////////////////////////////////
17
 
272 tk 18
// with this switch, seq_ui.h/seq_ui_pages.inc will create local variables
19
#define SEQ_UI_PAGES_INC_LOCAL_VARS 1
20
 
134 tk 21
#include <mios32.h>
299 tk 22
#include <string.h>
134 tk 23
#include <blm8x8.h>
190 tk 24
#include <seq_midi_out.h>
25
#include <seq_bpm.h>
134 tk 26
 
290 tk 27
#include "tasks.h"
134 tk 28
#include "seq_ui.h"
29
#include "seq_lcd.h"
30
#include "seq_led.h"
186 tk 31
#include "seq_midply.h"
134 tk 32
#include "seq_core.h"
333 tk 33
#include "seq_par.h"
178 tk 34
#include "seq_layer.h"
184 tk 35
#include "seq_cc.h"
299 tk 36
#include "seq_file.h"
248 tk 37
#include "seq_file_b.h"
280 tk 38
#include "seq_file_m.h"
134 tk 39
 
40
 
41
/////////////////////////////////////////////////////////////////////////////
42
// Global variables
43
/////////////////////////////////////////////////////////////////////////////
44
 
159 tk 45
u8 seq_ui_display_update_req;
46
u8 seq_ui_display_init_req;
134 tk 47
 
167 tk 48
seq_ui_button_state_t seq_ui_button_state;
49
 
134 tk 50
u8 ui_selected_group;
51
u8 ui_selected_tracks;
52
u8 ui_selected_par_layer;
53
u8 ui_selected_trg_layer;
328 tk 54
u8 ui_selected_instrument;
134 tk 55
u8 ui_selected_step_view;
56
u8 ui_selected_step;
168 tk 57
u8 ui_selected_item;
134 tk 58
 
168 tk 59
u8 ui_selected_item;
134 tk 60
 
240 tk 61
u16 ui_hold_msg_ctr;
62
 
206 tk 63
seq_ui_page_t ui_page;
272 tk 64
seq_ui_page_t ui_selected_page;
303 tk 65
seq_ui_page_t ui_stepview_prev_page;
326 tk 66
seq_ui_page_t ui_trglayer_prev_page;
67
seq_ui_page_t ui_parlayer_prev_page;
206 tk 68
 
173 tk 69
volatile u8 ui_cursor_flash;
70
u16 ui_cursor_flash_ctr;
134 tk 71
 
316 tk 72
char ui_edit_name[21];
73
u8 ui_edit_name_cursor;
74
u8 ui_edit_preset_num_category;
75
u8 ui_edit_preset_num_label;
76
 
193 tk 77
u8 ui_seq_pause;
78
 
79
 
134 tk 80
/////////////////////////////////////////////////////////////////////////////
81
// Local variables
82
/////////////////////////////////////////////////////////////////////////////
83
 
168 tk 84
static s32 (*ui_button_callback)(seq_ui_button_t button, s32 depressed);
85
static s32 (*ui_encoder_callback)(seq_ui_encoder_t encoder, s32 incrementer);
173 tk 86
static s32 (*ui_led_callback)(u16 *gp_leds);
167 tk 87
static s32 (*ui_lcd_callback)(u8 high_prio);
88
 
168 tk 89
static u16 ui_gp_leds;
167 tk 90
 
168 tk 91
 
299 tk 92
#define SDCARD_MSG_MAX_CHAR 21
93
static char sdcard_msg[2][SDCARD_MSG_MAX_CHAR];
94
static u16 sdcard_msg_ctr;
95
 
96
 
97
 
134 tk 98
/////////////////////////////////////////////////////////////////////////////
99
// Initialisation
100
/////////////////////////////////////////////////////////////////////////////
101
s32 SEQ_UI_Init(u32 mode)
102
{
103
  // init selection variables
104
  ui_selected_group = 0;
105
  ui_selected_tracks = (1 << 0);
106
  ui_selected_par_layer = 0;
107
  ui_selected_trg_layer = 0;
328 tk 108
  ui_selected_instrument = 0;
134 tk 109
  ui_selected_step_view = 0;
110
  ui_selected_step = 0;
168 tk 111
  ui_selected_item = 0;
134 tk 112
 
240 tk 113
  ui_hold_msg_ctr = 0;
299 tk 114
  sdcard_msg_ctr = 0;
240 tk 115
 
168 tk 116
  ui_cursor_flash_ctr = 0;
173 tk 117
  ui_cursor_flash = 0;
168 tk 118
 
167 tk 119
  seq_ui_button_state.ALL = 0;
120
 
193 tk 121
  ui_seq_pause = 0;
122
 
134 tk 123
  // visible GP pattern
124
  ui_gp_leds = 0x0000;
125
 
167 tk 126
  // change to edit page
127
  ui_page = SEQ_UI_PAGE_NONE;
128
  SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
134 tk 129
 
130
  return 0; // no error
131
}
132
 
133
 
134
/////////////////////////////////////////////////////////////////////////////
178 tk 135
// Inits the speed mode of all encoders
136
// Auto mode should be used whenever:
137
//    - the edit screen is entered
138
//    - the group is changed
139
//    - a track is changed
140
//    - a layer is changed
141
/////////////////////////////////////////////////////////////////////////////
142
s32 SEQ_UI_InitEncSpeed(u32 auto_config)
143
{
144
  mios32_enc_config_t enc_config;
145
 
146
  if( auto_config ) {
147
#if DEFAULT_AUTO_FAST_BUTTON
333 tk 148
    switch( SEQ_PAR_AssignmentGet(SEQ_UI_VisibleTrackGet(), ui_selected_par_layer) ) {
149
      case SEQ_PAR_Type_Velocity:
150
      case SEQ_PAR_Type_Length:
151
      case SEQ_PAR_Type_CC:
152
      case SEQ_PAR_Type_PitchBend:
153
      case SEQ_PAR_Type_Probability:
154
      case SEQ_PAR_Type_Delay:
155
      case SEQ_PAR_Type_Loopback:
178 tk 156
    seq_ui_button_state.FAST_ENCODERS = 1;
157
    break;
158
 
159
      default:
160
    seq_ui_button_state.FAST_ENCODERS = 0;
161
    }
162
#else
163
    // auto mode not enabled - ignore auto reconfiguration request
164
    return 0;
165
#endif
166
  }
167
 
168
  // change for datawheel and GP encoders
169
  int enc;
170
  for(enc=0; enc<17; ++enc) {
171
    enc_config = MIOS32_ENC_ConfigGet(enc);
172
    enc_config.cfg.speed = seq_ui_button_state.FAST_ENCODERS ? FAST : NORMAL;
173
    enc_config.cfg.speed_par = (enc == 0) ? DEFAULT_DATAWHEEL_SPEED_VALUE : DEFAULT_ENC_SPEED_VALUE;
174
    MIOS32_ENC_ConfigSet(enc, enc_config);
175
  }
176
 
177
  return 0; // no error
178
}
179
 
180
 
181
/////////////////////////////////////////////////////////////////////////////
167 tk 182
// Various installation routines for menu page LCD handlers
183
/////////////////////////////////////////////////////////////////////////////
168 tk 184
s32 SEQ_UI_InstallButtonCallback(void *callback)
167 tk 185
{
168 tk 186
  ui_button_callback = callback;
167 tk 187
  return 0; // no error
188
}
189
 
168 tk 190
s32 SEQ_UI_InstallEncoderCallback(void *callback)
167 tk 191
{
168 tk 192
  ui_encoder_callback = callback;
167 tk 193
  return 0; // no error
194
}
195
 
168 tk 196
s32 SEQ_UI_InstallLEDCallback(void *callback)
167 tk 197
{
168 tk 198
  ui_led_callback = callback;
167 tk 199
  return 0; // no error
200
}
201
 
168 tk 202
s32 SEQ_UI_InstallLCDCallback(void *callback)
167 tk 203
{
204
  ui_lcd_callback = callback;
205
  return 0; // no error
206
}
207
 
208
 
209
/////////////////////////////////////////////////////////////////////////////
210
// Change the menu page
211
/////////////////////////////////////////////////////////////////////////////
212
s32 SEQ_UI_PageSet(seq_ui_page_t page)
213
{
214
  if( page != ui_page ) {
215
    // disable hooks of previous page and request re-initialisation
318 tk 216
    portENTER_CRITICAL();
167 tk 217
    ui_page = page;
168 tk 218
    ui_button_callback = NULL;
219
    ui_encoder_callback = NULL;
220
    ui_led_callback = NULL;
167 tk 221
    ui_lcd_callback = NULL;
318 tk 222
    portEXIT_CRITICAL();
167 tk 223
 
178 tk 224
#if DEFAULT_BEHAVIOUR_BUTTON_MENU
168 tk 225
    seq_ui_button_state.MENU_PRESSED = 0; // MENU page selection finished
167 tk 226
#endif
227
 
228
    // request display initialisation
229
    seq_ui_display_init_req = 1;
230
  }
173 tk 231
 
306 tk 232
  // for MENU button:
233
  // first page has been selected - display new screen
234
  seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 1;
235
 
272 tk 236
  // for SEQ_UI_MENU which is accessible with EXIT button
237
  // remember the current selectable page
238
  if( ui_page >= SEQ_UI_FIRST_MENU_SELECTION_PAGE )
239
    ui_selected_page = ui_page;
240
 
184 tk 241
  return 0; // no error
167 tk 242
}
243
 
244
 
245
/////////////////////////////////////////////////////////////////////////////
272 tk 246
// Returns name of menu page (18 characters)
247
/////////////////////////////////////////////////////////////////////////////
248
char *SEQ_UI_PageNameGet(seq_ui_page_t page)
249
{
250
  return ui_menu_pages[page].name;
251
}
252
 
253
 
254
/////////////////////////////////////////////////////////////////////////////
134 tk 255
// Dedicated button functions
256
// Mapped to physical buttons in SEQ_UI_Button_Handler()
257
// Will also be mapped to MIDI keys later (for MIDI remote function)
258
/////////////////////////////////////////////////////////////////////////////
259
static s32 SEQ_UI_Button_GP(s32 depressed, u32 gp)
260
{
306 tk 261
  // in MENU page: overrule GP buttons so long MENU button is pressed/active
262
  if( seq_ui_button_state.MENU_PRESSED ) {
263
    if( depressed ) return -1;
264
    SEQ_UI_PageSet(ui_shortcut_menu_pages[gp]);
265
  } else {
266
    // forward to menu page
267
    if( ui_button_callback != NULL )
268
      ui_button_callback(gp, depressed);
269
    ui_cursor_flash_ctr = 0;
270
  }
134 tk 271
 
272
  return 0; // no error
273
}
274
 
275
static s32 SEQ_UI_Button_Left(s32 depressed)
276
{
168 tk 277
  // forward to menu page
306 tk 278
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 279
    ui_button_callback(SEQ_UI_BUTTON_Left, depressed);
173 tk 280
  ui_cursor_flash_ctr = 0;
134 tk 281
 
282
  return 0; // no error
283
}
284
 
285
static s32 SEQ_UI_Button_Right(s32 depressed)
286
{
168 tk 287
  // forward to menu page
306 tk 288
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 289
    ui_button_callback(SEQ_UI_BUTTON_Right, depressed);
173 tk 290
  ui_cursor_flash_ctr = 0;
134 tk 291
 
292
  return 0; // no error
293
}
294
 
168 tk 295
static s32 SEQ_UI_Button_Down(s32 depressed)
296
{
240 tk 297
  seq_ui_button_state.DOWN = depressed ? 0 : 1;
298
 
168 tk 299
  // forward to menu page
306 tk 300
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 301
    ui_button_callback(SEQ_UI_BUTTON_Down, depressed);
173 tk 302
  ui_cursor_flash_ctr = 0;
168 tk 303
 
304
  return 0; // no error
305
}
306
 
307
static s32 SEQ_UI_Button_Up(s32 depressed)
308
{
240 tk 309
  seq_ui_button_state.UP = depressed ? 0 : 1;
310
 
168 tk 311
  // forward to menu page
306 tk 312
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 313
    ui_button_callback(SEQ_UI_BUTTON_Up, depressed);
173 tk 314
  ui_cursor_flash_ctr = 0;
168 tk 315
 
316
  return 0; // no error
317
}
318
 
134 tk 319
static s32 SEQ_UI_Button_Scrub(s32 depressed)
320
{
178 tk 321
#if DEFAULT_BEHAVIOUR_BUTTON_SCRUB
322
  // toggle mode
134 tk 323
  if( depressed ) return -1; // ignore when button depressed
178 tk 324
  seq_ui_button_state.SCRUB ^= 1;
137 tk 325
#else
178 tk 326
  // set mode
327
  seq_ui_button_state.SCRUB = depressed ? 0 : 1;
137 tk 328
#endif
329
 
134 tk 330
  return 0; // no error
331
}
332
 
333
static s32 SEQ_UI_Button_Metronome(s32 depressed)
334
{
178 tk 335
#if DEFAULT_BEHAVIOUR_BUTTON_METRON
336
  // toggle mode
134 tk 337
  if( depressed ) return -1; // ignore when button depressed
178 tk 338
  seq_ui_button_state.METRONOME ^= 1;
290 tk 339
 
248 tk 340
#if 1
290 tk 341
  MUTEX_SDCARD_TAKE;
280 tk 342
 
328 tk 343
#if 1
249 tk 344
  u8 bank;
345
  for(bank=0; bank<SEQ_FILE_B_NUM_BANKS; ++bank) {
346
    SEQ_FILE_B_Create(bank);
347
    SEQ_FILE_B_Open(bank);
348
  }
280 tk 349
#else
350
    SEQ_FILE_M_Create();
351
    SEQ_FILE_M_Open();
352
#endif
353
 
290 tk 354
  MUTEX_SDCARD_GIVE;
248 tk 355
#endif
356
 
137 tk 357
#else
178 tk 358
  // set mode
359
  seq_ui_button_state.METRONOME = depressed ? 0 : 1;
137 tk 360
#endif
134 tk 361
 
362
  return 0; // no error
363
}
364
 
365
static s32 SEQ_UI_Button_Stop(s32 depressed)
366
{
367
  if( depressed ) return -1; // ignore when button depressed
368
 
159 tk 369
  // if sequencer running: stop it
370
  // if sequencer already stopped: reset song position
186 tk 371
#if MID_PLAYER_TEST
193 tk 372
  if( SEQ_BPM_IsRunning() )
373
    SEQ_BPM_Stop();
186 tk 374
  else
375
    SEQ_MIDPLY_Reset();
376
#else
193 tk 377
  if( SEQ_BPM_IsRunning() )
378
    SEQ_BPM_Stop();
159 tk 379
  else
380
    SEQ_CORE_Reset();
186 tk 381
#endif
159 tk 382
 
134 tk 383
  return 0; // no error
384
}
385
 
386
static s32 SEQ_UI_Button_Pause(s32 depressed)
387
{
388
  if( depressed ) return -1; // ignore when button depressed
389
 
193 tk 390
  // if in auto mode and BPM generator is clocked in slave mode:
391
  // change to master mode
392
  SEQ_BPM_CheckAutoMaster();
159 tk 393
 
193 tk 394
  // toggle pause mode
395
  ui_seq_pause ^= 1;
396
 
397
  // execute stop/continue depending on new mode
398
  if( ui_seq_pause )
399
    SEQ_BPM_Stop();
400
  else
401
    SEQ_BPM_Cont();
402
 
134 tk 403
  return 0; // no error
404
}
405
 
406
static s32 SEQ_UI_Button_Play(s32 depressed)
407
{
408
  if( depressed ) return -1; // ignore when button depressed
409
 
186 tk 410
  // if in auto mode and BPM generator is clocked in slave mode:
411
  // change to master mode
412
  SEQ_BPM_CheckAutoMaster();
413
 
193 tk 414
#if 0
415
  // if sequencer running: restart it
416
  // if sequencer stopped: continue at last song position
417
  if( SEQ_BPM_IsRunning() )
418
    SEQ_BPM_Start();
419
  else
420
    SEQ_BPM_Cont();
186 tk 421
#else
193 tk 422
  // always restart sequencer
423
  SEQ_BPM_Start();
186 tk 424
#endif
159 tk 425
 
134 tk 426
  return 0; // no error
427
}
428
 
429
static s32 SEQ_UI_Button_Rew(s32 depressed)
430
{
240 tk 431
  seq_ui_button_state.REW = depressed ? 0 : 1;
432
 
134 tk 433
  if( depressed ) return -1; // ignore when button depressed
434
 
435
  return 0; // no error
436
}
437
 
438
static s32 SEQ_UI_Button_Fwd(s32 depressed)
439
{
240 tk 440
  seq_ui_button_state.FWD = depressed ? 0 : 1;
441
 
134 tk 442
  if( depressed ) return -1; // ignore when button depressed
443
 
444
  return 0; // no error
445
}
446
 
447
static s32 SEQ_UI_Button_F1(s32 depressed)
448
{
240 tk 449
  seq_ui_button_state.F1 = depressed ? 0 : 1;
450
 
134 tk 451
  if( depressed ) return -1; // ignore when button depressed
452
 
240 tk 453
  // change to utility page
454
  SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
455
 
134 tk 456
  return 0; // no error
457
}
458
 
459
static s32 SEQ_UI_Button_F2(s32 depressed)
460
{
240 tk 461
  seq_ui_button_state.F2 = depressed ? 0 : 1;
462
 
134 tk 463
  if( depressed ) return -1; // ignore when button depressed
464
 
465
  return 0; // no error
466
}
467
 
468
static s32 SEQ_UI_Button_F3(s32 depressed)
469
{
240 tk 470
  seq_ui_button_state.F3 = depressed ? 0 : 1;
471
 
134 tk 472
  if( depressed ) return -1; // ignore when button depressed
473
 
474
  return 0; // no error
475
}
476
 
477
static s32 SEQ_UI_Button_F4(s32 depressed)
478
{
240 tk 479
  seq_ui_button_state.F4 = depressed ? 0 : 1;
480
 
134 tk 481
  if( depressed ) return -1; // ignore when button depressed
482
 
483
  return 0; // no error
484
}
485
 
486
static s32 SEQ_UI_Button_Utility(s32 depressed)
487
{
488
  if( depressed ) return -1; // ignore when button depressed
489
 
240 tk 490
  // change to utility page
491
  SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
492
 
134 tk 493
  return 0; // no error
494
}
495
 
496
static s32 SEQ_UI_Button_Copy(s32 depressed)
497
{
240 tk 498
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 499
 
240 tk 500
  seq_ui_button_state.COPY = depressed ? 0 : 1;
501
 
280 tk 502
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
503
    if( depressed ) return -1;
504
    SEQ_UI_MIXER_Copy();
505
    return 1;
506
  } else {
507
    if( !depressed ) {
508
      prev_page = ui_page;
509
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
510
    }
240 tk 511
 
280 tk 512
    s32 status = SEQ_UI_UTIL_CopyButton(depressed);
240 tk 513
 
280 tk 514
    if( depressed )
515
      SEQ_UI_PageSet(prev_page);
240 tk 516
 
280 tk 517
    return status;
518
  }
134 tk 519
}
520
 
521
static s32 SEQ_UI_Button_Paste(s32 depressed)
522
{
240 tk 523
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 524
 
240 tk 525
  seq_ui_button_state.PASTE = depressed ? 0 : 1;
526
 
280 tk 527
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
528
    if( depressed ) return -1;
529
    SEQ_UI_MIXER_Paste();
530
    return 1;
531
  } else {
532
    if( !depressed ) {
533
      prev_page = ui_page;
534
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
535
    }
240 tk 536
 
280 tk 537
    s32 status = SEQ_UI_UTIL_PasteButton(depressed);
240 tk 538
 
280 tk 539
    if( depressed )
540
      SEQ_UI_PageSet(prev_page);
240 tk 541
 
280 tk 542
    return status;
543
  }
134 tk 544
}
545
 
546
static s32 SEQ_UI_Button_Clear(s32 depressed)
547
{
240 tk 548
  seq_ui_button_state.CLEAR = depressed ? 0 : 1;
280 tk 549
 
550
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
551
    if( depressed ) return -1;
552
    SEQ_UI_MIXER_Clear();
553
    return 1;
554
  } else {
555
    return SEQ_UI_UTIL_ClearButton(depressed);
556
  }
134 tk 557
}
558
 
559
static s32 SEQ_UI_Button_Menu(s32 depressed)
560
{
167 tk 561
  // TODO: define generic #define for this button behaviour
178 tk 562
#if DEFAULT_BEHAVIOUR_BUTTON_MENU
563
  // toggle mode
134 tk 564
  if( depressed ) return -1; // ignore when button depressed
306 tk 565
  seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
167 tk 566
  seq_ui_button_state.MENU_PRESSED ^= 1; // toggle MENU pressed (will also be released once GP button has been pressed)
567
#else
178 tk 568
  // set mode
306 tk 569
  seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
167 tk 570
  seq_ui_button_state.MENU_PRESSED = depressed ? 0 : 1;
571
#endif
134 tk 572
 
573
  return 0; // no error
574
}
575
 
576
static s32 SEQ_UI_Button_Select(s32 depressed)
577
{
168 tk 578
  // forward to menu page
306 tk 579
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 580
    ui_button_callback(SEQ_UI_BUTTON_Select, depressed);
173 tk 581
  ui_cursor_flash_ctr = 0;
134 tk 582
 
583
  return 0; // no error
584
}
585
 
586
static s32 SEQ_UI_Button_Exit(s32 depressed)
587
{
272 tk 588
  if( depressed ) return -1; // ignore when button depressed
589
 
590
  u8 prev_ui_page = ui_page;
591
 
168 tk 592
  // forward to menu page
306 tk 593
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 594
    ui_button_callback(SEQ_UI_BUTTON_Exit, depressed);
173 tk 595
  ui_cursor_flash_ctr = 0;
134 tk 596
 
167 tk 597
  // release all button states
598
  seq_ui_button_state.ALL = 0;
599
 
272 tk 600
  // enter menu page if we were not there before
601
  if( prev_ui_page != SEQ_UI_PAGE_MENU )
602
    SEQ_UI_PageSet(SEQ_UI_PAGE_MENU);
603
 
134 tk 604
  return 0; // no error
605
}
606
 
607
static s32 SEQ_UI_Button_Edit(s32 depressed)
608
{
609
  if( depressed ) return -1; // ignore when button depressed
610
 
167 tk 611
  // change to edit page
612
  SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
613
 
178 tk 614
  // set/clear encoder fast function if required
615
  SEQ_UI_InitEncSpeed(1); // auto config
616
 
134 tk 617
  return 0; // no error
618
}
619
 
620
static s32 SEQ_UI_Button_Mute(s32 depressed)
621
{
622
  if( depressed ) return -1; // ignore when button depressed
623
 
184 tk 624
  SEQ_UI_PageSet(SEQ_UI_PAGE_MUTE);
625
 
134 tk 626
  return 0; // no error
627
}
628
 
629
static s32 SEQ_UI_Button_Pattern(s32 depressed)
630
{
631
  if( depressed ) return -1; // ignore when button depressed
632
 
184 tk 633
  SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN);
634
 
134 tk 635
  return 0; // no error
636
}
637
 
638
static s32 SEQ_UI_Button_Song(s32 depressed)
639
{
640
  if( depressed ) return -1; // ignore when button depressed
641
 
642
  return 0; // no error
643
}
644
 
645
static s32 SEQ_UI_Button_Solo(s32 depressed)
646
{
178 tk 647
#if DEFAULT_BEHAVIOUR_BUTTON_ALL
648
  // toggle mode
134 tk 649
  if( depressed ) return -1; // ignore when button depressed
178 tk 650
  seq_ui_button_state.SOLO ^= 1;
651
#else
652
  // set mode
653
  seq_ui_button_state.SOLO = depressed ? 0 : 1;
654
#endif
134 tk 655
 
656
  return 0; // no error
657
}
658
 
659
static s32 SEQ_UI_Button_Fast(s32 depressed)
660
{
178 tk 661
#if DEFAULT_BEHAVIOUR_BUTTON_FAST
662
  // toggle mode
134 tk 663
  if( depressed ) return -1; // ignore when button depressed
178 tk 664
  seq_ui_button_state.FAST_ENCODERS ^= 1;
665
#else
666
  // set mode
667
  seq_ui_button_state.FAST_ENCODERS = depressed ? 0 : 1;
668
#endif
134 tk 669
 
178 tk 670
  SEQ_UI_InitEncSpeed(0); // no auto config
671
 
134 tk 672
  return 0; // no error
673
}
674
 
675
static s32 SEQ_UI_Button_All(s32 depressed)
676
{
178 tk 677
  seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE = depressed ? 0 : 1;
134 tk 678
 
178 tk 679
#if DEFAULT_BEHAVIOUR_BUTTON_ALL
680
  // toggle mode
681
  if( depressed ) return -1;
682
  seq_ui_button_state.CHANGE_ALL_STEPS ^= 1;
683
#else
684
  // set mode
685
  seq_ui_button_state.CHANGE_ALL_STEPS = depressed ? 0 : 1;
686
#endif
687
 
134 tk 688
  return 0; // no error
689
}
690
 
691
static s32 SEQ_UI_Button_StepView(s32 depressed)
692
{
326 tk 693
 
303 tk 694
#if DEFAULT_BEHAVIOUR_BUTTON_STEPVIEW
134 tk 695
  if( depressed ) return -1; // ignore when button depressed
303 tk 696
  seq_ui_button_state.STEPVIEW ^= 1; // toggle STEPVIEW pressed (will also be released once GP button has been pressed)
697
#else
698
  // set mode
699
  seq_ui_button_state.STEPVIEW = depressed ? 0 : 1;
700
#endif
134 tk 701
 
303 tk 702
  if( seq_ui_button_state.STEPVIEW ) {
703
    ui_stepview_prev_page = ui_page;
704
    SEQ_UI_PageSet(SEQ_UI_PAGE_STEPSEL);
705
  } else {
706
    SEQ_UI_PageSet(ui_stepview_prev_page);
707
  }
134 tk 708
 
709
  return 0; // no error
710
}
711
 
712
static s32 SEQ_UI_Button_TapTempo(s32 depressed)
713
{
714
  if( depressed ) return -1; // ignore when button depressed
715
 
716
  return 0; // no error
717
}
718
 
719
static s32 SEQ_UI_Button_Track(s32 depressed, u32 track)
720
{
721
  if( depressed ) return -1; // ignore when button depressed
722
 
723
  if( track >= 4 ) return -2; // max. 4 track buttons
724
 
725
  ui_selected_tracks = (1 << track); // TODO: multi-selections!
726
 
178 tk 727
  // set/clear encoder fast function if required
728
  SEQ_UI_InitEncSpeed(1); // auto config
729
 
134 tk 730
  return 0; // no error
731
}
732
 
733
static s32 SEQ_UI_Button_Group(s32 depressed, u32 group)
734
{
735
  if( depressed ) return -1; // ignore when button depressed
736
 
737
  if( group >= 4 ) return -2; // max. 4 group buttons
738
 
739
  ui_selected_group = group;
740
 
178 tk 741
  // set/clear encoder fast function if required
742
  SEQ_UI_InitEncSpeed(1); // auto config
743
 
134 tk 744
  return 0; // no error
745
}
746
 
747
static s32 SEQ_UI_Button_ParLayer(s32 depressed, u32 par_layer)
748
{
749
  if( par_layer >= 3 ) return -2; // max. 3 parlayer buttons
750
 
333 tk 751
  u8 visible_track = SEQ_UI_VisibleTrackGet();
752
  u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
134 tk 753
 
333 tk 754
  if( num_p_layers <= 3 ) {
755
    // 3 layers: direct selection with LayerA/B/C button
756
    if( depressed ) return -1; // ignore when button depressed
757
    seq_ui_button_state.PAR_LAYER_SEL = 0;
758
    ui_selected_par_layer = par_layer;
759
  } else if( num_p_layers <= 4 ) {
760
    // 4 layers: LayerC Button toggles between C and D
761
    if( depressed ) return -1; // ignore when button depressed
762
    seq_ui_button_state.PAR_LAYER_SEL = 0;
763
    if( par_layer == 3 )
764
      ui_selected_par_layer = (ui_selected_par_layer == 3) ? 4 : 3;
765
    else
766
      ui_selected_par_layer = par_layer;
767
  } else {
768
    // >4 layers: LayerA/B button selects directly, Layer C button enters layer selection page
769
    if( par_layer <= 1 ) {
770
      if( depressed ) return -1; // ignore when button depressed
771
      seq_ui_button_state.PAR_LAYER_SEL = 0;
772
      ui_selected_par_layer = par_layer;
773
    } else {
774
#if DEFAULT_BEHAVIOUR_BUTTON_PAR_LAYER
775
      if( depressed ) return -1; // ignore when button depressed
776
      seq_ui_button_state.PAR_LAYER_SEL ^= 1; // toggle PARSEL status (will also be released once GP button has been pressed)
777
#else
778
      // set mode
779
      seq_ui_button_state.PAR_LAYER_SEL = depressed ? 0 : 1;
780
#endif
781
 
782
      if( seq_ui_button_state.PAR_LAYER_SEL ) {
783
    ui_parlayer_prev_page = ui_page;
784
    SEQ_UI_PageSet(SEQ_UI_PAGE_PARSEL);
785
      } else {
786
    SEQ_UI_PageSet(ui_parlayer_prev_page);
787
      }
788
    }
789
  }
790
 
178 tk 791
  // set/clear encoder fast function if required
792
  SEQ_UI_InitEncSpeed(1); // auto config
793
 
134 tk 794
  return 0; // no error
795
}
796
 
797
static s32 SEQ_UI_Button_TrgLayer(s32 depressed, u32 trg_layer)
798
{
799
  if( trg_layer >= 3 ) return -2; // max. 3 trglayer buttons
800
 
326 tk 801
  u8 visible_track = SEQ_UI_VisibleTrackGet();
802
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
803
  u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
134 tk 804
 
328 tk 805
  if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 3 ) {
326 tk 806
    // 3 layers: direct selection with LayerA/B/C button
807
    if( depressed ) return -1; // ignore when button depressed
808
    seq_ui_button_state.TRG_LAYER_SEL = 0;
809
    ui_selected_trg_layer = trg_layer;
328 tk 810
  } else if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 4 ) {
326 tk 811
    // 4 layers: LayerC Button toggles between C and D
812
    if( depressed ) return -1; // ignore when button depressed
813
    seq_ui_button_state.TRG_LAYER_SEL = 0;
814
    if( trg_layer == 3 )
815
      ui_selected_trg_layer = (ui_selected_trg_layer == 3) ? 4 : 3;
816
    else
817
      ui_selected_trg_layer = trg_layer;
818
  } else {
333 tk 819
    // >4 layers or drum mode: LayerA/B button selects directly, Layer C button enters trigger selection page
326 tk 820
    // also used for drum tracks
821
    if( trg_layer <= 1 ) {
822
      if( depressed ) return -1; // ignore when button depressed
328 tk 823
      seq_ui_button_state.TRG_LAYER_SEL = 0;
824
      ui_selected_trg_layer = trg_layer;
326 tk 825
    } else {
826
#if DEFAULT_BEHAVIOUR_BUTTON_TRG_LAYER
827
      if( depressed ) return -1; // ignore when button depressed
828
      seq_ui_button_state.TRG_LAYER_SEL ^= 1; // toggle TRGSEL status (will also be released once GP button has been pressed)
829
#else
830
      // set mode
831
      seq_ui_button_state.TRG_LAYER_SEL = depressed ? 0 : 1;
832
#endif
833
 
834
      if( seq_ui_button_state.TRG_LAYER_SEL ) {
835
    ui_trglayer_prev_page = ui_page;
836
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRGSEL);
837
      } else {
838
    SEQ_UI_PageSet(ui_trglayer_prev_page);
839
      }
840
    }
841
  }
842
 
134 tk 843
  return 0; // no error
844
}
845
 
846
 
847
 
848
/////////////////////////////////////////////////////////////////////////////
849
// Button handler
850
/////////////////////////////////////////////////////////////////////////////
851
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
852
{
328 tk 853
  // ensure that selections are matching with track constraints
854
  SEQ_UI_CheckSelections();
855
 
134 tk 856
  switch( pin ) {
168 tk 857
#if BUTTON_GP1 != BUTTON_DISABLED
134 tk 858
    case BUTTON_GP1:   SEQ_UI_Button_GP(pin_value, 0); break;
859
#endif
168 tk 860
#if BUTTON_GP2 != BUTTON_DISABLED
134 tk 861
    case BUTTON_GP2:   SEQ_UI_Button_GP(pin_value, 1); break;
862
#endif
168 tk 863
#if BUTTON_GP3 != BUTTON_DISABLED
134 tk 864
    case BUTTON_GP3:   SEQ_UI_Button_GP(pin_value, 2); break;
865
#endif
168 tk 866
#if BUTTON_GP4 != BUTTON_DISABLED
134 tk 867
    case BUTTON_GP4:   SEQ_UI_Button_GP(pin_value, 3); break;
868
#endif
168 tk 869
#if BUTTON_GP5 != BUTTON_DISABLED
134 tk 870
    case BUTTON_GP5:   SEQ_UI_Button_GP(pin_value, 4); break;
871
#endif
168 tk 872
#if BUTTON_GP6 != BUTTON_DISABLED
134 tk 873
    case BUTTON_GP6:   SEQ_UI_Button_GP(pin_value, 5); break;
874
#endif
168 tk 875
#if BUTTON_GP7 != BUTTON_DISABLED
134 tk 876
    case BUTTON_GP7:   SEQ_UI_Button_GP(pin_value, 6); break;
877
#endif
168 tk 878
#if BUTTON_GP8 != BUTTON_DISABLED
134 tk 879
    case BUTTON_GP8:   SEQ_UI_Button_GP(pin_value, 7); break;
880
#endif
168 tk 881
#if BUTTON_GP9 != BUTTON_DISABLED
134 tk 882
    case BUTTON_GP9:   SEQ_UI_Button_GP(pin_value, 8); break;
883
#endif
168 tk 884
#if BUTTON_GP10 != BUTTON_DISABLED
134 tk 885
    case BUTTON_GP10:  SEQ_UI_Button_GP(pin_value, 9); break;
886
#endif
168 tk 887
#if BUTTON_GP11 != BUTTON_DISABLED
134 tk 888
    case BUTTON_GP11:  SEQ_UI_Button_GP(pin_value, 10); break;
889
#endif
168 tk 890
#if BUTTON_GP12 != BUTTON_DISABLED
134 tk 891
    case BUTTON_GP12:  SEQ_UI_Button_GP(pin_value, 11); break;
892
#endif
168 tk 893
#if BUTTON_GP13 != BUTTON_DISABLED
134 tk 894
    case BUTTON_GP13:  SEQ_UI_Button_GP(pin_value, 12); break;
895
#endif
168 tk 896
#if BUTTON_GP14 != BUTTON_DISABLED
134 tk 897
    case BUTTON_GP14:  SEQ_UI_Button_GP(pin_value, 13); break;
898
#endif
168 tk 899
#if BUTTON_GP15 != BUTTON_DISABLED
134 tk 900
    case BUTTON_GP15:  SEQ_UI_Button_GP(pin_value, 14); break;
901
#endif
168 tk 902
#if BUTTON_GP16 != BUTTON_DISABLED
134 tk 903
    case BUTTON_GP16:  SEQ_UI_Button_GP(pin_value, 15); break;
904
#endif
905
 
168 tk 906
#if BUTTON_LEFT != BUTTON_DISABLED
134 tk 907
    case BUTTON_LEFT:  SEQ_UI_Button_Left(pin_value); break;
908
#endif
168 tk 909
#if BUTTON_RIGHT != BUTTON_DISABLED
134 tk 910
    case BUTTON_RIGHT: SEQ_UI_Button_Right(pin_value); break;
911
#endif
912
 
168 tk 913
#if BUTTON_DOWN != BUTTON_DISABLED
914
    case BUTTON_DOWN:  SEQ_UI_Button_Down(pin_value); break;
915
#endif
916
#if BUTTON_UP != BUTTON_DISABLED
917
    case BUTTON_UP:    SEQ_UI_Button_Up(pin_value); break;
918
#endif
919
 
920
#if BUTTON_SCRUB != BUTTON_DISABLED
134 tk 921
    case BUTTON_SCRUB: SEQ_UI_Button_Scrub(pin_value); break;
922
#endif
168 tk 923
#if BUTTON_METRONOME != BUTTON_DISABLED
134 tk 924
    case BUTTON_METRONOME: SEQ_UI_Button_Metronome(pin_value); break;
925
#endif
926
 
168 tk 927
#if BUTTON_STOP != BUTTON_DISABLED
134 tk 928
    case BUTTON_STOP:  SEQ_UI_Button_Stop(pin_value); break;
929
#endif
168 tk 930
#if BUTTON_PAUSE != BUTTON_DISABLED
134 tk 931
    case BUTTON_PAUSE: SEQ_UI_Button_Pause(pin_value); break;
932
#endif
168 tk 933
#if BUTTON_PLAY != BUTTON_DISABLED
134 tk 934
    case BUTTON_PLAY:  SEQ_UI_Button_Play(pin_value); break;
935
#endif
168 tk 936
#if BUTTON_REW != BUTTON_DISABLED
134 tk 937
    case BUTTON_REW:   SEQ_UI_Button_Rew(pin_value); break;
938
#endif
168 tk 939
#if BUTTON_FWD != BUTTON_DISABLED
134 tk 940
    case BUTTON_FWD:   SEQ_UI_Button_Fwd(pin_value); break;
941
#endif
942
 
168 tk 943
#if BUTTON_F1 != BUTTON_DISABLED
134 tk 944
    case BUTTON_F1:    SEQ_UI_Button_F1(pin_value); break;
945
#endif
168 tk 946
#if BUTTON_F2 != BUTTON_DISABLED
134 tk 947
    case BUTTON_F2:    SEQ_UI_Button_F2(pin_value); break;
948
#endif
168 tk 949
#if BUTTON_F3 != BUTTON_DISABLED
134 tk 950
    case BUTTON_F3:    SEQ_UI_Button_F3(pin_value); break;
951
#endif
168 tk 952
#if BUTTON_F4 != BUTTON_DISABLED
134 tk 953
    case BUTTON_F4:    SEQ_UI_Button_F4(pin_value); break;
954
#endif
955
 
168 tk 956
#if BUTTON_UTILITY != BUTTON_DISABLED
134 tk 957
    case BUTTON_UTILITY: SEQ_UI_Button_Utility(pin_value); break;
958
#endif
168 tk 959
#if BUTTON_COPY != BUTTON_DISABLED
134 tk 960
    case BUTTON_COPY:  SEQ_UI_Button_Copy(pin_value); break;
961
#endif
168 tk 962
#if BUTTON_PASTE != BUTTON_DISABLED
134 tk 963
    case BUTTON_PASTE: SEQ_UI_Button_Paste(pin_value); break;
964
#endif
168 tk 965
#if BUTTON_CLEAR != BUTTON_DISABLED
134 tk 966
    case BUTTON_CLEAR: SEQ_UI_Button_Clear(pin_value); break;
967
#endif
968
 
168 tk 969
#if BUTTON_MENU != BUTTON_DISABLED
134 tk 970
    case BUTTON_MENU:  SEQ_UI_Button_Menu(pin_value); break;
971
#endif
168 tk 972
#if BUTTON_SELECT != BUTTON_DISABLED
134 tk 973
    case BUTTON_SELECT:SEQ_UI_Button_Select(pin_value); break;
974
#endif
168 tk 975
#if BUTTON_EXIT != BUTTON_DISABLED
134 tk 976
    case BUTTON_EXIT:  SEQ_UI_Button_Exit(pin_value); break;
977
#endif
978
 
168 tk 979
#if BUTTON_TRACK1 != BUTTON_DISABLED
134 tk 980
    case BUTTON_TRACK1: SEQ_UI_Button_Track(pin_value, 0); break;
981
#endif
168 tk 982
#if BUTTON_TRACK2 != BUTTON_DISABLED
134 tk 983
    case BUTTON_TRACK2: SEQ_UI_Button_Track(pin_value, 1); break;
984
#endif
168 tk 985
#if BUTTON_TRACK3 != BUTTON_DISABLED
134 tk 986
    case BUTTON_TRACK3: SEQ_UI_Button_Track(pin_value, 2); break;
987
#endif
168 tk 988
#if BUTTON_TRACK4 != BUTTON_DISABLED
134 tk 989
    case BUTTON_TRACK4: SEQ_UI_Button_Track(pin_value, 3); break;
990
#endif
991
 
168 tk 992
#if BUTTON_PAR_LAYER_A != BUTTON_DISABLED
134 tk 993
    case BUTTON_PAR_LAYER_A: SEQ_UI_Button_ParLayer(pin_value, 0); break;
994
#endif
168 tk 995
#if BUTTON_PAR_LAYER_B != BUTTON_DISABLED
134 tk 996
    case BUTTON_PAR_LAYER_B: SEQ_UI_Button_ParLayer(pin_value, 1); break;
997
#endif
168 tk 998
#if BUTTON_PAR_LAYER_C != BUTTON_DISABLED
134 tk 999
    case BUTTON_PAR_LAYER_C: SEQ_UI_Button_ParLayer(pin_value, 2); break;
1000
#endif
1001
 
168 tk 1002
#if BUTTON_EDIT != BUTTON_DISABLED
134 tk 1003
    case BUTTON_EDIT:   SEQ_UI_Button_Edit(pin_value); break;
1004
#endif
168 tk 1005
#if BUTTON_MUTE != BUTTON_DISABLED
134 tk 1006
    case BUTTON_MUTE:   SEQ_UI_Button_Mute(pin_value); break;
1007
#endif
168 tk 1008
#if BUTTON_PATTERN != BUTTON_DISABLED
134 tk 1009
    case BUTTON_PATTERN:SEQ_UI_Button_Pattern(pin_value); break;
1010
#endif
168 tk 1011
#if BUTTON_SONG != BUTTON_DISABLED
134 tk 1012
    case BUTTON_SONG:   SEQ_UI_Button_Song(pin_value); break;
1013
#endif
1014
 
168 tk 1015
#if BUTTON_SOLO != BUTTON_DISABLED
134 tk 1016
    case BUTTON_SOLO:   SEQ_UI_Button_Solo(pin_value); break;
1017
#endif
168 tk 1018
#if BUTTON_FAST != BUTTON_DISABLED
134 tk 1019
    case BUTTON_FAST:   SEQ_UI_Button_Fast(pin_value); break;
1020
#endif
168 tk 1021
#if BUTTON_ALL != BUTTON_DISABLED
134 tk 1022
    case BUTTON_ALL:    SEQ_UI_Button_All(pin_value); break;
1023
#endif
1024
 
168 tk 1025
#if BUTTON_GROUP1 != BUTTON_DISABLED
134 tk 1026
    case BUTTON_GROUP1: SEQ_UI_Button_Group(pin_value, 0); break;
1027
#endif
168 tk 1028
#if BUTTON_GROUP2 != BUTTON_DISABLED
134 tk 1029
    case BUTTON_GROUP2: SEQ_UI_Button_Group(pin_value, 1); break;
1030
#endif
168 tk 1031
#if BUTTON_GROUP3 != BUTTON_DISABLED
134 tk 1032
    case BUTTON_GROUP3: SEQ_UI_Button_Group(pin_value, 2); break;
1033
#endif
168 tk 1034
#if BUTTON_GROUP4 != BUTTON_DISABLED
134 tk 1035
    case BUTTON_GROUP4: SEQ_UI_Button_Group(pin_value, 3); break;
1036
#endif
1037
 
168 tk 1038
#if BUTTON_TRG_LAYER_A != BUTTON_DISABLED
134 tk 1039
    case BUTTON_TRG_LAYER_A: SEQ_UI_Button_TrgLayer(pin_value, 0); break;
1040
#endif
168 tk 1041
#if BUTTON_TRG_LAYER_B != BUTTON_DISABLED
134 tk 1042
    case BUTTON_TRG_LAYER_B: SEQ_UI_Button_TrgLayer(pin_value, 1); break;
1043
#endif
168 tk 1044
#if BUTTON_TRG_LAYER_C != BUTTON_DISABLED
134 tk 1045
    case BUTTON_TRG_LAYER_C: SEQ_UI_Button_TrgLayer(pin_value, 2); break;
1046
#endif
1047
 
168 tk 1048
#if BUTTON_STEP_VIEW != BUTTON_DISABLED
134 tk 1049
    case BUTTON_STEP_VIEW: SEQ_UI_Button_StepView(pin_value); break;
1050
#endif
1051
 
168 tk 1052
#if BUTTON_TAP_TEMPO != BUTTON_DISABLED
134 tk 1053
    case BUTTON_TAP_TEMPO:   SEQ_UI_Button_TapTempo(pin_value); break;
1054
#endif
1055
 
1056
    default:
1057
      return -1; // button function not mapped to physical button
1058
  }
1059
 
1060
  // request display update
159 tk 1061
  seq_ui_display_update_req = 1;
134 tk 1062
 
1063
  return 0; // no error
1064
}
1065
 
1066
 
1067
/////////////////////////////////////////////////////////////////////////////
1068
// Encoder handler
1069
/////////////////////////////////////////////////////////////////////////////
1070
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
1071
{
1072
  if( encoder > 16 )
1073
    return -1; // encoder doesn't exist
1074
 
328 tk 1075
  // ensure that selections are matching with track constraints
1076
  SEQ_UI_CheckSelections();
1077
 
134 tk 1078
  // limit incrementer
1079
  if( incrementer > 3 )
1080
    incrementer = 3;
1081
  else if( incrementer < -3 )
1082
    incrementer = -3;
1083
 
306 tk 1084
  if( !seq_ui_button_state.MENU_PRESSED && ui_encoder_callback != NULL ) {
173 tk 1085
    ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
1086
    ui_cursor_flash_ctr = 0; // ensure that value is visible when it has been changed
134 tk 1087
  }
1088
 
1089
  // request display update
159 tk 1090
  seq_ui_display_update_req = 1;
134 tk 1091
 
1092
  return 0; // no error
1093
}
1094
 
1095
 
1096
/////////////////////////////////////////////////////////////////////////////
1097
// Update LCD messages
1098
// Usually called from background task
1099
/////////////////////////////////////////////////////////////////////////////
1100
s32 SEQ_UI_LCD_Handler(void)
1101
{
159 tk 1102
  if( seq_ui_display_init_req ) {
1103
    seq_ui_display_init_req = 0; // clear request
134 tk 1104
 
278 tk 1105
    // clear force update of LCD
1106
    SEQ_LCD_Clear();
1107
    SEQ_LCD_Update(1);
134 tk 1108
 
168 tk 1109
    // select first menu item
1110
    ui_selected_item = 0;
1111
 
167 tk 1112
    // call init function of current page
272 tk 1113
    if( ui_menu_pages[ui_page].init_callback != NULL )
1114
      ui_menu_pages[ui_page].init_callback(0); // mode
134 tk 1115
 
1116
    // request display update
159 tk 1117
    seq_ui_display_update_req = 1;
134 tk 1118
  }
1119
 
306 tk 1120
  // in MENU page: overrule LCD output so long MENU button is pressed/active
1121
  if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
1122
    SEQ_LCD_CursorSet(0, 0);
1123
    //                      <-------------------------------------->
1124
    //                      0123456789012345678901234567890123456789
1125
    SEQ_LCD_PrintString("Menu Shortcuts:");
1126
    SEQ_LCD_PrintSpaces(25 + 40);
1127
    SEQ_LCD_CursorSet(0, 1);
1128
    SEQ_LCD_PrintString(UI_SHORTCUT_STR); // defined in seq_ui_pages.inc
1129
  } else {
1130
    // perform high priority LCD update request
1131
    if( ui_lcd_callback != NULL )
1132
      ui_lcd_callback(1); // high_prio
167 tk 1133
 
306 tk 1134
    // perform low priority LCD update request if requested
1135
    if( seq_ui_display_update_req ) {
1136
      seq_ui_display_update_req = 0; // clear request
328 tk 1137
 
1138
      // ensure that selections are matching with track constraints
1139
      SEQ_UI_CheckSelections();
1140
 
306 tk 1141
      if( ui_lcd_callback != NULL )
1142
    ui_lcd_callback(0); // no high_prio
1143
    }
134 tk 1144
  }
1145
 
299 tk 1146
  // if SD card message active: copy over the text
1147
  if( sdcard_msg_ctr ) {
1148
    const char animation_l[4][3] = {
1149
      "  ", " >", ">>", "> " };
1150
    const char animation_r[4][3] = {
1151
      "  ", "< ", "<<", " <" };
1152
    int anum = (sdcard_msg_ctr % 1000) / 250;
1153
 
1154
    int line;
1155
    for(line=0; line<2; ++line) {
1156
      SEQ_LCD_CursorSet(40, line);
1157
      SEQ_LCD_PrintFormattedString(" %s| %-20s |%s ",
1158
                   (char *)animation_l[anum],
1159
                   (char *)sdcard_msg[line],
1160
                   (char *)animation_r[anum]);
1161
    }
1162
  }
1163
 
278 tk 1164
  // transfer all changed characters to LCD
1165
  SEQ_LCD_Update(0);
159 tk 1166
 
134 tk 1167
  return 0; // no error
1168
}
1169
 
1170
 
1171
 
1172
/////////////////////////////////////////////////////////////////////////////
1173
// Update all LEDs
1174
// Usually called from background task
1175
/////////////////////////////////////////////////////////////////////////////
1176
s32 SEQ_UI_LED_Handler(void)
1177
{
326 tk 1178
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1179
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1180
 
134 tk 1181
  // track LEDs
167 tk 1182
  SEQ_LED_PinSet(LED_TRACK1, (ui_selected_tracks & (1 << 0)));
1183
  SEQ_LED_PinSet(LED_TRACK2, (ui_selected_tracks & (1 << 1)));
1184
  SEQ_LED_PinSet(LED_TRACK3, (ui_selected_tracks & (1 << 2)));
1185
  SEQ_LED_PinSet(LED_TRACK4, (ui_selected_tracks & (1 << 3)));
134 tk 1186
 
1187
  // parameter layer LEDs
167 tk 1188
  SEQ_LED_PinSet(LED_PAR_LAYER_A, (ui_selected_par_layer == 0));
1189
  SEQ_LED_PinSet(LED_PAR_LAYER_B, (ui_selected_par_layer == 1));
326 tk 1190
  SEQ_LED_PinSet(LED_PAR_LAYER_C, (ui_selected_par_layer >= 2) || seq_ui_button_state.PAR_LAYER_SEL);
134 tk 1191
 
1192
  // group LEDs
167 tk 1193
  SEQ_LED_PinSet(LED_GROUP1, (ui_selected_group == 0));
1194
  SEQ_LED_PinSet(LED_GROUP2, (ui_selected_group == 1));
1195
  SEQ_LED_PinSet(LED_GROUP3, (ui_selected_group == 2));
1196
  SEQ_LED_PinSet(LED_GROUP4, (ui_selected_group == 3));
134 tk 1197
 
1198
  // trigger layer LEDs
328 tk 1199
  SEQ_LED_PinSet(LED_TRG_LAYER_A, (ui_selected_trg_layer == 0));
1200
  SEQ_LED_PinSet(LED_TRG_LAYER_B, (ui_selected_trg_layer == 1));
1201
  SEQ_LED_PinSet(LED_TRG_LAYER_C, (ui_selected_trg_layer >= 2) || seq_ui_button_state.TRG_LAYER_SEL);
134 tk 1202
 
1203
  // remaining LEDs
167 tk 1204
  SEQ_LED_PinSet(LED_EDIT, ui_page == SEQ_UI_PAGE_EDIT);
184 tk 1205
  SEQ_LED_PinSet(LED_MUTE, ui_page == SEQ_UI_PAGE_MUTE);
1206
  SEQ_LED_PinSet(LED_PATTERN, ui_page == SEQ_UI_PAGE_PATTERN);
134 tk 1207
  SEQ_LED_PinSet(LED_SONG, 0);
1208
 
178 tk 1209
  SEQ_LED_PinSet(LED_SOLO, seq_ui_button_state.SOLO);
1210
  SEQ_LED_PinSet(LED_FAST, seq_ui_button_state.FAST_ENCODERS);
1211
  SEQ_LED_PinSet(LED_ALL, seq_ui_button_state.CHANGE_ALL_STEPS);
134 tk 1212
 
193 tk 1213
  SEQ_LED_PinSet(LED_PLAY, SEQ_BPM_IsRunning());
1214
  SEQ_LED_PinSet(LED_STOP, !SEQ_BPM_IsRunning() && !ui_seq_pause);
1215
  SEQ_LED_PinSet(LED_PAUSE, ui_seq_pause);
240 tk 1216
 
1217
  SEQ_LED_PinSet(LED_REW, seq_ui_button_state.REW);
1218
  SEQ_LED_PinSet(LED_FWD, seq_ui_button_state.FWD);
134 tk 1219
 
303 tk 1220
  SEQ_LED_PinSet(LED_STEPVIEW, seq_ui_button_state.STEPVIEW);
134 tk 1221
 
167 tk 1222
  SEQ_LED_PinSet(LED_MENU, seq_ui_button_state.MENU_PRESSED);
178 tk 1223
  SEQ_LED_PinSet(LED_SCRUB, seq_ui_button_state.SCRUB);
1224
  SEQ_LED_PinSet(LED_METRONOME, seq_ui_button_state.METRONOME);
134 tk 1225
 
240 tk 1226
  SEQ_LED_PinSet(LED_UTILITY, ui_page == SEQ_UI_PAGE_UTIL);
1227
  SEQ_LED_PinSet(LED_COPY, seq_ui_button_state.COPY);
1228
  SEQ_LED_PinSet(LED_PASTE, seq_ui_button_state.PASTE);
1229
  SEQ_LED_PinSet(LED_CLEAR, seq_ui_button_state.CLEAR);
1230
 
1231
  SEQ_LED_PinSet(LED_F1, seq_ui_button_state.F1);
1232
  SEQ_LED_PinSet(LED_F2, seq_ui_button_state.F2);
1233
  SEQ_LED_PinSet(LED_F3, seq_ui_button_state.F3);
1234
  SEQ_LED_PinSet(LED_F4, seq_ui_button_state.F4);
1235
 
1236
  SEQ_LED_PinSet(LED_DOWN, seq_ui_button_state.DOWN);
1237
  SEQ_LED_PinSet(LED_UP, seq_ui_button_state.UP);
1238
 
167 tk 1239
 
306 tk 1240
  // in MENU page: overrule GP LEDs so long MENU button is pressed/active
1241
  if( seq_ui_button_state.MENU_PRESSED ) {
1242
    if( ui_cursor_flash ) // if flashing flag active: no LED flag set
1243
      ui_gp_leds = 0x0000;
1244
    else {
1245
      int i;
1246
      u16 new_ui_gp_leds = 0x0000;
1247
      for(i=0; i<16; ++i)
1248
    if( ui_page == ui_shortcut_menu_pages[i] )
1249
      new_ui_gp_leds |= (1 << i);
1250
      ui_gp_leds = new_ui_gp_leds;
1251
    }
1252
  } else {
1253
    // note: the background function is permanently interrupted - therefore we write the GP pattern
1254
    // into a temporary variable, and take it over once completed
1255
    u16 new_ui_gp_leds = 0x0000;
1256
    // request GP LED values from current menu page
1257
    // will be transfered to DOUT registers in SEQ_UI_LED_Handler_Periodic
1258
    new_ui_gp_leds = 0x0000;
206 tk 1259
 
306 tk 1260
    if( ui_led_callback != NULL )
1261
      ui_led_callback(&new_ui_gp_leds);
167 tk 1262
 
306 tk 1263
    ui_gp_leds = new_ui_gp_leds;
1264
  }
1265
 
134 tk 1266
  return 0; // no error
1267
}
1268
 
1269
 
1270
/////////////////////////////////////////////////////////////////////////////
1271
// updates high-prio LED functions (GP LEDs and Beat LED)
168 tk 1272
// called each mS
134 tk 1273
/////////////////////////////////////////////////////////////////////////////
1274
s32 SEQ_UI_LED_Handler_Periodic()
1275
{
1276
  // GP LEDs are only updated when ui_gp_leds or pos_marker_mask has changed
1277
  static u16 prev_ui_gp_leds = 0x0000;
1278
  static u16 prev_pos_marker_mask = 0x0000;
1279
 
1280
  // beat LED: tmp. for demo w/o real sequencer
193 tk 1281
  u8 sequencer_running = SEQ_BPM_IsRunning();
325 tk 1282
  SEQ_LED_PinSet(LED_BEAT, sequencer_running && ((seq_core_state.ref_step & 3) == 0));
134 tk 1283
 
1284
  // for song position marker (supports 16 LEDs, check for selected step view)
1285
  u16 pos_marker_mask = 0x0000;
325 tk 1286
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1287
  u8 played_step = seq_core_trk[visible_track].step;
1288
  if( seq_ui_button_state.STEPVIEW ) {
1289
    // if STEPVIEW button pressed: pos marker correlated to zoom ratio
1290
    if( sequencer_running )
1291
      pos_marker_mask = 1 << (played_step / (SEQ_TRG_NumStepsGet(visible_track)/16));
1292
  } else {
1293
    if( sequencer_running && (played_step >> 4) == ui_selected_step_view )
1294
      pos_marker_mask = 1 << (played_step & 0xf);
1295
  }
134 tk 1296
 
1297
  // exit of pattern hasn't changed
173 tk 1298
  if( prev_ui_gp_leds == ui_gp_leds && prev_pos_marker_mask == pos_marker_mask )
134 tk 1299
    return 0;
173 tk 1300
  prev_ui_gp_leds = ui_gp_leds;
134 tk 1301
  prev_pos_marker_mask = pos_marker_mask;
1302
 
1303
  // transfer to GP LEDs
1304
 
1305
#ifdef DEFAULT_GP_DOUT_SR_L
1306
# ifdef DEFAULT_GP_DOUT_SR_L2
173 tk 1307
  SEQ_LED_SRSet(DEFAULT_GP_DOUT_SR_L-1, (ui_gp_leds >> 0) & 0xff);
134 tk 1308
# else
173 tk 1309
  SEQ_LED_SRSet(DEFAULT_GP_DOUT_SR_L-1, ((ui_gp_leds ^ pos_marker_mask) >> 0) & 0xff);
134 tk 1310
# endif
1311
#endif
1312
#ifdef DEFAULT_GP_DOUT_SR_R
1313
# ifdef DEFAULT_GP_DOUT_SR_R2
173 tk 1314
  SEQ_LED_SRSet(DEFAULT_GP_DOUT_SR_R-1, (ui_gp_leds >> 8) & 0xff);
134 tk 1315
#else
173 tk 1316
  SEQ_LED_SRSet(DEFAULT_GP_DOUT_SR_R-1, ((ui_gp_leds ^ pos_marker_mask) >> 8) & 0xff);
134 tk 1317
#endif
1318
#endif
1319
 
1320
#ifdef DEFAULT_GP_DOUT_SR_L2
1321
  SEQ_LED_SRSet(DEFAULT_GP_DOUT_SR_L2-1, (pos_marker_mask >> 0) & 0xff);
1322
#endif
1323
#ifdef DEFAULT_GP_DOUT_SR_R2
1324
  SEQ_LED_SRSet(DEFAULT_GP_DOUT_SR_R2-1, (pos_marker_mask >> 8) & 0xff);
1325
#endif
1326
 
1327
#if DEFAULT_SRM_ENABLED && DEFAULT_SRM_DOUT_M_MAPPING == 1
1328
  // for wilba's frontpanel
1329
 
1330
  // BLM8X8 DOUT -> GP LED mapping
1331
  // 0 = 15,16  1 = 13,14   2 = 11,12   3 = 9,10
1332
  // 4 = 1,2    5 = 3,4     6 = 5,6     7 = 7,8
1333
 
1334
  // bit 7: first green (i.e. GP1-G)
1335
  // bit 6: first red (i.e. GP1-R)
1336
  // bit 5: second green (i.e. GP2-G)
1337
  // bit 4: second red (i.e. GP2-R)
1338
 
1339
  // this mapping routine takes ca. 5 uS
173 tk 1340
  // since it's only executed when ui_gp_leds or gp_mask has changed, it doesn't really hurt
134 tk 1341
 
173 tk 1342
  u16 modified_gp_leds = ui_gp_leds;
134 tk 1343
#if 1
1344
  // extra: red LED is lit exclusively for higher contrast
1345
  modified_gp_leds &= ~pos_marker_mask;
1346
#endif
1347
 
1348
  int sr;
1349
  const u8 blm8x8_sr_map[8] = {4, 5, 6, 7, 3, 2, 1, 0};
1350
  u16 gp_mask = 1 << 0;
1351
  for(sr=0; sr<8; ++sr) {
1352
    u8 pattern = 0;
1353
 
1354
    if( modified_gp_leds & gp_mask )
1355
      pattern |= 0x80;
1356
    if( pos_marker_mask & gp_mask )
1357
      pattern |= 0x40;
1358
    gp_mask <<= 1;
1359
    if( modified_gp_leds & gp_mask )
1360
      pattern |= 0x20;
1361
    if( pos_marker_mask & gp_mask )
1362
      pattern |= 0x10;
1363
    gp_mask <<= 1;
1364
 
1365
    u8 mapped_sr = blm8x8_sr_map[sr];
1366
    blm8x8_led_row[mapped_sr] = (blm8x8_led_row[mapped_sr] & 0x0f) | pattern;
1367
  }
1368
#endif
1369
 
184 tk 1370
  return 0; // no error
134 tk 1371
}
1372
 
1373
 
1374
/////////////////////////////////////////////////////////////////////////////
168 tk 1375
// for menu handling (e.g. flashing cursor, doubleclick counter, etc...)
1376
// called each mS
1377
/////////////////////////////////////////////////////////////////////////////
1378
s32 SEQ_UI_MENU_Handler_Periodic()
1379
{
1380
  if( ++ui_cursor_flash_ctr >= SEQ_UI_CURSOR_FLASH_CTR_MAX ) {
1381
    ui_cursor_flash_ctr = 0;
1382
    seq_ui_display_update_req = 1;
173 tk 1383
  } else if( ui_cursor_flash_ctr == SEQ_UI_CURSOR_FLASH_CTR_LED_OFF ) {
168 tk 1384
    seq_ui_display_update_req = 1;
173 tk 1385
  }
1386
  // important: flash flag has to be recalculated on each invocation of this
1387
  // handler, since counter could also be reseted outside this function
1388
  ui_cursor_flash = ui_cursor_flash_ctr >= SEQ_UI_CURSOR_FLASH_CTR_LED_OFF;
168 tk 1389
 
184 tk 1390
 
240 tk 1391
  // used in some pages for temporary messages
1392
  if( ui_hold_msg_ctr )
1393
    --ui_hold_msg_ctr;
1394
 
299 tk 1395
  // used for temporary SD Card messages
1396
  if( sdcard_msg_ctr )
1397
    --sdcard_msg_ctr;
1398
 
184 tk 1399
  // VU meters (used in MUTE menu, could also be available as LED matrix...)
1400
  static u8 vu_meter_prediv = 0; // predivider for VU meters
1401
 
1402
  if( ++vu_meter_prediv >= 4 ) {
1403
    vu_meter_prediv = 0;
1404
 
333 tk 1405
 
1406
    portENTER_CRITICAL();
1407
 
184 tk 1408
    u8 track;
1409
    seq_core_trk_t *t = &seq_core_trk[0];
1410
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++t, ++track)
1411
      if( t->vu_meter )
1412
    --t->vu_meter;
333 tk 1413
 
1414
    int i;
1415
    u8 *vu_meter = (u8 *)&seq_layer_vu_meter[0];
1416
    for(i=0; i<sizeof(seq_layer_vu_meter); ++i, ++vu_meter) {
1417
      if( *vu_meter && !(*vu_meter & 0x80) ) // if bit 7 set: static value
1418
    *vu_meter -= 1;
1419
    }
1420
 
318 tk 1421
    portEXIT_CRITICAL();
184 tk 1422
  }
1423
 
168 tk 1424
  return 0;
1425
}
1426
 
1427
 
1428
/////////////////////////////////////////////////////////////////////////////
328 tk 1429
// Should be regulary called to check if the layer/instrument/step selection
1430
// is valid for the current track
1431
// At least executed before button/encoder and LCD function calls
1432
/////////////////////////////////////////////////////////////////////////////
1433
s32 SEQ_UI_CheckSelections(void)
1434
{
1435
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1436
 
1437
  if( ui_selected_instrument >= SEQ_PAR_NumInstrumentsGet(visible_track) )
1438
    ui_selected_instrument = 0;
1439
 
1440
  if( ui_selected_par_layer >= SEQ_PAR_NumLayersGet(visible_track) )
1441
    ui_selected_par_layer = 0;
1442
 
1443
  if( ui_selected_trg_layer >= SEQ_TRG_NumLayersGet(visible_track) )
1444
    ui_selected_trg_layer = 0;
1445
 
1446
  if( ui_selected_step >= SEQ_TRG_NumStepsGet(visible_track) )
1447
    ui_selected_step = 0;
1448
 
1449
  if( ui_selected_step_view >= (SEQ_TRG_NumStepsGet(visible_track)/16) ) {
1450
    ui_selected_step_view = 0;
1451
    ui_selected_step %= 16;
1452
  }
1453
 
1454
  if( ui_selected_step >= ui_selected_step_view*16 )
1455
    ui_selected_step_view = ui_selected_step / 16;
1456
 
1457
  return 0; // no error
1458
}
1459
 
1460
 
1461
/////////////////////////////////////////////////////////////////////////////
134 tk 1462
// Returns the currently visible track
1463
/////////////////////////////////////////////////////////////////////////////
1464
u8 SEQ_UI_VisibleTrackGet(void)
1465
{
1466
  u8 offset = 0;
1467
 
1468
  if( ui_selected_tracks & (1 << 3) )
1469
    offset = 3;
1470
  if( ui_selected_tracks & (1 << 2) )
1471
    offset = 2;
1472
  if( ui_selected_tracks & (1 << 1) )
1473
    offset = 1;
1474
  if( ui_selected_tracks & (1 << 0) )
1475
    offset = 0;
1476
 
1477
  return 4*ui_selected_group + offset;
1478
}
1479
 
168 tk 1480
 
1481
/////////////////////////////////////////////////////////////////////////////
178 tk 1482
// Returns 1 if 'track' is selected
1483
/////////////////////////////////////////////////////////////////////////////
1484
s32 SEQ_UI_IsSelectedTrack(u8 track)
1485
{
1486
  if( (track>>2) != ui_selected_group )
1487
    return 0;
1488
  return (ui_selected_tracks & (1 << (track&3))) ? 1 : 0;
1489
}
1490
 
1491
 
1492
/////////////////////////////////////////////////////////////////////////////
240 tk 1493
// Sets a new selected step and updates the step view
1494
/////////////////////////////////////////////////////////////////////////////
1495
s32 SEQ_UI_SelectedStepSet(u8 step)
1496
{
1497
  ui_selected_step = step;
328 tk 1498
  SEQ_UI_CheckSelections();
1499
 
240 tk 1500
  return 0; // no error
1501
}
1502
 
1503
 
1504
/////////////////////////////////////////////////////////////////////////////
168 tk 1505
// Increments the selected tracks/groups
1506
// OUT: 1 if value has been changed, otherwise 0
1507
/////////////////////////////////////////////////////////////////////////////
1508
s32 SEQ_UI_GxTyInc(s32 incrementer)
1509
{
1510
  int gxty = SEQ_UI_VisibleTrackGet();
1511
  int prev_gxty = gxty;
1512
 
1513
  if( incrementer >= 0 ) {
1514
    if( (gxty += incrementer) >= SEQ_CORE_NUM_TRACKS )
1515
      gxty = SEQ_CORE_NUM_TRACKS-1;
1516
  } else {
1517
    if( (gxty += incrementer) < 0 )
1518
      gxty = 0;
1519
  }
1520
 
1521
  if( gxty == prev_gxty )
1522
    return 0; // no change
1523
 
1524
  ui_selected_tracks = 1 << (gxty % 4);
1525
  ui_selected_group = gxty / 4;
1526
 
1527
  return 1; // value changed
1528
}
1529
 
1530
 
1531
/////////////////////////////////////////////////////////////////////////////
236 tk 1532
// Increments a 16bit variable within given min/max range
1533
// OUT: 1 if value has been changed, otherwise 0
1534
/////////////////////////////////////////////////////////////////////////////
240 tk 1535
s32 SEQ_UI_Var16_Inc(u16 *value, u16 min, u16 max, s32 incrementer)
236 tk 1536
{
1537
  int new_value = *value;
1538
  int prev_value = new_value;
1539
 
1540
  if( incrementer >= 0 ) {
1541
    if( (new_value += incrementer) >= max )
1542
      new_value = max;
1543
  } else {
1544
    if( (new_value += incrementer) < min )
1545
      new_value = min;
1546
  }
1547
 
1548
  if( new_value == prev_value )
1549
    return 0; // no change
1550
 
1551
  *value = new_value;
1552
 
1553
  return 1; // value changed
1554
}
1555
 
240 tk 1556
/////////////////////////////////////////////////////////////////////////////
1557
// Increments an 8bit variable within given min/max range
1558
// OUT: 1 if value has been changed, otherwise 0
1559
/////////////////////////////////////////////////////////////////////////////
1560
s32 SEQ_UI_Var8_Inc(u8 *value, u16 min, u16 max, s32 incrementer)
1561
{
1562
  u16 tmp = *value;
1563
  if( SEQ_UI_Var16_Inc(&tmp, min, max, incrementer) ) {
1564
    *value = tmp;
1565
    return 1; // value changed
1566
  }
236 tk 1567
 
240 tk 1568
  return 0; // value hasn't been changed
1569
}
1570
 
1571
 
236 tk 1572
/////////////////////////////////////////////////////////////////////////////
168 tk 1573
// Increments a CC within given min/max range
1574
// OUT: 1 if value has been changed, otherwise 0
1575
/////////////////////////////////////////////////////////////////////////////
248 tk 1576
s32 SEQ_UI_CC_Inc(u8 cc, u8 min, u8 max, s32 incrementer)
168 tk 1577
{
1578
  u8 visible_track = SEQ_UI_VisibleTrackGet();
173 tk 1579
  int new_value = SEQ_CC_Get(visible_track, cc);
1580
  int prev_value = new_value;
168 tk 1581
 
1582
  if( incrementer >= 0 ) {
173 tk 1583
    if( (new_value += incrementer) >= max )
1584
      new_value = max;
168 tk 1585
  } else {
173 tk 1586
    if( (new_value += incrementer) < min )
1587
      new_value = min;
168 tk 1588
  }
1589
 
173 tk 1590
  if( new_value == prev_value )
168 tk 1591
    return 0; // no change
1592
 
173 tk 1593
  SEQ_CC_Set(visible_track, cc, new_value);
168 tk 1594
 
179 tk 1595
  // set same value for all selected tracks
1596
  u8 track;
1597
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1598
    if( track != visible_track && SEQ_UI_IsSelectedTrack(track) )
1599
      SEQ_CC_Set(track, cc, new_value);
1600
 
168 tk 1601
  return 1; // value changed
1602
}
1603
 
173 tk 1604
 
1605
/////////////////////////////////////////////////////////////////////////////
179 tk 1606
// Sets a CC value on all selected tracks
1607
// OUT: 1 if value has been changed, otherwise 0
1608
/////////////////////////////////////////////////////////////////////////////
248 tk 1609
s32 SEQ_UI_CC_Set(u8 cc, u8 value)
179 tk 1610
{
1611
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1612
  int prev_value = SEQ_CC_Get(visible_track, cc);
1613
 
1614
  if( value == prev_value )
1615
    return 0; // no change
1616
 
1617
  SEQ_CC_Set(visible_track, cc, value);
1618
 
1619
  // set same value for all selected tracks
1620
  u8 track;
1621
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1622
    if( track != visible_track && SEQ_UI_IsSelectedTrack(track) )
1623
      SEQ_CC_Set(track, cc, value);
1624
 
1625
  return 1; // value changed
1626
}
1627
 
1628
/////////////////////////////////////////////////////////////////////////////
173 tk 1629
// Modifies a bitfield in a CC value to a given value
1630
// OUT: 1 if value has been changed, otherwise 0
1631
/////////////////////////////////////////////////////////////////////////////
248 tk 1632
s32 SEQ_UI_CC_SetFlags(u8 cc, u8 flag_mask, u8 value)
173 tk 1633
{
1634
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1635
  int new_value = SEQ_CC_Get(visible_track, cc);
1636
  int prev_value = new_value;
1637
 
1638
  new_value = (new_value & ~flag_mask) | value;
1639
 
1640
  if( new_value == prev_value )
1641
    return 0; // no change
1642
 
1643
  SEQ_CC_Set(visible_track, cc, new_value);
1644
 
179 tk 1645
  // do same modification for all selected tracks
1646
  u8 track;
1647
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1648
    if( track != visible_track && SEQ_UI_IsSelectedTrack(track) ) {
1649
      int new_value = SEQ_CC_Get(track, cc);
1650
      new_value = (new_value & ~flag_mask) | value;
1651
      SEQ_CC_Set(track, cc, new_value);
1652
    }
1653
 
173 tk 1654
  return 1; // value changed
1655
}
1656
 
1657
 
299 tk 1658
/////////////////////////////////////////////////////////////////////////////
1659
// Print temporary messages after file operations
1660
// expects mS delay and two lines, each up to 20 characters
1661
/////////////////////////////////////////////////////////////////////////////
1662
s32 SEQ_UI_SDCardMsg(u16 delay, char *line1, char *line2)
1663
{
1664
  sdcard_msg_ctr = delay;
1665
  strncpy((char *)sdcard_msg[0], line1, SDCARD_MSG_MAX_CHAR);
1666
  strncpy((char *)sdcard_msg[1], line2, SDCARD_MSG_MAX_CHAR);
1667
 
1668
  return 0; // no error
1669
}
1670
 
1671
/////////////////////////////////////////////////////////////////////////////
1672
// Prints a temporary error messages after file operation
1673
// Expects error status number (as defined in seq_file.h)
1674
/////////////////////////////////////////////////////////////////////////////
1675
s32 SEQ_UI_SDCardErrMsg(u16 delay, s32 status)
1676
{
1677
  // TODO: add more verbose error messages, they are clearly defined in seq_file.h)
1678
  char str[21];
1679
  sprintf(str, "E%3d (DOSFS: D%3d)", -status, seq_file_dfs_errno < 1000 ? seq_file_dfs_errno : 999);
1680
  return SEQ_UI_SDCardMsg(delay, "!! SD Card Error !!!", str);
1681
}