Subversion Repositories svn.mios32

Rev

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