Subversion Repositories svn.mios32

Rev

Rev 514 | Rev 544 | 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 524 2009-05-16 20:11:13Z tk $
2
/*
3
 * User Interface Routines
4
 *
336 tk 5
 * TODO: allow to loop the selected view while editing a track
6
 * TODO: add loop fx page for setting loop point interactively
7
 * TODO: scroll function should use this loop point
8
 * TODO: utility page in drum mode: allow to handle only selected instrument
9
 *
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
 
913
 
914
/////////////////////////////////////////////////////////////////////////////
915
// Button handler
916
/////////////////////////////////////////////////////////////////////////////
917
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
918
{
492 tk 919
  int i;
920
 
496 tk 921
  // ignore so long hardware config hasn't been read
922
  if( !SEQ_FILE_HW_ConfigLocked() )
923
    return -1;
924
 
328 tk 925
  // ensure that selections are matching with track constraints
926
  SEQ_UI_CheckSelections();
927
 
492 tk 928
  // request display update
929
  seq_ui_display_update_req = 1;
134 tk 930
 
931
 
492 tk 932
  // MEMO: we could also use a jump table with references to the functions
933
  // here, but this "spagetthi code" simplifies the configuration and
934
  // the resulting ASM doesn't look that bad!
168 tk 935
 
492 tk 936
  for(i=0; i<SEQ_HWCFG_NUM_GP; ++i)
937
    if( pin == seq_hwcfg_button.gp[i] )
938
      return SEQ_UI_Button_GP(pin_value, i);
134 tk 939
 
492 tk 940
  for(i=0; i<SEQ_HWCFG_NUM_TRACK; ++i)
941
    if( pin == seq_hwcfg_button.track[i] )
942
      return SEQ_UI_Button_Track(pin_value, i);
513 tk 943
  if( pin == seq_hwcfg_button.track_sel )
944
    return SEQ_UI_Button_TrackSel(pin_value);
134 tk 945
 
492 tk 946
  for(i=0; i<SEQ_HWCFG_NUM_GROUP; ++i)
947
    if( pin == seq_hwcfg_button.group[i] )
948
      return SEQ_UI_Button_Group(pin_value, i);
134 tk 949
 
492 tk 950
  for(i=0; i<SEQ_HWCFG_NUM_PAR_LAYER; ++i)
951
    if( pin == seq_hwcfg_button.par_layer[i] )
952
      return SEQ_UI_Button_ParLayer(pin_value, i);
513 tk 953
  if( pin == seq_hwcfg_button.par_layer_sel )
954
    return SEQ_UI_Button_ParLayerSel(pin_value);
134 tk 955
 
492 tk 956
  for(i=0; i<SEQ_HWCFG_NUM_TRG_LAYER; ++i)
957
    if( pin == seq_hwcfg_button.trg_layer[i] )
958
      return SEQ_UI_Button_TrgLayer(pin_value, i);
513 tk 959
  if( pin == seq_hwcfg_button.trg_layer_sel )
960
    return SEQ_UI_Button_TrgLayerSel(pin_value);
134 tk 961
 
492 tk 962
  if( pin == seq_hwcfg_button.left )
963
    return SEQ_UI_Button_Left(pin_value);
964
  if( pin == seq_hwcfg_button.right )
965
    return SEQ_UI_Button_Right(pin_value);
966
  if( pin == seq_hwcfg_button.down )
967
    return SEQ_UI_Button_Down(pin_value);
968
  if( pin == seq_hwcfg_button.up )
969
    return SEQ_UI_Button_Up(pin_value);
134 tk 970
 
492 tk 971
  if( pin == seq_hwcfg_button.scrub )
972
    return SEQ_UI_Button_Scrub(pin_value);
973
  if( pin == seq_hwcfg_button.metronome )
974
    return SEQ_UI_Button_Metronome(pin_value);
134 tk 975
 
492 tk 976
  if( pin == seq_hwcfg_button.stop )
977
    return SEQ_UI_Button_Stop(pin_value);
978
  if( pin == seq_hwcfg_button.pause )
979
    return SEQ_UI_Button_Pause(pin_value);
980
  if( pin == seq_hwcfg_button.play )
981
    return SEQ_UI_Button_Play(pin_value);
982
  if( pin == seq_hwcfg_button.rew )
983
    return SEQ_UI_Button_Rew(pin_value);
984
  if( pin == seq_hwcfg_button.fwd )
985
    return SEQ_UI_Button_Fwd(pin_value);
134 tk 986
 
492 tk 987
  if( pin == seq_hwcfg_button.utility )
988
    return SEQ_UI_Button_Utility(pin_value);
989
  if( pin == seq_hwcfg_button.copy )
990
    return SEQ_UI_Button_Copy(pin_value);
991
  if( pin == seq_hwcfg_button.paste )
992
    return SEQ_UI_Button_Paste(pin_value);
993
  if( pin == seq_hwcfg_button.clear )
994
    return SEQ_UI_Button_Clear(pin_value);
134 tk 995
 
492 tk 996
  if( pin == seq_hwcfg_button.menu )
997
    return SEQ_UI_Button_Menu(pin_value);
998
  if( pin == seq_hwcfg_button.select )
999
    return SEQ_UI_Button_Select(pin_value);
1000
  if( pin == seq_hwcfg_button.exit )
1001
    return SEQ_UI_Button_Exit(pin_value);
134 tk 1002
 
513 tk 1003
  if( pin == seq_hwcfg_button.tap_tempo )
1004
    return SEQ_UI_Button_TapTempo(pin_value);
1005
  if( pin == seq_hwcfg_button.tempo_preset )
1006
    return SEQ_UI_Button_TempoPreset(pin_value);
524 tk 1007
  if( pin == seq_hwcfg_button.ext_restart )
1008
    return SEQ_UI_Button_ExtRestart(pin_value);
134 tk 1009
 
492 tk 1010
  if( pin == seq_hwcfg_button.edit )
1011
    return SEQ_UI_Button_Edit(pin_value);
1012
  if( pin == seq_hwcfg_button.mute )
1013
    return SEQ_UI_Button_Mute(pin_value);
1014
  if( pin == seq_hwcfg_button.pattern )
1015
    return SEQ_UI_Button_Pattern(pin_value);
1016
  if( pin == seq_hwcfg_button.song )
1017
    return SEQ_UI_Button_Song(pin_value);
134 tk 1018
 
492 tk 1019
  if( pin == seq_hwcfg_button.solo )
1020
    return SEQ_UI_Button_Solo(pin_value);
1021
  if( pin == seq_hwcfg_button.fast )
1022
    return SEQ_UI_Button_Fast(pin_value);
1023
  if( pin == seq_hwcfg_button.all )
1024
    return SEQ_UI_Button_All(pin_value);
134 tk 1025
 
492 tk 1026
  if( pin == seq_hwcfg_button.step_view )
1027
    return SEQ_UI_Button_StepView(pin_value);
1028
  if( pin == seq_hwcfg_button.tap_tempo )
1029
    return SEQ_UI_Button_TapTempo(pin_value);
134 tk 1030
 
492 tk 1031
  return -1; // button not mapped
134 tk 1032
}
1033
 
1034
 
1035
/////////////////////////////////////////////////////////////////////////////
524 tk 1036
// BLM Button handler
1037
/////////////////////////////////////////////////////////////////////////////
1038
s32 SEQ_UI_BLM_Button_Handler(u32 row, u32 pin, u32 pin_value)
1039
{
1040
  // ignore so long hardware config hasn't been read
1041
  if( !SEQ_FILE_HW_ConfigLocked() )
1042
    return -1;
1043
 
1044
  if( row >= SEQ_CORE_NUM_TRACKS_PER_GROUP )
1045
    return -1; // more than 4 tracks not supported (yet) - could be done in this function w/o much effort
1046
 
1047
  if( pin >= 16 )
1048
    return -1; // more than 16 step buttons not supported (yet) - could be done by selecting the step view
1049
 
1050
  // select track depending on row
1051
  ui_selected_tracks = 1 << (row + 4*ui_selected_group);
1052
 
1053
  // ensure that selections are matching with track constraints
1054
  SEQ_UI_CheckSelections();
1055
 
1056
  // request display update
1057
  seq_ui_display_update_req = 1;
1058
 
1059
  // emulate general purpose button
1060
  return SEQ_UI_Button_GP(pin_value, pin);
1061
}
1062
 
1063
 
1064
/////////////////////////////////////////////////////////////////////////////
134 tk 1065
// Encoder handler
1066
/////////////////////////////////////////////////////////////////////////////
1067
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
1068
{
496 tk 1069
  // ignore so long hardware config hasn't been read
1070
  if( !SEQ_FILE_HW_ConfigLocked() )
1071
    return -1;
1072
 
134 tk 1073
  if( encoder > 16 )
1074
    return -1; // encoder doesn't exist
1075
 
328 tk 1076
  // ensure that selections are matching with track constraints
1077
  SEQ_UI_CheckSelections();
1078
 
134 tk 1079
  // limit incrementer
1080
  if( incrementer > 3 )
1081
    incrementer = 3;
1082
  else if( incrementer < -3 )
1083
    incrementer = -3;
1084
 
306 tk 1085
  if( !seq_ui_button_state.MENU_PRESSED && ui_encoder_callback != NULL ) {
173 tk 1086
    ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
1087
    ui_cursor_flash_ctr = 0; // ensure that value is visible when it has been changed
134 tk 1088
  }
1089
 
1090
  // request display update
159 tk 1091
  seq_ui_display_update_req = 1;
134 tk 1092
 
1093
  return 0; // no error
1094
}
1095
 
1096
 
353 tk 1097
 
134 tk 1098
/////////////////////////////////////////////////////////////////////////////
1099
// Update LCD messages
1100
// Usually called from background task
1101
/////////////////////////////////////////////////////////////////////////////
1102
s32 SEQ_UI_LCD_Handler(void)
1103
{
159 tk 1104
  if( seq_ui_display_init_req ) {
1105
    seq_ui_display_init_req = 0; // clear request
134 tk 1106
 
278 tk 1107
    // clear force update of LCD
1108
    SEQ_LCD_Clear();
1109
    SEQ_LCD_Update(1);
134 tk 1110
 
168 tk 1111
    // select first menu item
1112
    ui_selected_item = 0;
1113
 
167 tk 1114
    // call init function of current page
272 tk 1115
    if( ui_menu_pages[ui_page].init_callback != NULL )
1116
      ui_menu_pages[ui_page].init_callback(0); // mode
134 tk 1117
 
1118
    // request display update
159 tk 1119
    seq_ui_display_update_req = 1;
134 tk 1120
  }
1121
 
496 tk 1122
  // print boot screen so long hardware config hasn't been read
1123
  if( !SEQ_FILE_HW_ConfigLocked() ) {
1124
    SEQ_LCD_Clear();
306 tk 1125
    SEQ_LCD_CursorSet(0, 0);
496 tk 1126
    //                   <-------------------------------------->
1127
    //                   0123456789012345678901234567890123456789
1128
    SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE1);
1129
    SEQ_LCD_CursorSet(40, 0);
1130
    SEQ_LCD_PrintString("Searching for SD Card...");
1131
    SEQ_LCD_CursorSet(0, 1);
1132
    SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE2);
1133
    // TODO: print nice animation
1134
  } else if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
1135
    SEQ_LCD_CursorSet(0, 0);
1136
    //                   <-------------------------------------->
1137
    //                   0123456789012345678901234567890123456789
306 tk 1138
    SEQ_LCD_PrintString("Menu Shortcuts:");
1139
    SEQ_LCD_PrintSpaces(25 + 40);
1140
    SEQ_LCD_CursorSet(0, 1);
1141
    SEQ_LCD_PrintString(UI_SHORTCUT_STR); // defined in seq_ui_pages.inc
1142
  } else {
1143
    // perform high priority LCD update request
1144
    if( ui_lcd_callback != NULL )
1145
      ui_lcd_callback(1); // high_prio
167 tk 1146
 
306 tk 1147
    // perform low priority LCD update request if requested
1148
    if( seq_ui_display_update_req ) {
1149
      seq_ui_display_update_req = 0; // clear request
328 tk 1150
 
1151
      // ensure that selections are matching with track constraints
1152
      SEQ_UI_CheckSelections();
1153
 
306 tk 1154
      if( ui_lcd_callback != NULL )
1155
    ui_lcd_callback(0); // no high_prio
1156
    }
134 tk 1157
  }
1158
 
353 tk 1159
  // transfer all changed characters to LCD
1160
  SEQ_UI_LCD_Update();
1161
 
1162
  return 0; // no error
1163
}
1164
 
1165
 
1166
/////////////////////////////////////////////////////////////////////////////
1167
// Called from SEQ_UI_LCD_Handler(), but optionally also from other tasks
1168
// to update the LCD screen immediately
1169
/////////////////////////////////////////////////////////////////////////////
1170
s32 SEQ_UI_LCD_Update(void)
1171
{
299 tk 1172
  // if SD card message active: copy over the text
1173
  if( sdcard_msg_ctr ) {
1174
    const char animation_l[4][3] = {
1175
      "  ", " >", ">>", "> " };
1176
    const char animation_r[4][3] = {
1177
      "  ", "< ", "<<", " <" };
1178
    int anum = (sdcard_msg_ctr % 1000) / 250;
1179
 
1180
    int line;
1181
    for(line=0; line<2; ++line) {
353 tk 1182
      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 1183
      SEQ_LCD_PrintFormattedString(" %s| %-20s |%s ",
1184
                   (char *)animation_l[anum],
1185
                   (char *)sdcard_msg[line],
1186
                   (char *)animation_r[anum]);
1187
    }
1188
  }
1189
 
278 tk 1190
  // transfer all changed characters to LCD
353 tk 1191
  // SEQ_LCD_Update provides a MUTEX handling to allow updates from different tasks
1192
  return SEQ_LCD_Update(0);
134 tk 1193
}
1194
 
1195
 
1196
/////////////////////////////////////////////////////////////////////////////
1197
// Update all LEDs
1198
// Usually called from background task
1199
/////////////////////////////////////////////////////////////////////////////
1200
s32 SEQ_UI_LED_Handler(void)
1201
{
524 tk 1202
  int i;
1203
 
496 tk 1204
  // ignore so long hardware config hasn't been read
1205
  if( !SEQ_FILE_HW_ConfigLocked() )
1206
    return -1;
1207
 
326 tk 1208
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1209
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1210
 
134 tk 1211
  // track LEDs
484 tk 1212
  u8 selected_tracks = ui_selected_tracks >> (4*ui_selected_group);
492 tk 1213
  SEQ_LED_PinSet(seq_hwcfg_led.track[0], (selected_tracks & (1 << 0)));
1214
  SEQ_LED_PinSet(seq_hwcfg_led.track[1], (selected_tracks & (1 << 1)));
1215
  SEQ_LED_PinSet(seq_hwcfg_led.track[2], (selected_tracks & (1 << 2)));
1216
  SEQ_LED_PinSet(seq_hwcfg_led.track[3], (selected_tracks & (1 << 3)));
513 tk 1217
  SEQ_LED_PinSet(seq_hwcfg_led.track_sel, seq_ui_button_state.TRACK_SEL);
134 tk 1218
 
1219
  // parameter layer LEDs
492 tk 1220
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], (ui_selected_par_layer == 0));
1221
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], (ui_selected_par_layer == 1));
1222
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], (ui_selected_par_layer >= 2) || seq_ui_button_state.PAR_LAYER_SEL);
513 tk 1223
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer_sel, seq_ui_button_state.PAR_LAYER_SEL);
134 tk 1224
 
1225
  // group LEDs
492 tk 1226
  SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_group == 0));
1227
  SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_group == 1));
1228
  SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_group == 2));
1229
  SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_group == 3));
134 tk 1230
 
1231
  // trigger layer LEDs
492 tk 1232
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[0], (ui_selected_trg_layer == 0));
1233
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[1], (ui_selected_trg_layer == 1));
1234
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[2], (ui_selected_trg_layer >= 2) || seq_ui_button_state.TRG_LAYER_SEL);
513 tk 1235
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer_sel, seq_ui_button_state.TRG_LAYER_SEL);
134 tk 1236
 
1237
  // remaining LEDs
492 tk 1238
  SEQ_LED_PinSet(seq_hwcfg_led.edit, ui_page == SEQ_UI_PAGE_EDIT);
1239
  SEQ_LED_PinSet(seq_hwcfg_led.mute, ui_page == SEQ_UI_PAGE_MUTE);
1240
  SEQ_LED_PinSet(seq_hwcfg_led.pattern, ui_page == SEQ_UI_PAGE_PATTERN);
399 tk 1241
  if( SEQ_SONG_ActiveGet() )
492 tk 1242
    SEQ_LED_PinSet(seq_hwcfg_led.song, 1);
399 tk 1243
  else
492 tk 1244
    SEQ_LED_PinSet(seq_hwcfg_led.song, ui_cursor_flash ? 0 : (ui_page == SEQ_UI_PAGE_SONG));
134 tk 1245
 
492 tk 1246
  SEQ_LED_PinSet(seq_hwcfg_led.solo, seq_ui_button_state.SOLO);
1247
  SEQ_LED_PinSet(seq_hwcfg_led.fast, seq_ui_button_state.FAST_ENCODERS);
1248
  SEQ_LED_PinSet(seq_hwcfg_led.all, seq_ui_button_state.CHANGE_ALL_STEPS);
134 tk 1249
 
492 tk 1250
  SEQ_LED_PinSet(seq_hwcfg_led.play, SEQ_BPM_IsRunning());
1251
  SEQ_LED_PinSet(seq_hwcfg_led.stop, !SEQ_BPM_IsRunning() && !ui_seq_pause);
1252
  SEQ_LED_PinSet(seq_hwcfg_led.pause, ui_seq_pause);
240 tk 1253
 
492 tk 1254
  SEQ_LED_PinSet(seq_hwcfg_led.rew, seq_ui_button_state.REW);
1255
  SEQ_LED_PinSet(seq_hwcfg_led.fwd, seq_ui_button_state.FWD);
134 tk 1256
 
513 tk 1257
  SEQ_LED_PinSet(seq_hwcfg_led.step_view, seq_ui_button_state.STEP_VIEW);
134 tk 1258
 
492 tk 1259
  SEQ_LED_PinSet(seq_hwcfg_led.menu, seq_ui_button_state.MENU_PRESSED);
1260
  SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_ui_button_state.SCRUB);
524 tk 1261
  SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.METRONOME);
134 tk 1262
 
492 tk 1263
  SEQ_LED_PinSet(seq_hwcfg_led.utility, ui_page == SEQ_UI_PAGE_UTIL);
1264
  SEQ_LED_PinSet(seq_hwcfg_led.copy, seq_ui_button_state.COPY);
1265
  SEQ_LED_PinSet(seq_hwcfg_led.paste, seq_ui_button_state.PASTE);
1266
  SEQ_LED_PinSet(seq_hwcfg_led.clear, seq_ui_button_state.CLEAR);
240 tk 1267
 
513 tk 1268
  SEQ_LED_PinSet(seq_hwcfg_led.tap_tempo, seq_ui_button_state.TAP_TEMPO);
1269
  SEQ_LED_PinSet(seq_hwcfg_led.tempo_preset, seq_ui_button_state.TEMPO_PRESET);
524 tk 1270
  SEQ_LED_PinSet(seq_hwcfg_led.ext_restart, seq_core_state.EXT_RESTART_REQ);
240 tk 1271
 
492 tk 1272
  SEQ_LED_PinSet(seq_hwcfg_led.down, seq_ui_button_state.DOWN);
1273
  SEQ_LED_PinSet(seq_hwcfg_led.up, seq_ui_button_state.UP);
240 tk 1274
 
167 tk 1275
 
306 tk 1276
  // in MENU page: overrule GP LEDs so long MENU button is pressed/active
1277
  if( seq_ui_button_state.MENU_PRESSED ) {
1278
    if( ui_cursor_flash ) // if flashing flag active: no LED flag set
1279
      ui_gp_leds = 0x0000;
1280
    else {
1281
      int i;
1282
      u16 new_ui_gp_leds = 0x0000;
1283
      for(i=0; i<16; ++i)
1284
    if( ui_page == ui_shortcut_menu_pages[i] )
1285
      new_ui_gp_leds |= (1 << i);
1286
      ui_gp_leds = new_ui_gp_leds;
1287
    }
1288
  } else {
1289
    // note: the background function is permanently interrupted - therefore we write the GP pattern
1290
    // into a temporary variable, and take it over once completed
1291
    u16 new_ui_gp_leds = 0x0000;
1292
    // request GP LED values from current menu page
1293
    // will be transfered to DOUT registers in SEQ_UI_LED_Handler_Periodic
1294
    new_ui_gp_leds = 0x0000;
206 tk 1295
 
306 tk 1296
    if( ui_led_callback != NULL )
1297
      ui_led_callback(&new_ui_gp_leds);
167 tk 1298
 
306 tk 1299
    ui_gp_leds = new_ui_gp_leds;
1300
  }
1301
 
524 tk 1302
 
1303
  // BLM LEDs
1304
  u8 visible_track0 = 4*ui_selected_group;
1305
  u8 visible_sr0  = 2*ui_selected_step_view;
1306
 
1307
  for(i=0; i<NUM_BLM_LED_SRS; ++i)
1308
    ui_blm_leds[i] = SEQ_TRG_Get8(visible_track0+(i>>1), visible_sr0+(i&1), ui_selected_trg_layer, ui_selected_instrument);
1309
 
134 tk 1310
  return 0; // no error
1311
}
1312
 
1313
 
1314
/////////////////////////////////////////////////////////////////////////////
1315
// updates high-prio LED functions (GP LEDs and Beat LED)
168 tk 1316
// called each mS
134 tk 1317
/////////////////////////////////////////////////////////////////////////////
1318
s32 SEQ_UI_LED_Handler_Periodic()
1319
{
496 tk 1320
  // ignore so long hardware config hasn't been read
1321
  if( !SEQ_FILE_HW_ConfigLocked() )
1322
    return -1;
1323
 
134 tk 1324
  // GP LEDs are only updated when ui_gp_leds or pos_marker_mask has changed
1325
  static u16 prev_ui_gp_leds = 0x0000;
1326
  static u16 prev_pos_marker_mask = 0x0000;
1327
 
1328
  // beat LED: tmp. for demo w/o real sequencer
193 tk 1329
  u8 sequencer_running = SEQ_BPM_IsRunning();
492 tk 1330
  SEQ_LED_PinSet(seq_hwcfg_led.beat, sequencer_running && ((seq_core_state.ref_step & 3) == 0));
134 tk 1331
 
1332
  // for song position marker (supports 16 LEDs, check for selected step view)
1333
  u16 pos_marker_mask = 0x0000;
325 tk 1334
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1335
  u8 played_step = seq_core_trk[visible_track].step;
513 tk 1336
  if( seq_ui_button_state.STEP_VIEW ) {
1337
    // if STEP_VIEW button pressed: pos marker correlated to zoom ratio
325 tk 1338
    if( sequencer_running )
1339
      pos_marker_mask = 1 << (played_step / (SEQ_TRG_NumStepsGet(visible_track)/16));
1340
  } else {
1341
    if( sequencer_running && (played_step >> 4) == ui_selected_step_view )
1342
      pos_marker_mask = 1 << (played_step & 0xf);
1343
  }
134 tk 1344
 
1345
  // exit of pattern hasn't changed
173 tk 1346
  if( prev_ui_gp_leds == ui_gp_leds && prev_pos_marker_mask == pos_marker_mask )
134 tk 1347
    return 0;
173 tk 1348
  prev_ui_gp_leds = ui_gp_leds;
134 tk 1349
  prev_pos_marker_mask = pos_marker_mask;
1350
 
1351
  // transfer to GP LEDs
514 tk 1352
  if( seq_hwcfg_led.gp_dout_l_sr ) {
1353
    if( seq_hwcfg_led.gp_dout_l2_sr )
1354
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_l_sr-1, (ui_gp_leds >> 0) & 0xff);
496 tk 1355
    else
514 tk 1356
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_l_sr-1, ((ui_gp_leds ^ pos_marker_mask) >> 0) & 0xff);
496 tk 1357
  }
134 tk 1358
 
514 tk 1359
  if( seq_hwcfg_led.gp_dout_r_sr ) {
1360
    if( seq_hwcfg_led.gp_dout_r2_sr )
1361
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_r_sr-1, (ui_gp_leds >> 8) & 0xff);
496 tk 1362
    else
514 tk 1363
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_r_sr-1, ((ui_gp_leds ^ pos_marker_mask) >> 8) & 0xff);
496 tk 1364
  }
134 tk 1365
 
514 tk 1366
  if( seq_hwcfg_led.gp_dout_l2_sr )
1367
    SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_l2_sr-1, (pos_marker_mask >> 0) & 0xff);
1368
  if( seq_hwcfg_led.gp_dout_r2_sr )
1369
    SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_r2_sr-1, (pos_marker_mask >> 8) & 0xff);
496 tk 1370
 
524 tk 1371
 
1372
  if( seq_hwcfg_blm.enabled ) {
1373
    // Red LEDs (position marker)
1374
    int track_ix;
1375
    for(track_ix=0; track_ix<(NUM_BLM_LED_SRS/2); ++track_ix) {
1376
      u16 pos_marker_mask = 0x0000;
1377
      if( sequencer_running ) {
1378
    u8 track = ui_selected_group + track_ix;
1379
    u8 played_step = seq_core_trk[track].step;
1380
    if( (played_step >> 4) == ui_selected_step_view )
1381
      pos_marker_mask = 1 << (played_step & 0xf);
1382
      }
1383
 
1384
      // Prepare Green LEDs (triggers)
1385
      u8 green_l = ui_blm_leds[2*track_ix+0];
1386
      u8 green_r = ui_blm_leds[2*track_ix+1];
1387
 
1388
      // Red LEDs (position marker)
1389
      if( seq_hwcfg_blm.dout_duocolour ) {
1390
    BLM_DOUT_SRSet(1, 2*track_ix+0, pos_marker_mask & 0xff);
1391
    BLM_DOUT_SRSet(1, 2*track_ix+1, (pos_marker_mask >> 8) & 0xff);
1392
 
1393
    if( seq_hwcfg_blm.dout_duocolour == 2 ) {
1394
      // Colour Mode 2: clear green LED, so that only one LED is lit
1395
      if( pos_marker_mask & 0x00ff )
1396
        green_l &= ~pos_marker_mask;
1397
      else if( pos_marker_mask & 0xff00 )
1398
        green_r &= ~(pos_marker_mask >> 8);
1399
    }
1400
      } else {
1401
    // If Duo-LEDs not enabled: invert Green LEDs
1402
    if( pos_marker_mask & 0x00ff )
1403
      green_l ^= pos_marker_mask;
1404
    else if( pos_marker_mask & 0xff00 )
1405
      green_r ^= (pos_marker_mask >> 8);
1406
      }
1407
 
1408
      // Set Green LEDs
1409
      BLM_DOUT_SRSet(0, 2*track_ix+0, green_l);
1410
      BLM_DOUT_SRSet(0, 2*track_ix+1, green_r);
1411
    }
1412
  }
1413
 
1414
 
514 tk 1415
  if( seq_hwcfg_blm8x8.enabled && seq_hwcfg_blm8x8.dout_gp_mapping ) {
513 tk 1416
    // for wilba's frontpanel
134 tk 1417
 
513 tk 1418
    // BLM_X DOUT -> GP LED mapping
1419
    // 0 = 15,16    1 = 13,14   2 = 11,12   3 = 9,10
1420
    // 4 = 1,2  5 = 3,4     6 = 5,6     7 = 7,8
134 tk 1421
 
513 tk 1422
    // bit 7: first green (i.e. GP1-G)
1423
    // bit 6: first red (i.e. GP1-R)
1424
    // bit 5: second green (i.e. GP2-G)
1425
    // bit 4: second red (i.e. GP2-R)
134 tk 1426
 
513 tk 1427
    // this mapping routine takes ca. 5 uS
1428
    // since it's only executed when ui_gp_leds or gp_mask has changed, it doesn't really hurt
134 tk 1429
 
513 tk 1430
    u16 modified_gp_leds = ui_gp_leds;
134 tk 1431
#if 1
513 tk 1432
    // extra: red LED is lit exclusively for higher contrast
1433
    modified_gp_leds &= ~pos_marker_mask;
134 tk 1434
#endif
1435
 
513 tk 1436
    int sr;
1437
    const u8 blm_x_sr_map[8] = {4, 5, 6, 7, 3, 2, 1, 0};
1438
    u16 gp_mask = 1 << 0;
1439
    for(sr=0; sr<8; ++sr) {
1440
      u8 pattern = 0;
134 tk 1441
 
513 tk 1442
      if( modified_gp_leds & gp_mask )
1443
    pattern |= 0x80;
1444
      if( pos_marker_mask & gp_mask )
1445
    pattern |= 0x40;
1446
      gp_mask <<= 1;
1447
      if( modified_gp_leds & gp_mask )
1448
    pattern |= 0x20;
1449
      if( pos_marker_mask & gp_mask )
1450
    pattern |= 0x10;
1451
      gp_mask <<= 1;
134 tk 1452
 
513 tk 1453
      u8 mapped_sr = blm_x_sr_map[sr];
1454
      BLM_X_LED_rows[mapped_sr][0] = (BLM_X_LED_rows[mapped_sr][0] & 0x0f) | pattern;
1455
    }
134 tk 1456
  }
1457
 
184 tk 1458
  return 0; // no error
134 tk 1459
}
1460
 
1461
 
1462
/////////////////////////////////////////////////////////////////////////////
168 tk 1463
// for menu handling (e.g. flashing cursor, doubleclick counter, etc...)
1464
// called each mS
1465
/////////////////////////////////////////////////////////////////////////////
1466
s32 SEQ_UI_MENU_Handler_Periodic()
1467
{
1468
  if( ++ui_cursor_flash_ctr >= SEQ_UI_CURSOR_FLASH_CTR_MAX ) {
1469
    ui_cursor_flash_ctr = 0;
1470
    seq_ui_display_update_req = 1;
173 tk 1471
  } else if( ui_cursor_flash_ctr == SEQ_UI_CURSOR_FLASH_CTR_LED_OFF ) {
168 tk 1472
    seq_ui_display_update_req = 1;
173 tk 1473
  }
1474
  // important: flash flag has to be recalculated on each invocation of this
1475
  // handler, since counter could also be reseted outside this function
1476
  ui_cursor_flash = ui_cursor_flash_ctr >= SEQ_UI_CURSOR_FLASH_CTR_LED_OFF;
168 tk 1477
 
184 tk 1478
 
240 tk 1479
  // used in some pages for temporary messages
416 tk 1480
  if( ui_hold_msg_ctr ) {
240 tk 1481
    --ui_hold_msg_ctr;
1482
 
416 tk 1483
    if( !ui_hold_msg_ctr )
1484
      seq_ui_display_update_req = 1;
1485
  }
1486
 
299 tk 1487
  // used for temporary SD Card messages
1488
  if( sdcard_msg_ctr )
1489
    --sdcard_msg_ctr;
1490
 
184 tk 1491
  // VU meters (used in MUTE menu, could also be available as LED matrix...)
1492
  static u8 vu_meter_prediv = 0; // predivider for VU meters
1493
 
1494
  if( ++vu_meter_prediv >= 4 ) {
1495
    vu_meter_prediv = 0;
1496
 
333 tk 1497
 
1498
    portENTER_CRITICAL();
1499
 
184 tk 1500
    u8 track;
1501
    seq_core_trk_t *t = &seq_core_trk[0];
1502
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++t, ++track)
1503
      if( t->vu_meter )
1504
    --t->vu_meter;
333 tk 1505
 
1506
    int i;
1507
    u8 *vu_meter = (u8 *)&seq_layer_vu_meter[0];
1508
    for(i=0; i<sizeof(seq_layer_vu_meter); ++i, ++vu_meter) {
1509
      if( *vu_meter && !(*vu_meter & 0x80) ) // if bit 7 set: static value
1510
    *vu_meter -= 1;
1511
    }
1512
 
318 tk 1513
    portEXIT_CRITICAL();
184 tk 1514
  }
1515
 
168 tk 1516
  return 0;
1517
}
1518
 
1519
 
1520
/////////////////////////////////////////////////////////////////////////////
328 tk 1521
// Should be regulary called to check if the layer/instrument/step selection
1522
// is valid for the current track
1523
// At least executed before button/encoder and LCD function calls
1524
/////////////////////////////////////////////////////////////////////////////
1525
s32 SEQ_UI_CheckSelections(void)
1526
{
492 tk 1527
  if( (ui_selected_tracks >> (4*ui_selected_group)) == 0 )
1528
    ui_selected_tracks = 1 << (4*ui_selected_group);
1529
 
328 tk 1530
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1531
 
1532
  if( ui_selected_instrument >= SEQ_PAR_NumInstrumentsGet(visible_track) )
1533
    ui_selected_instrument = 0;
1534
 
1535
  if( ui_selected_par_layer >= SEQ_PAR_NumLayersGet(visible_track) )
1536
    ui_selected_par_layer = 0;
1537
 
1538
  if( ui_selected_trg_layer >= SEQ_TRG_NumLayersGet(visible_track) )
1539
    ui_selected_trg_layer = 0;
1540
 
1541
  if( ui_selected_step >= SEQ_TRG_NumStepsGet(visible_track) )
1542
    ui_selected_step = 0;
1543
 
1544
  if( ui_selected_step_view >= (SEQ_TRG_NumStepsGet(visible_track)/16) ) {
1545
    ui_selected_step_view = 0;
1546
    ui_selected_step %= 16;
1547
  }
1548
 
336 tk 1549
  if( ui_selected_step < (16*ui_selected_step_view) ||
1550
      ui_selected_step >= (16*(ui_selected_step_view+1)) )
328 tk 1551
    ui_selected_step_view = ui_selected_step / 16;
1552
 
1553
  return 0; // no error
1554
}
1555
 
1556
 
1557
/////////////////////////////////////////////////////////////////////////////
134 tk 1558
// Returns the currently visible track
1559
/////////////////////////////////////////////////////////////////////////////
1560
u8 SEQ_UI_VisibleTrackGet(void)
1561
{
1562
  u8 offset = 0;
1563
 
484 tk 1564
  u8 selected_tracks = ui_selected_tracks >> (4*ui_selected_group);
1565
  if( selected_tracks & (1 << 3) )
134 tk 1566
    offset = 3;
484 tk 1567
  if( selected_tracks & (1 << 2) )
134 tk 1568
    offset = 2;
484 tk 1569
  if( selected_tracks & (1 << 1) )
134 tk 1570
    offset = 1;
484 tk 1571
  if( selected_tracks & (1 << 0) )
134 tk 1572
    offset = 0;
1573
 
1574
  return 4*ui_selected_group + offset;
1575
}
1576
 
168 tk 1577
 
1578
/////////////////////////////////////////////////////////////////////////////
178 tk 1579
// Returns 1 if 'track' is selected
1580
/////////////////////////////////////////////////////////////////////////////
1581
s32 SEQ_UI_IsSelectedTrack(u8 track)
1582
{
484 tk 1583
  return (ui_selected_tracks & (1 << track)) ? 1 : 0;
178 tk 1584
}
1585
 
1586
 
1587
/////////////////////////////////////////////////////////////////////////////
240 tk 1588
// Sets a new selected step and updates the step view
1589
/////////////////////////////////////////////////////////////////////////////
1590
s32 SEQ_UI_SelectedStepSet(u8 step)
1591
{
1592
  ui_selected_step = step;
328 tk 1593
  SEQ_UI_CheckSelections();
1594
 
240 tk 1595
  return 0; // no error
1596
}
1597
 
1598
 
1599
/////////////////////////////////////////////////////////////////////////////
168 tk 1600
// Increments the selected tracks/groups
1601
// OUT: 1 if value has been changed, otherwise 0
1602
/////////////////////////////////////////////////////////////////////////////
1603
s32 SEQ_UI_GxTyInc(s32 incrementer)
1604
{
1605
  int gxty = SEQ_UI_VisibleTrackGet();
1606
  int prev_gxty = gxty;
1607
 
1608
  if( incrementer >= 0 ) {
1609
    if( (gxty += incrementer) >= SEQ_CORE_NUM_TRACKS )
1610
      gxty = SEQ_CORE_NUM_TRACKS-1;
1611
  } else {
1612
    if( (gxty += incrementer) < 0 )
1613
      gxty = 0;
1614
  }
1615
 
1616
  if( gxty == prev_gxty )
1617
    return 0; // no change
1618
 
484 tk 1619
  ui_selected_tracks = 1 << gxty;
168 tk 1620
  ui_selected_group = gxty / 4;
1621
 
1622
  return 1; // value changed
1623
}
1624
 
1625
 
1626
/////////////////////////////////////////////////////////////////////////////
236 tk 1627
// Increments a 16bit variable within given min/max range
1628
// OUT: 1 if value has been changed, otherwise 0
1629
/////////////////////////////////////////////////////////////////////////////
240 tk 1630
s32 SEQ_UI_Var16_Inc(u16 *value, u16 min, u16 max, s32 incrementer)
236 tk 1631
{
1632
  int new_value = *value;
1633
  int prev_value = new_value;
1634
 
1635
  if( incrementer >= 0 ) {
1636
    if( (new_value += incrementer) >= max )
1637
      new_value = max;
1638
  } else {
1639
    if( (new_value += incrementer) < min )
1640
      new_value = min;
1641
  }
1642
 
1643
  if( new_value == prev_value )
1644
    return 0; // no change
1645
 
1646
  *value = new_value;
1647
 
1648
  return 1; // value changed
1649
}
1650
 
240 tk 1651
/////////////////////////////////////////////////////////////////////////////
1652
// Increments an 8bit variable within given min/max range
1653
// OUT: 1 if value has been changed, otherwise 0
1654
/////////////////////////////////////////////////////////////////////////////
1655
s32 SEQ_UI_Var8_Inc(u8 *value, u16 min, u16 max, s32 incrementer)
1656
{
1657
  u16 tmp = *value;
1658
  if( SEQ_UI_Var16_Inc(&tmp, min, max, incrementer) ) {
1659
    *value = tmp;
1660
    return 1; // value changed
1661
  }
236 tk 1662
 
240 tk 1663
  return 0; // value hasn't been changed
1664
}
1665
 
1666
 
236 tk 1667
/////////////////////////////////////////////////////////////////////////////
168 tk 1668
// Increments a CC within given min/max range
1669
// OUT: 1 if value has been changed, otherwise 0
1670
/////////////////////////////////////////////////////////////////////////////
248 tk 1671
s32 SEQ_UI_CC_Inc(u8 cc, u8 min, u8 max, s32 incrementer)
168 tk 1672
{
1673
  u8 visible_track = SEQ_UI_VisibleTrackGet();
173 tk 1674
  int new_value = SEQ_CC_Get(visible_track, cc);
1675
  int prev_value = new_value;
168 tk 1676
 
1677
  if( incrementer >= 0 ) {
173 tk 1678
    if( (new_value += incrementer) >= max )
1679
      new_value = max;
168 tk 1680
  } else {
173 tk 1681
    if( (new_value += incrementer) < min )
1682
      new_value = min;
168 tk 1683
  }
1684
 
173 tk 1685
  if( new_value == prev_value )
168 tk 1686
    return 0; // no change
1687
 
173 tk 1688
  SEQ_CC_Set(visible_track, cc, new_value);
168 tk 1689
 
179 tk 1690
  // set same value for all selected tracks
1691
  u8 track;
1692
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1693
    if( track != visible_track && SEQ_UI_IsSelectedTrack(track) )
1694
      SEQ_CC_Set(track, cc, new_value);
1695
 
168 tk 1696
  return 1; // value changed
1697
}
1698
 
173 tk 1699
 
1700
/////////////////////////////////////////////////////////////////////////////
179 tk 1701
// Sets a CC value on all selected tracks
1702
// OUT: 1 if value has been changed, otherwise 0
1703
/////////////////////////////////////////////////////////////////////////////
248 tk 1704
s32 SEQ_UI_CC_Set(u8 cc, u8 value)
179 tk 1705
{
1706
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1707
  int prev_value = SEQ_CC_Get(visible_track, cc);
1708
 
1709
  if( value == prev_value )
1710
    return 0; // no change
1711
 
1712
  SEQ_CC_Set(visible_track, cc, value);
1713
 
1714
  // set same value for all selected tracks
1715
  u8 track;
1716
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1717
    if( track != visible_track && SEQ_UI_IsSelectedTrack(track) )
1718
      SEQ_CC_Set(track, cc, value);
1719
 
1720
  return 1; // value changed
1721
}
1722
 
1723
/////////////////////////////////////////////////////////////////////////////
173 tk 1724
// Modifies a bitfield in a CC value to a given value
1725
// OUT: 1 if value has been changed, otherwise 0
1726
/////////////////////////////////////////////////////////////////////////////
248 tk 1727
s32 SEQ_UI_CC_SetFlags(u8 cc, u8 flag_mask, u8 value)
173 tk 1728
{
1729
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1730
  int new_value = SEQ_CC_Get(visible_track, cc);
1731
  int prev_value = new_value;
1732
 
1733
  new_value = (new_value & ~flag_mask) | value;
1734
 
1735
  if( new_value == prev_value )
1736
    return 0; // no change
1737
 
1738
  SEQ_CC_Set(visible_track, cc, new_value);
1739
 
179 tk 1740
  // do same modification for all selected tracks
1741
  u8 track;
1742
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1743
    if( track != visible_track && SEQ_UI_IsSelectedTrack(track) ) {
1744
      int new_value = SEQ_CC_Get(track, cc);
1745
      new_value = (new_value & ~flag_mask) | value;
1746
      SEQ_CC_Set(track, cc, new_value);
1747
    }
1748
 
173 tk 1749
  return 1; // value changed
1750
}
1751
 
1752
 
299 tk 1753
/////////////////////////////////////////////////////////////////////////////
1754
// Print temporary messages after file operations
1755
// expects mS delay and two lines, each up to 20 characters
1756
/////////////////////////////////////////////////////////////////////////////
1757
s32 SEQ_UI_SDCardMsg(u16 delay, char *line1, char *line2)
1758
{
1759
  sdcard_msg_ctr = delay;
1760
  strncpy((char *)sdcard_msg[0], line1, SDCARD_MSG_MAX_CHAR);
1761
  strncpy((char *)sdcard_msg[1], line2, SDCARD_MSG_MAX_CHAR);
1762
 
1763
  return 0; // no error
1764
}
1765
 
1766
/////////////////////////////////////////////////////////////////////////////
1767
// Prints a temporary error messages after file operation
1768
// Expects error status number (as defined in seq_file.h)
1769
/////////////////////////////////////////////////////////////////////////////
1770
s32 SEQ_UI_SDCardErrMsg(u16 delay, s32 status)
1771
{
1772
  // TODO: add more verbose error messages, they are clearly defined in seq_file.h)
1773
  char str[21];
1774
  sprintf(str, "E%3d (DOSFS: D%3d)", -status, seq_file_dfs_errno < 1000 ? seq_file_dfs_errno : 999);
1775
  return SEQ_UI_SDCardMsg(delay, "!! SD Card Error !!!", str);
1776
}