Subversion Repositories svn.mios32

Rev

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