Subversion Repositories svn.mios32

Rev

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