Subversion Repositories svn.mios32

Rev

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