Subversion Repositories svn.mios32

Rev

Rev 728 | Rev 740 | 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 729 2009-09-30 13:32:55Z 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>
690 tk 23
#include <blm.h>
464 tk 24
#include <blm_x.h>
190 tk 25
#include <seq_midi_out.h>
625 tk 26
#include <seq_midi_sysex.h>
190 tk 27
#include <seq_bpm.h>
134 tk 28
 
290 tk 29
#include "tasks.h"
134 tk 30
#include "seq_ui.h"
728 tk 31
#include "seq_lcd.h"
32
#include "seq_lcd_logo.h"
492 tk 33
#include "seq_hwcfg.h"
134 tk 34
#include "seq_lcd.h"
35
#include "seq_led.h"
186 tk 36
#include "seq_midply.h"
134 tk 37
#include "seq_core.h"
399 tk 38
#include "seq_song.h"
333 tk 39
#include "seq_par.h"
178 tk 40
#include "seq_layer.h"
184 tk 41
#include "seq_cc.h"
299 tk 42
#include "seq_file.h"
690 tk 43
#include "seq_file_hw.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;
600 tk 70
seq_ui_page_t ui_stepview_prev_page;
71
seq_ui_page_t ui_trglayer_prev_page;
72
seq_ui_page_t ui_parlayer_prev_page;
206 tk 73
 
173 tk 74
volatile u8 ui_cursor_flash;
75
u16 ui_cursor_flash_ctr;
134 tk 76
 
316 tk 77
u8 ui_edit_name_cursor;
78
u8 ui_edit_preset_num_category;
79
u8 ui_edit_preset_num_label;
729 tk 80
u8 ui_edit_preset_num_drum;
316 tk 81
 
193 tk 82
u8 ui_seq_pause;
83
 
625 tk 84
seq_ui_remote_mode_t seq_ui_remote_mode;
626 tk 85
seq_ui_remote_mode_t seq_ui_remote_active_mode;
625 tk 86
mios32_midi_port_t seq_ui_remote_port;
626 tk 87
mios32_midi_port_t seq_ui_remote_active_port;
625 tk 88
u8 seq_ui_remote_id;
626 tk 89
u16 seq_ui_remote_client_timeout_ctr;
90
u8 seq_ui_remote_force_lcd_update;
91
u8 seq_ui_remote_force_led_update;
193 tk 92
 
634 tk 93
u8 seq_ui_backup_req;
625 tk 94
 
634 tk 95
 
134 tk 96
/////////////////////////////////////////////////////////////////////////////
97
// Local variables
98
/////////////////////////////////////////////////////////////////////////////
99
 
168 tk 100
static s32 (*ui_button_callback)(seq_ui_button_t button, s32 depressed);
101
static s32 (*ui_encoder_callback)(seq_ui_encoder_t encoder, s32 incrementer);
173 tk 102
static s32 (*ui_led_callback)(u16 *gp_leds);
167 tk 103
static s32 (*ui_lcd_callback)(u8 high_prio);
352 tk 104
static s32 (*ui_exit_callback)(void);
167 tk 105
 
168 tk 106
static u16 ui_gp_leds;
167 tk 107
 
524 tk 108
#define NUM_BLM_LED_SRS (2*4)
109
static u8 ui_blm_leds[NUM_BLM_LED_SRS];
110
 
596 tk 111
#define UI_MSG_MAX_CHAR 21
112
static char ui_msg[2][UI_MSG_MAX_CHAR];
113
static u16 ui_msg_ctr;
114
static seq_ui_msg_type_t ui_msg_type;
299 tk 115
 
116
 
134 tk 117
/////////////////////////////////////////////////////////////////////////////
118
// Initialisation
119
/////////////////////////////////////////////////////////////////////////////
120
s32 SEQ_UI_Init(u32 mode)
121
{
626 tk 122
  int i;
123
  // clear all LEDs
124
  for(i=0; i<SEQ_LED_NUM_SR; ++i)
125
    SEQ_LED_SRSet(i, 0x00);
126
 
134 tk 127
  // init selection variables
128
  ui_selected_group = 0;
129
  ui_selected_tracks = (1 << 0);
130
  ui_selected_par_layer = 0;
131
  ui_selected_trg_layer = 0;
328 tk 132
  ui_selected_instrument = 0;
134 tk 133
  ui_selected_step_view = 0;
134
  ui_selected_step = 0;
168 tk 135
  ui_selected_item = 0;
134 tk 136
 
240 tk 137
  ui_hold_msg_ctr = 0;
596 tk 138
  ui_msg_ctr = 0;
240 tk 139
 
168 tk 140
  ui_cursor_flash_ctr = 0;
173 tk 141
  ui_cursor_flash = 0;
168 tk 142
 
167 tk 143
  seq_ui_button_state.ALL = 0;
144
 
193 tk 145
  ui_seq_pause = 0;
146
 
134 tk 147
  // visible GP pattern
148
  ui_gp_leds = 0x0000;
149
 
625 tk 150
  // default remote mode
151
  seq_ui_remote_mode = SEQ_UI_REMOTE_MODE_AUTO;
626 tk 152
  seq_ui_remote_active_mode = SEQ_UI_REMOTE_MODE_AUTO;
625 tk 153
  seq_ui_remote_port = DEFAULT;
626 tk 154
  seq_ui_remote_active_port = DEFAULT;
625 tk 155
  seq_ui_remote_id = 0x00;
626 tk 156
  seq_ui_remote_client_timeout_ctr = 0;
157
  seq_ui_remote_force_lcd_update = 0;
158
  seq_ui_remote_force_led_update = 0;
625 tk 159
 
634 tk 160
  // misc
161
  seq_ui_backup_req = 0;
162
 
167 tk 163
  // change to edit page
164
  ui_page = SEQ_UI_PAGE_NONE;
165
  SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
134 tk 166
 
596 tk 167
 
134 tk 168
  return 0; // no error
169
}
170
 
171
 
172
/////////////////////////////////////////////////////////////////////////////
178 tk 173
// Inits the speed mode of all encoders
174
// Auto mode should be used whenever:
175
//    - the edit screen is entered
176
//    - the group is changed
177
//    - a track is changed
178
//    - a layer is changed
179
/////////////////////////////////////////////////////////////////////////////
180
s32 SEQ_UI_InitEncSpeed(u32 auto_config)
181
{
182
  mios32_enc_config_t enc_config;
183
 
184
  if( auto_config ) {
513 tk 185
 
186
    if( !seq_hwcfg_enc.auto_fast )
187
      return 0; // auto mode not enabled - ignore auto reconfiguration request
188
 
333 tk 189
    switch( SEQ_PAR_AssignmentGet(SEQ_UI_VisibleTrackGet(), ui_selected_par_layer) ) {
190
      case SEQ_PAR_Type_Velocity:
191
      case SEQ_PAR_Type_Length:
192
      case SEQ_PAR_Type_CC:
193
      case SEQ_PAR_Type_PitchBend:
194
      case SEQ_PAR_Type_Probability:
195
      case SEQ_PAR_Type_Delay:
178 tk 196
    seq_ui_button_state.FAST_ENCODERS = 1;
197
    break;
198
 
199
      default:
200
    seq_ui_button_state.FAST_ENCODERS = 0;
201
    }
202
  }
203
 
204
  // change for datawheel and GP encoders
205
  int enc;
206
  for(enc=0; enc<17; ++enc) {
207
    enc_config = MIOS32_ENC_ConfigGet(enc);
208
    enc_config.cfg.speed = seq_ui_button_state.FAST_ENCODERS ? FAST : NORMAL;
513 tk 209
    enc_config.cfg.speed_par = (enc == 0) ? seq_hwcfg_enc.datawheel_fast_speed : seq_hwcfg_enc.gp_fast_speed;
178 tk 210
    MIOS32_ENC_ConfigSet(enc, enc_config);
211
  }
212
 
213
  return 0; // no error
214
}
215
 
216
 
217
/////////////////////////////////////////////////////////////////////////////
167 tk 218
// Various installation routines for menu page LCD handlers
219
/////////////////////////////////////////////////////////////////////////////
168 tk 220
s32 SEQ_UI_InstallButtonCallback(void *callback)
167 tk 221
{
168 tk 222
  ui_button_callback = callback;
167 tk 223
  return 0; // no error
224
}
225
 
168 tk 226
s32 SEQ_UI_InstallEncoderCallback(void *callback)
167 tk 227
{
168 tk 228
  ui_encoder_callback = callback;
167 tk 229
  return 0; // no error
230
}
231
 
168 tk 232
s32 SEQ_UI_InstallLEDCallback(void *callback)
167 tk 233
{
168 tk 234
  ui_led_callback = callback;
167 tk 235
  return 0; // no error
236
}
237
 
168 tk 238
s32 SEQ_UI_InstallLCDCallback(void *callback)
167 tk 239
{
240
  ui_lcd_callback = callback;
241
  return 0; // no error
242
}
243
 
352 tk 244
s32 SEQ_UI_InstallExitCallback(void *callback)
245
{
246
  ui_exit_callback = callback;
247
  return 0; // no error
248
}
167 tk 249
 
352 tk 250
 
167 tk 251
/////////////////////////////////////////////////////////////////////////////
252
// Change the menu page
253
/////////////////////////////////////////////////////////////////////////////
254
s32 SEQ_UI_PageSet(seq_ui_page_t page)
255
{
256
  if( page != ui_page ) {
352 tk 257
 
258
    // call page exit callback
259
    if( ui_exit_callback != NULL )
260
      ui_exit_callback();
261
 
167 tk 262
    // disable hooks of previous page and request re-initialisation
318 tk 263
    portENTER_CRITICAL();
167 tk 264
    ui_page = page;
168 tk 265
    ui_button_callback = NULL;
266
    ui_encoder_callback = NULL;
267
    ui_led_callback = NULL;
167 tk 268
    ui_lcd_callback = NULL;
352 tk 269
    ui_exit_callback = NULL;
318 tk 270
    portEXIT_CRITICAL();
167 tk 271
 
513 tk 272
    if( seq_hwcfg_button_beh.menu )
273
      seq_ui_button_state.MENU_PRESSED = 0; // MENU page selection finished
167 tk 274
 
275
    // request display initialisation
276
    seq_ui_display_init_req = 1;
277
  }
173 tk 278
 
306 tk 279
  // for MENU button:
280
  // first page has been selected - display new screen
281
  seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 1;
282
 
272 tk 283
  // for SEQ_UI_MENU which is accessible with EXIT button
284
  // remember the current selectable page
285
  if( ui_page >= SEQ_UI_FIRST_MENU_SELECTION_PAGE )
286
    ui_selected_page = ui_page;
287
 
184 tk 288
  return 0; // no error
167 tk 289
}
290
 
291
 
292
/////////////////////////////////////////////////////////////////////////////
272 tk 293
// Returns name of menu page (18 characters)
294
/////////////////////////////////////////////////////////////////////////////
295
char *SEQ_UI_PageNameGet(seq_ui_page_t page)
296
{
690 tk 297
  return (char *)ui_menu_pages[page].name;
272 tk 298
}
299
 
300
 
301
/////////////////////////////////////////////////////////////////////////////
134 tk 302
// Dedicated button functions
303
// Mapped to physical buttons in SEQ_UI_Button_Handler()
304
// Will also be mapped to MIDI keys later (for MIDI remote function)
305
/////////////////////////////////////////////////////////////////////////////
306
static s32 SEQ_UI_Button_GP(s32 depressed, u32 gp)
307
{
306 tk 308
  // in MENU page: overrule GP buttons so long MENU button is pressed/active
309
  if( seq_ui_button_state.MENU_PRESSED ) {
310
    if( depressed ) return -1;
311
    SEQ_UI_PageSet(ui_shortcut_menu_pages[gp]);
312
  } else {
313
    // forward to menu page
314
    if( ui_button_callback != NULL )
315
      ui_button_callback(gp, depressed);
316
    ui_cursor_flash_ctr = 0;
317
  }
134 tk 318
 
319
  return 0; // no error
320
}
321
 
322
static s32 SEQ_UI_Button_Left(s32 depressed)
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_Left, depressed);
173 tk 327
  ui_cursor_flash_ctr = 0;
134 tk 328
 
329
  return 0; // no error
330
}
331
 
332
static s32 SEQ_UI_Button_Right(s32 depressed)
333
{
168 tk 334
  // forward to menu page
306 tk 335
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 336
    ui_button_callback(SEQ_UI_BUTTON_Right, depressed);
173 tk 337
  ui_cursor_flash_ctr = 0;
134 tk 338
 
339
  return 0; // no error
340
}
341
 
168 tk 342
static s32 SEQ_UI_Button_Down(s32 depressed)
343
{
240 tk 344
  seq_ui_button_state.DOWN = depressed ? 0 : 1;
345
 
168 tk 346
  // forward to menu page
306 tk 347
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 348
    ui_button_callback(SEQ_UI_BUTTON_Down, depressed);
173 tk 349
  ui_cursor_flash_ctr = 0;
168 tk 350
 
351
  return 0; // no error
352
}
353
 
354
static s32 SEQ_UI_Button_Up(s32 depressed)
355
{
240 tk 356
  seq_ui_button_state.UP = depressed ? 0 : 1;
357
 
168 tk 358
  // forward to menu page
306 tk 359
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 360
    ui_button_callback(SEQ_UI_BUTTON_Up, depressed);
173 tk 361
  ui_cursor_flash_ctr = 0;
168 tk 362
 
363
  return 0; // no error
364
}
365
 
134 tk 366
static s32 SEQ_UI_Button_Stop(s32 depressed)
367
{
368
  if( depressed ) return -1; // ignore when button depressed
369
 
159 tk 370
  // if sequencer running: stop it
371
  // if sequencer already stopped: reset song position
186 tk 372
#if MID_PLAYER_TEST
193 tk 373
  if( SEQ_BPM_IsRunning() )
374
    SEQ_BPM_Stop();
186 tk 375
  else
376
    SEQ_MIDPLY_Reset();
377
#else
193 tk 378
  if( SEQ_BPM_IsRunning() )
379
    SEQ_BPM_Stop();
159 tk 380
  else
381
    SEQ_CORE_Reset();
186 tk 382
#endif
159 tk 383
 
134 tk 384
  return 0; // no error
385
}
386
 
387
static s32 SEQ_UI_Button_Pause(s32 depressed)
388
{
389
  if( depressed ) return -1; // ignore when button depressed
390
 
193 tk 391
  // if in auto mode and BPM generator is clocked in slave mode:
392
  // change to master mode
393
  SEQ_BPM_CheckAutoMaster();
159 tk 394
 
193 tk 395
  // toggle pause mode
396
  ui_seq_pause ^= 1;
397
 
398
  // execute stop/continue depending on new mode
399
  if( ui_seq_pause )
400
    SEQ_BPM_Stop();
401
  else
402
    SEQ_BPM_Cont();
403
 
134 tk 404
  return 0; // no error
405
}
406
 
407
static s32 SEQ_UI_Button_Play(s32 depressed)
408
{
409
  if( depressed ) return -1; // ignore when button depressed
410
 
186 tk 411
  // if in auto mode and BPM generator is clocked in slave mode:
412
  // change to master mode
413
  SEQ_BPM_CheckAutoMaster();
414
 
193 tk 415
#if 0
416
  // if sequencer running: restart it
417
  // if sequencer stopped: continue at last song position
418
  if( SEQ_BPM_IsRunning() )
419
    SEQ_BPM_Start();
420
  else
421
    SEQ_BPM_Cont();
186 tk 422
#else
193 tk 423
  // always restart sequencer
424
  SEQ_BPM_Start();
186 tk 425
#endif
159 tk 426
 
134 tk 427
  return 0; // no error
428
}
429
 
430
static s32 SEQ_UI_Button_Rew(s32 depressed)
431
{
240 tk 432
  seq_ui_button_state.REW = depressed ? 0 : 1;
433
 
134 tk 434
  if( depressed ) return -1; // ignore when button depressed
435
 
607 tk 436
  if( SEQ_SONG_ActiveGet() ) {
437
    portENTER_CRITICAL();
438
    SEQ_SONG_Rew();
439
    portEXIT_CRITICAL();
440
  } else
441
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "We are not", "in Song Mode!");
442
 
134 tk 443
  return 0; // no error
444
}
445
 
446
static s32 SEQ_UI_Button_Fwd(s32 depressed)
447
{
240 tk 448
  seq_ui_button_state.FWD = depressed ? 0 : 1;
449
 
134 tk 450
  if( depressed ) return -1; // ignore when button depressed
451
 
607 tk 452
  if( SEQ_SONG_ActiveGet() ) {
453
    portENTER_CRITICAL();
454
    SEQ_SONG_Fwd();
455
    portEXIT_CRITICAL();
456
  } else
457
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "We are not", "in Song Mode!");
458
 
134 tk 459
  return 0; // no error
460
}
461
 
596 tk 462
static s32 SEQ_UI_Button_Loop(s32 depressed)
463
{
464
  if( seq_hwcfg_button_beh.loop ) {
465
    // toggle mode
466
    if( depressed ) return -1; // ignore when button depressed
467
    // should be atomic
468
    portENTER_CRITICAL();
469
    seq_core_state.LOOP ^= 1;
470
  } else {
471
    // should be atomic
472
    portENTER_CRITICAL();
473
    // set mode
474
    seq_core_state.LOOP = depressed ? 0 : 1;
475
  }
476
  portEXIT_CRITICAL();
477
 
478
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Loop Mode", seq_core_state.LOOP ? "    on" : "   off");
479
 
480
  return 0; // no error
481
}
482
 
483
static s32 SEQ_UI_Button_Scrub(s32 depressed)
484
{
485
  // double function: -> Loop if menu button pressed
486
  if( seq_ui_button_state.MENU_PRESSED )
487
    return SEQ_UI_Button_Loop(depressed);
488
 
489
  if( seq_hwcfg_button_beh.scrub ) {
490
    // toggle mode
491
    if( depressed ) return -1; // ignore when button depressed
492
    seq_ui_button_state.SCRUB ^= 1;
493
  } else {
494
    // set mode
495
    seq_ui_button_state.SCRUB = depressed ? 0 : 1;
496
  }
497
 
498
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Scrub Mode", seq_ui_button_state.SCRUB ? "    on" : "   off");
499
 
500
  return 0; // no error
501
}
502
 
513 tk 503
static s32 SEQ_UI_Button_TempoPreset(s32 depressed)
134 tk 504
{
513 tk 505
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
240 tk 506
 
513 tk 507
  if( seq_hwcfg_button_beh.tempo_preset ) {
508
    if( depressed ) return -1; // ignore when button depressed
678 tk 509
    if( !seq_ui_button_state.TEMPO_PRESET ) // due to page change: button going to be set, clear other toggle buttons
510
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 511
    seq_ui_button_state.TEMPO_PRESET ^= 1; // toggle TEMPO_PRESET pressed (will also be released once GP button has been pressed)
512
  } else {
513
    // set mode
514
    seq_ui_button_state.TEMPO_PRESET = depressed ? 0 : 1;
515
  }
134 tk 516
 
513 tk 517
  if( seq_ui_button_state.TEMPO_PRESET ) {
518
    prev_page = ui_page;
519
    SEQ_UI_PageSet(SEQ_UI_PAGE_BPM_PRESETS);
520
  } else {
524 tk 521
    if( ui_page == SEQ_UI_PAGE_BPM_PRESETS )
522
      SEQ_UI_PageSet(prev_page);
513 tk 523
  }
240 tk 524
 
134 tk 525
  return 0; // no error
526
}
527
 
513 tk 528
static s32 SEQ_UI_Button_TapTempo(s32 depressed)
134 tk 529
{
513 tk 530
  seq_ui_button_state.TAP_TEMPO = depressed ? 0 : 1;
240 tk 531
 
134 tk 532
  if( depressed ) return -1; // ignore when button depressed
533
 
534
  return 0; // no error
535
}
536
 
524 tk 537
static s32 SEQ_UI_Button_ExtRestart(s32 depressed)
134 tk 538
{
539
  if( depressed ) return -1; // ignore when button depressed
540
 
596 tk 541
  // should be atomic
524 tk 542
  portENTER_CRITICAL();
543
  seq_core_state.EXT_RESTART_REQ = 1;
544
  portEXIT_CRITICAL();
545
 
596 tk 546
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "External Restart", "requested");
547
 
134 tk 548
  return 0; // no error
549
}
550
 
596 tk 551
static s32 SEQ_UI_Button_Metronome(s32 depressed)
552
{
553
  // double function: -> ExtRestart if menu button pressed
554
  if( seq_ui_button_state.MENU_PRESSED )
555
    return SEQ_UI_Button_ExtRestart(depressed);
556
 
557
  if( seq_hwcfg_button_beh.metronome ) {
558
    // toggle mode
559
    if( depressed ) return -1; // ignore when button depressed
560
    // should be atomic
561
    portENTER_CRITICAL();
562
    seq_core_state.METRONOME ^= 1;
563
  } else {
564
    // should be atomic
565
    portENTER_CRITICAL();
566
    // set mode
567
    seq_core_state.METRONOME = depressed ? 0 : 1;
568
  }
569
  portEXIT_CRITICAL();
570
 
571
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Metronome", seq_core_state.METRONOME ? "    on" : "   off");
572
 
599 tk 573
#if 0
574
  // metronome button can be used to trigger pattern file fixes
575
  if( !depressed )
576
    SEQ_PATTERN_FixAll();
577
#endif
578
 
596 tk 579
  return 0; // no error
580
}
581
 
630 tk 582
static s32 SEQ_UI_Button_Record(s32 depressed)
583
{
584
  if( depressed ) return -1; // ignore when button depressed
585
 
586
  // change to utility page
587
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKREC);
588
 
589
  return 0; // no error
590
}
591
 
134 tk 592
static s32 SEQ_UI_Button_Utility(s32 depressed)
593
{
594
  if( depressed ) return -1; // ignore when button depressed
595
 
240 tk 596
  // change to utility page
597
  SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
598
 
134 tk 599
  return 0; // no error
600
}
601
 
602
static s32 SEQ_UI_Button_Copy(s32 depressed)
603
{
240 tk 604
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 605
 
240 tk 606
  seq_ui_button_state.COPY = depressed ? 0 : 1;
607
 
280 tk 608
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
609
    if( depressed ) return -1;
610
    SEQ_UI_MIXER_Copy();
729 tk 611
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Mixer Map", "copied");
280 tk 612
    return 1;
729 tk 613
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
614
    if( depressed ) return -1;
615
    SEQ_UI_SONG_Copy();
616
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Song Position", "copied");
617
    return 1;
280 tk 618
  } else {
619
    if( !depressed ) {
620
      prev_page = ui_page;
621
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
622
    }
240 tk 623
 
280 tk 624
    s32 status = SEQ_UI_UTIL_CopyButton(depressed);
240 tk 625
 
596 tk 626
    if( depressed ) {
627
      if( prev_page != SEQ_UI_PAGE_UTIL )
628
    SEQ_UI_PageSet(prev_page);
240 tk 629
 
596 tk 630
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "copied");
631
    }
632
 
280 tk 633
    return status;
634
  }
134 tk 635
}
636
 
637
static s32 SEQ_UI_Button_Paste(s32 depressed)
638
{
240 tk 639
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 640
 
240 tk 641
  seq_ui_button_state.PASTE = depressed ? 0 : 1;
642
 
280 tk 643
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
644
    if( depressed ) return -1;
645
    SEQ_UI_MIXER_Paste();
729 tk 646
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Mixer Map", "pasted");
280 tk 647
    return 1;
729 tk 648
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
649
    if( depressed ) return -1;
650
    SEQ_UI_SONG_Paste();
651
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Song Position", "pasted");
652
    return 1;
280 tk 653
  } else {
654
    if( !depressed ) {
655
      prev_page = ui_page;
656
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
657
    }
240 tk 658
 
280 tk 659
    s32 status = SEQ_UI_UTIL_PasteButton(depressed);
240 tk 660
 
596 tk 661
    if( depressed ) {
662
      if( prev_page != SEQ_UI_PAGE_UTIL )
663
    SEQ_UI_PageSet(prev_page);
240 tk 664
 
596 tk 665
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "pasted");
666
    }
667
 
280 tk 668
    return status;
669
  }
134 tk 670
}
671
 
672
static s32 SEQ_UI_Button_Clear(s32 depressed)
673
{
240 tk 674
  seq_ui_button_state.CLEAR = depressed ? 0 : 1;
280 tk 675
 
676
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
677
    if( depressed ) return -1;
678
    SEQ_UI_MIXER_Clear();
729 tk 679
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Mixer Map", "cleared");
680
    return 1;
681
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
682
    if( depressed ) return -1;
683
    SEQ_UI_SONG_Clear();
684
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Song Position", "cleared");
685
    return 1;
686
  } else {
687
    if( depressed ) return -1;
688
    SEQ_UI_UTIL_ClearButton(0); // button pressed
689
    SEQ_UI_UTIL_ClearButton(1); // button depressed
596 tk 690
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "cleared");
280 tk 691
    return 1;
692
  }
134 tk 693
}
694
 
695
static s32 SEQ_UI_Button_Menu(s32 depressed)
696
{
513 tk 697
  if( seq_hwcfg_button_beh.menu ) {
698
    // toggle mode
699
    if( depressed ) return -1; // ignore when button depressed
700
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
678 tk 701
    if( !seq_ui_button_state.MENU_PRESSED ) // due to page change: button going to be set, clear other toggle buttons
702
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 703
    seq_ui_button_state.MENU_PRESSED ^= 1; // toggle MENU pressed (will also be released once GP button has been pressed)
704
  } else {
705
    // set mode
706
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
707
    seq_ui_button_state.MENU_PRESSED = depressed ? 0 : 1;
708
  }
134 tk 709
 
710
  return 0; // no error
711
}
712
 
713
static s32 SEQ_UI_Button_Select(s32 depressed)
714
{
168 tk 715
  // forward to menu page
591 tk 716
  if( !seq_ui_button_state.MENU_PRESSED ) {
717
    seq_ui_button_state.SELECT_PRESSED = depressed ? 0 : 1;
718
    if( ui_button_callback != NULL )
719
      ui_button_callback(SEQ_UI_BUTTON_Select, depressed);
720
  }
173 tk 721
  ui_cursor_flash_ctr = 0;
134 tk 722
 
723
  return 0; // no error
724
}
725
 
726
static s32 SEQ_UI_Button_Exit(s32 depressed)
727
{
272 tk 728
  if( depressed ) return -1; // ignore when button depressed
729
 
730
  u8 prev_ui_page = ui_page;
731
 
591 tk 732
  seq_ui_button_state.EXIT_PRESSED = depressed ? 0 : 1;
733
 
168 tk 734
  // forward to menu page
306 tk 735
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL )
168 tk 736
    ui_button_callback(SEQ_UI_BUTTON_Exit, depressed);
173 tk 737
  ui_cursor_flash_ctr = 0;
134 tk 738
 
167 tk 739
  // release all button states
740
  seq_ui_button_state.ALL = 0;
741
 
272 tk 742
  // enter menu page if we were not there before
743
  if( prev_ui_page != SEQ_UI_PAGE_MENU )
744
    SEQ_UI_PageSet(SEQ_UI_PAGE_MENU);
745
 
134 tk 746
  return 0; // no error
747
}
748
 
749
static s32 SEQ_UI_Button_Edit(s32 depressed)
750
{
591 tk 751
  seq_ui_button_state.EXIT_PRESSED = depressed ? 0 : 1;
752
 
134 tk 753
  if( depressed ) return -1; // ignore when button depressed
754
 
167 tk 755
  // change to edit page
756
  SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
757
 
178 tk 758
  // set/clear encoder fast function if required
759
  SEQ_UI_InitEncSpeed(1); // auto config
760
 
134 tk 761
  return 0; // no error
762
}
763
 
764
static s32 SEQ_UI_Button_Mute(s32 depressed)
765
{
591 tk 766
  seq_ui_button_state.MUTE_PRESSED = depressed ? 0 : 1;
767
 
134 tk 768
  if( depressed ) return -1; // ignore when button depressed
769
 
184 tk 770
  SEQ_UI_PageSet(SEQ_UI_PAGE_MUTE);
771
 
134 tk 772
  return 0; // no error
773
}
774
 
775
static s32 SEQ_UI_Button_Pattern(s32 depressed)
776
{
591 tk 777
  seq_ui_button_state.PATTERN_PRESSED = depressed ? 0 : 1;
778
 
134 tk 779
  if( depressed ) return -1; // ignore when button depressed
780
 
184 tk 781
  SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN);
782
 
134 tk 783
  return 0; // no error
784
}
785
 
786
static s32 SEQ_UI_Button_Song(s32 depressed)
787
{
591 tk 788
  seq_ui_button_state.SONG_PRESSED = depressed ? 0 : 1;
789
 
134 tk 790
  if( depressed ) return -1; // ignore when button depressed
791
 
399 tk 792
  SEQ_UI_PageSet(SEQ_UI_PAGE_SONG);
793
 
134 tk 794
  return 0; // no error
795
}
796
 
797
static s32 SEQ_UI_Button_Solo(s32 depressed)
798
{
513 tk 799
  if( seq_hwcfg_button_beh.solo ) {
800
    // toggle mode
801
    if( depressed ) return -1; // ignore when button depressed
802
    seq_ui_button_state.SOLO ^= 1;
803
  } else {
804
    // set mode
805
    seq_ui_button_state.SOLO = depressed ? 0 : 1;
806
  }
134 tk 807
 
808
  return 0; // no error
809
}
810
 
811
static s32 SEQ_UI_Button_Fast(s32 depressed)
812
{
513 tk 813
  if( seq_hwcfg_button_beh.fast ) {
814
    // toggle mode
815
    if( depressed ) return -1; // ignore when button depressed
816
    seq_ui_button_state.FAST_ENCODERS ^= 1;
817
  } else {
818
    // set mode
819
    seq_ui_button_state.FAST_ENCODERS = depressed ? 0 : 1;
820
  }
134 tk 821
 
178 tk 822
  SEQ_UI_InitEncSpeed(0); // no auto config
823
 
134 tk 824
  return 0; // no error
825
}
826
 
827
static s32 SEQ_UI_Button_All(s32 depressed)
828
{
178 tk 829
  seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE = depressed ? 0 : 1;
134 tk 830
 
513 tk 831
  if( seq_hwcfg_button_beh.all ) {
832
    // toggle mode
833
    if( depressed ) return -1;
834
    seq_ui_button_state.CHANGE_ALL_STEPS ^= 1;
835
  } else {
836
    // set mode
837
    seq_ui_button_state.CHANGE_ALL_STEPS = depressed ? 0 : 1;
838
  }
178 tk 839
 
134 tk 840
  return 0; // no error
841
}
842
 
843
static s32 SEQ_UI_Button_StepView(s32 depressed)
844
{
600 tk 845
  //  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
846
  // also used by seq_ui_stepsel
847
 
513 tk 848
  if( seq_hwcfg_button_beh.step_view ) {
849
    if( depressed ) return -1; // ignore when button depressed
678 tk 850
    if( !seq_ui_button_state.STEP_VIEW ) // due to page change: button going to be set, clear other toggle buttons
851
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 852
    seq_ui_button_state.STEP_VIEW ^= 1; // toggle STEP_VIEW pressed (will also be released once GP button has been pressed)
853
  } else {
854
    // set mode
855
    seq_ui_button_state.STEP_VIEW = depressed ? 0 : 1;
856
  }
134 tk 857
 
513 tk 858
  if( seq_ui_button_state.STEP_VIEW ) {
600 tk 859
    ui_stepview_prev_page = ui_page;
303 tk 860
    SEQ_UI_PageSet(SEQ_UI_PAGE_STEPSEL);
861
  } else {
524 tk 862
    if( ui_page == SEQ_UI_PAGE_STEPSEL )
600 tk 863
      SEQ_UI_PageSet(ui_stepview_prev_page);
303 tk 864
  }
134 tk 865
 
866
  return 0; // no error
867
}
868
 
513 tk 869
static s32 SEQ_UI_Button_TrackSel(s32 depressed)
134 tk 870
{
513 tk 871
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 872
 
513 tk 873
  if( seq_hwcfg_button_beh.track_sel ) {
874
    if( depressed ) return -1; // ignore when button depressed
678 tk 875
    if( !seq_ui_button_state.TRACK_SEL ) // due to page change: button going to be set, clear other toggle buttons
876
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 877
    seq_ui_button_state.TRACK_SEL ^= 1; // toggle TRACKSEL status (will also be released once GP button has been pressed)
878
  } else {
879
    seq_ui_button_state.TRACK_SEL = depressed ? 0 : 1;
880
  }
881
 
882
  if( seq_ui_button_state.TRACK_SEL ) {
883
    prev_page = ui_page;
884
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRACKSEL);
885
  } else {
524 tk 886
    if( ui_page == SEQ_UI_PAGE_TRACKSEL )
887
      SEQ_UI_PageSet(prev_page);
513 tk 888
  }
889
 
134 tk 890
  return 0; // no error
891
}
892
 
484 tk 893
static s32 SEQ_UI_Button_Track(s32 depressed, u32 track_button)
134 tk 894
{
484 tk 895
  static u8 button_state = 0x0f; // all 4 buttons depressed
134 tk 896
 
484 tk 897
  if( track_button >= 4 ) return -2; // max. 4 track buttons
134 tk 898
 
484 tk 899
  if( depressed ) {
900
    button_state |= (1 << track_button);
901
    return 0; // no error
902
  }
134 tk 903
 
484 tk 904
  button_state &= ~(1 << track_button);
905
 
906
  if( button_state == (~(1 << track_button) & 0xf) ) {
907
    // if only one select button pressed: radio-button function (1 of 4)
908
    ui_selected_tracks = 1 << (track_button + 4*ui_selected_group);
909
  } else {
910
    // if more than one select button pressed: toggle function (4 of 4)
911
    ui_selected_tracks ^= 1 << (track_button + 4*ui_selected_group);
912
  }
913
 
178 tk 914
  // set/clear encoder fast function if required
915
  SEQ_UI_InitEncSpeed(1); // auto config
916
 
134 tk 917
  return 0; // no error
918
}
919
 
920
static s32 SEQ_UI_Button_Group(s32 depressed, u32 group)
921
{
922
  if( depressed ) return -1; // ignore when button depressed
923
 
924
  if( group >= 4 ) return -2; // max. 4 group buttons
925
 
484 tk 926
  // if group has changed:
927
  if( group != ui_selected_group ) {
928
    // get current track selection
929
    u16 old_tracks = ui_selected_tracks >> (4*ui_selected_group);
134 tk 930
 
484 tk 931
    // select new group
932
    ui_selected_group = group;
933
 
934
    // take over old track selection
935
    ui_selected_tracks = old_tracks << (4*ui_selected_group);
936
  }
937
 
178 tk 938
  // set/clear encoder fast function if required
939
  SEQ_UI_InitEncSpeed(1); // auto config
940
 
134 tk 941
  return 0; // no error
942
}
943
 
513 tk 944
static s32 SEQ_UI_Button_ParLayerSel(s32 depressed)
945
{
600 tk 946
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
947
  // also used by seq_ui_parsel.c
513 tk 948
 
949
  if( seq_hwcfg_button_beh.par_layer ) {
950
    if( depressed ) return -1; // ignore when button depressed
678 tk 951
    if( !seq_ui_button_state.PAR_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
952
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 953
    seq_ui_button_state.PAR_LAYER_SEL ^= 1; // toggle PARSEL status (will also be released once GP button has been pressed)
954
  } else {
955
    seq_ui_button_state.PAR_LAYER_SEL = depressed ? 0 : 1;
956
  }
957
 
958
  if( seq_ui_button_state.PAR_LAYER_SEL ) {
600 tk 959
    ui_parlayer_prev_page = ui_page;
513 tk 960
    SEQ_UI_PageSet(SEQ_UI_PAGE_PARSEL);
961
  } else {
524 tk 962
    if( ui_page == SEQ_UI_PAGE_PARSEL )
600 tk 963
      SEQ_UI_PageSet(ui_parlayer_prev_page);
513 tk 964
  }
965
 
966
  // set/clear encoder fast function if required
967
  SEQ_UI_InitEncSpeed(1); // auto config
968
 
969
  return 0; // no error
970
}
971
 
134 tk 972
static s32 SEQ_UI_Button_ParLayer(s32 depressed, u32 par_layer)
973
{
974
  if( par_layer >= 3 ) return -2; // max. 3 parlayer buttons
975
 
333 tk 976
  u8 visible_track = SEQ_UI_VisibleTrackGet();
977
  u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
134 tk 978
 
333 tk 979
  if( num_p_layers <= 3 ) {
980
    // 3 layers: direct selection with LayerA/B/C button
981
    if( depressed ) return -1; // ignore when button depressed
596 tk 982
    if( par_layer >= num_p_layers ) {
983
      char str1[21];
984
      sprintf(str1, "Parameter Layer %c", 'A'+par_layer);
985
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
986
    } else {
987
      seq_ui_button_state.PAR_LAYER_SEL = 0;
988
      ui_selected_par_layer = par_layer;
989
    }
333 tk 990
  } else if( num_p_layers <= 4 ) {
991
    // 4 layers: LayerC Button toggles between C and D
992
    if( depressed ) return -1; // ignore when button depressed
993
    seq_ui_button_state.PAR_LAYER_SEL = 0;
336 tk 994
    if( par_layer == 2 )
995
      ui_selected_par_layer = (ui_selected_par_layer == 2) ? 3 : 2;
333 tk 996
    else
997
      ui_selected_par_layer = par_layer;
998
  } else {
999
    // >4 layers: LayerA/B button selects directly, Layer C button enters layer selection page
1000
    if( par_layer <= 1 ) {
1001
      if( depressed ) return -1; // ignore when button depressed
1002
      seq_ui_button_state.PAR_LAYER_SEL = 0;
1003
      ui_selected_par_layer = par_layer;
1004
    } else {
513 tk 1005
      return SEQ_UI_Button_ParLayerSel(depressed);
333 tk 1006
    }
1007
  }
1008
 
178 tk 1009
  // set/clear encoder fast function if required
1010
  SEQ_UI_InitEncSpeed(1); // auto config
1011
 
134 tk 1012
  return 0; // no error
1013
}
1014
 
513 tk 1015
static s32 SEQ_UI_Button_TrgLayerSel(s32 depressed)
1016
{
600 tk 1017
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1018
  // also used by seq_ui_trgsel.c
513 tk 1019
 
1020
  if( seq_hwcfg_button_beh.trg_layer ) {
1021
    if( depressed ) return -1; // ignore when button depressed
678 tk 1022
    if( !seq_ui_button_state.TRG_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1023
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1024
    seq_ui_button_state.TRG_LAYER_SEL ^= 1; // toggle TRGSEL status (will also be released once GP button has been pressed)
1025
  } else {
1026
    seq_ui_button_state.TRG_LAYER_SEL = depressed ? 0 : 1;
1027
  }
1028
 
1029
  if( seq_ui_button_state.TRG_LAYER_SEL ) {
600 tk 1030
    ui_trglayer_prev_page = ui_page;
513 tk 1031
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRGSEL);
1032
  } else {
524 tk 1033
    if( ui_page == SEQ_UI_PAGE_TRGSEL )
600 tk 1034
      SEQ_UI_PageSet(ui_trglayer_prev_page);
513 tk 1035
  }
1036
 
1037
  return 0; // no error
1038
}
1039
 
134 tk 1040
static s32 SEQ_UI_Button_TrgLayer(s32 depressed, u32 trg_layer)
1041
{
1042
  if( trg_layer >= 3 ) return -2; // max. 3 trglayer buttons
1043
 
326 tk 1044
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1045
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1046
  u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
134 tk 1047
 
328 tk 1048
  if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 3 ) {
326 tk 1049
    // 3 layers: direct selection with LayerA/B/C button
1050
    if( depressed ) return -1; // ignore when button depressed
596 tk 1051
    if( trg_layer >= num_t_layers ) {
1052
      char str1[21];
1053
      sprintf(str1, "Trigger Layer %c", 'A'+trg_layer);
1054
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1055
    } else {
1056
      seq_ui_button_state.TRG_LAYER_SEL = 0;
1057
      ui_selected_trg_layer = trg_layer;
1058
    }
328 tk 1059
  } else if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 4 ) {
326 tk 1060
    // 4 layers: LayerC Button toggles between C and D
1061
    if( depressed ) return -1; // ignore when button depressed
1062
    seq_ui_button_state.TRG_LAYER_SEL = 0;
336 tk 1063
    if( trg_layer == 2 )
1064
      ui_selected_trg_layer = (ui_selected_trg_layer == 2) ? 3 : 2;
326 tk 1065
    else
1066
      ui_selected_trg_layer = trg_layer;
1067
  } else {
333 tk 1068
    // >4 layers or drum mode: LayerA/B button selects directly, Layer C button enters trigger selection page
326 tk 1069
    // also used for drum tracks
1070
    if( trg_layer <= 1 ) {
1071
      if( depressed ) return -1; // ignore when button depressed
328 tk 1072
      seq_ui_button_state.TRG_LAYER_SEL = 0;
1073
      ui_selected_trg_layer = trg_layer;
326 tk 1074
    } else {
513 tk 1075
      return SEQ_UI_Button_TrgLayerSel(depressed);
326 tk 1076
    }
1077
  }
1078
 
134 tk 1079
  return 0; // no error
1080
}
1081
 
1082
 
544 tk 1083
static s32 SEQ_UI_Button_Morph(s32 depressed)
1084
{
1085
  if( depressed ) return -1; // ignore when button depressed
134 tk 1086
 
544 tk 1087
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMORPH);
1088
 
1089
  return 0; // no error
1090
}
1091
 
1092
static s32 SEQ_UI_Button_Mixer(s32 depressed)
1093
{
1094
  if( depressed ) return -1; // ignore when button depressed
1095
 
1096
  SEQ_UI_PageSet(SEQ_UI_PAGE_MIXER);
1097
 
1098
  return 0; // no error
1099
}
1100
 
1101
static s32 SEQ_UI_Button_Transpose(s32 depressed)
1102
{
1103
  if( depressed ) return -1; // ignore when button depressed
1104
 
1105
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKTRAN);
1106
 
1107
  return 0; // no error
1108
}
1109
 
1110
 
1111
 
1112
 
134 tk 1113
/////////////////////////////////////////////////////////////////////////////
1114
// Button handler
1115
/////////////////////////////////////////////////////////////////////////////
1116
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
1117
{
492 tk 1118
  int i;
1119
 
625 tk 1120
  // send MIDI event in remote mode and exit
626 tk 1121
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 1122
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendButton(pin, pin_value);
1123
 
496 tk 1124
  // ignore so long hardware config hasn't been read
1125
  if( !SEQ_FILE_HW_ConfigLocked() )
1126
    return -1;
1127
 
634 tk 1128
  // ignore during a backup is created
1129
  if( seq_ui_backup_req )
1130
    return -1;
1131
 
328 tk 1132
  // ensure that selections are matching with track constraints
1133
  SEQ_UI_CheckSelections();
1134
 
492 tk 1135
  // request display update
1136
  seq_ui_display_update_req = 1;
134 tk 1137
 
596 tk 1138
  // stop current message if (new) button has been pressed
1139
  if( pin_value == 0 )
1140
    SEQ_UI_MsgStop();
134 tk 1141
 
596 tk 1142
 
492 tk 1143
  // MEMO: we could also use a jump table with references to the functions
1144
  // here, but this "spagetthi code" simplifies the configuration and
1145
  // the resulting ASM doesn't look that bad!
168 tk 1146
 
492 tk 1147
  for(i=0; i<SEQ_HWCFG_NUM_GP; ++i)
1148
    if( pin == seq_hwcfg_button.gp[i] )
1149
      return SEQ_UI_Button_GP(pin_value, i);
134 tk 1150
 
492 tk 1151
  for(i=0; i<SEQ_HWCFG_NUM_TRACK; ++i)
1152
    if( pin == seq_hwcfg_button.track[i] )
1153
      return SEQ_UI_Button_Track(pin_value, i);
513 tk 1154
  if( pin == seq_hwcfg_button.track_sel )
1155
    return SEQ_UI_Button_TrackSel(pin_value);
134 tk 1156
 
492 tk 1157
  for(i=0; i<SEQ_HWCFG_NUM_GROUP; ++i)
1158
    if( pin == seq_hwcfg_button.group[i] )
1159
      return SEQ_UI_Button_Group(pin_value, i);
134 tk 1160
 
492 tk 1161
  for(i=0; i<SEQ_HWCFG_NUM_PAR_LAYER; ++i)
1162
    if( pin == seq_hwcfg_button.par_layer[i] )
1163
      return SEQ_UI_Button_ParLayer(pin_value, i);
513 tk 1164
  if( pin == seq_hwcfg_button.par_layer_sel )
1165
    return SEQ_UI_Button_ParLayerSel(pin_value);
134 tk 1166
 
492 tk 1167
  for(i=0; i<SEQ_HWCFG_NUM_TRG_LAYER; ++i)
1168
    if( pin == seq_hwcfg_button.trg_layer[i] )
1169
      return SEQ_UI_Button_TrgLayer(pin_value, i);
513 tk 1170
  if( pin == seq_hwcfg_button.trg_layer_sel )
1171
    return SEQ_UI_Button_TrgLayerSel(pin_value);
134 tk 1172
 
492 tk 1173
  if( pin == seq_hwcfg_button.left )
1174
    return SEQ_UI_Button_Left(pin_value);
1175
  if( pin == seq_hwcfg_button.right )
1176
    return SEQ_UI_Button_Right(pin_value);
1177
  if( pin == seq_hwcfg_button.down )
1178
    return SEQ_UI_Button_Down(pin_value);
1179
  if( pin == seq_hwcfg_button.up )
1180
    return SEQ_UI_Button_Up(pin_value);
134 tk 1181
 
492 tk 1182
  if( pin == seq_hwcfg_button.scrub )
1183
    return SEQ_UI_Button_Scrub(pin_value);
1184
  if( pin == seq_hwcfg_button.metronome )
1185
    return SEQ_UI_Button_Metronome(pin_value);
134 tk 1186
 
630 tk 1187
  if( pin == seq_hwcfg_button.record )
1188
    return SEQ_UI_Button_Record(pin_value);
1189
 
492 tk 1190
  if( pin == seq_hwcfg_button.stop )
1191
    return SEQ_UI_Button_Stop(pin_value);
1192
  if( pin == seq_hwcfg_button.pause )
1193
    return SEQ_UI_Button_Pause(pin_value);
1194
  if( pin == seq_hwcfg_button.play )
1195
    return SEQ_UI_Button_Play(pin_value);
1196
  if( pin == seq_hwcfg_button.rew )
1197
    return SEQ_UI_Button_Rew(pin_value);
1198
  if( pin == seq_hwcfg_button.fwd )
1199
    return SEQ_UI_Button_Fwd(pin_value);
596 tk 1200
  if( pin == seq_hwcfg_button.loop )
1201
    return SEQ_UI_Button_Loop(pin_value);
134 tk 1202
 
492 tk 1203
  if( pin == seq_hwcfg_button.utility )
1204
    return SEQ_UI_Button_Utility(pin_value);
1205
  if( pin == seq_hwcfg_button.copy )
1206
    return SEQ_UI_Button_Copy(pin_value);
1207
  if( pin == seq_hwcfg_button.paste )
1208
    return SEQ_UI_Button_Paste(pin_value);
1209
  if( pin == seq_hwcfg_button.clear )
1210
    return SEQ_UI_Button_Clear(pin_value);
134 tk 1211
 
492 tk 1212
  if( pin == seq_hwcfg_button.menu )
1213
    return SEQ_UI_Button_Menu(pin_value);
1214
  if( pin == seq_hwcfg_button.select )
1215
    return SEQ_UI_Button_Select(pin_value);
1216
  if( pin == seq_hwcfg_button.exit )
1217
    return SEQ_UI_Button_Exit(pin_value);
134 tk 1218
 
513 tk 1219
  if( pin == seq_hwcfg_button.tap_tempo )
1220
    return SEQ_UI_Button_TapTempo(pin_value);
1221
  if( pin == seq_hwcfg_button.tempo_preset )
1222
    return SEQ_UI_Button_TempoPreset(pin_value);
524 tk 1223
  if( pin == seq_hwcfg_button.ext_restart )
1224
    return SEQ_UI_Button_ExtRestart(pin_value);
134 tk 1225
 
492 tk 1226
  if( pin == seq_hwcfg_button.edit )
1227
    return SEQ_UI_Button_Edit(pin_value);
1228
  if( pin == seq_hwcfg_button.mute )
1229
    return SEQ_UI_Button_Mute(pin_value);
1230
  if( pin == seq_hwcfg_button.pattern )
1231
    return SEQ_UI_Button_Pattern(pin_value);
1232
  if( pin == seq_hwcfg_button.song )
1233
    return SEQ_UI_Button_Song(pin_value);
134 tk 1234
 
492 tk 1235
  if( pin == seq_hwcfg_button.solo )
1236
    return SEQ_UI_Button_Solo(pin_value);
1237
  if( pin == seq_hwcfg_button.fast )
1238
    return SEQ_UI_Button_Fast(pin_value);
1239
  if( pin == seq_hwcfg_button.all )
1240
    return SEQ_UI_Button_All(pin_value);
134 tk 1241
 
492 tk 1242
  if( pin == seq_hwcfg_button.step_view )
1243
    return SEQ_UI_Button_StepView(pin_value);
1244
  if( pin == seq_hwcfg_button.tap_tempo )
1245
    return SEQ_UI_Button_TapTempo(pin_value);
134 tk 1246
 
544 tk 1247
  if( pin == seq_hwcfg_button.morph )
1248
    return SEQ_UI_Button_Morph(pin_value);
1249
  if( pin == seq_hwcfg_button.mixer )
1250
    return SEQ_UI_Button_Mixer(pin_value);
1251
  if( pin == seq_hwcfg_button.transpose )
1252
    return SEQ_UI_Button_Transpose(pin_value);
1253
 
625 tk 1254
  // always print debugging message
1255
#if 1
1256
  MIOS32_MIDI_SendDebugMessage("[SEQ_UI_Button_Handler] Button SR:%d, Pin:%d not mapped, it has been %s.\n",
1257
                   (pin >> 3) + 1,
1258
                   pin & 7,
1259
                   pin_value ? "depressed" : "pressed");
1260
#endif
1261
 
492 tk 1262
  return -1; // button not mapped
134 tk 1263
}
1264
 
1265
 
1266
/////////////////////////////////////////////////////////////////////////////
524 tk 1267
// BLM Button handler
1268
/////////////////////////////////////////////////////////////////////////////
1269
s32 SEQ_UI_BLM_Button_Handler(u32 row, u32 pin, u32 pin_value)
1270
{
625 tk 1271
  // send MIDI event in remote mode and exit
626 tk 1272
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 1273
    return SEQ_MIDI_SYSEX_REMOTE_Client_Send_BLM_Button(row, pin, pin_value);
1274
 
524 tk 1275
  // ignore so long hardware config hasn't been read
1276
  if( !SEQ_FILE_HW_ConfigLocked() )
1277
    return -1;
1278
 
634 tk 1279
  // ignore during a backup is created
1280
  if( seq_ui_backup_req )
1281
    return -1;
1282
 
524 tk 1283
  if( row >= SEQ_CORE_NUM_TRACKS_PER_GROUP )
1284
    return -1; // more than 4 tracks not supported (yet) - could be done in this function w/o much effort
1285
 
1286
  if( pin >= 16 )
1287
    return -1; // more than 16 step buttons not supported (yet) - could be done by selecting the step view
1288
 
1289
  // select track depending on row
1290
  ui_selected_tracks = 1 << (row + 4*ui_selected_group);
1291
 
1292
  // ensure that selections are matching with track constraints
1293
  SEQ_UI_CheckSelections();
1294
 
1295
  // request display update
1296
  seq_ui_display_update_req = 1;
1297
 
1298
  // emulate general purpose button
1299
  return SEQ_UI_Button_GP(pin_value, pin);
1300
}
1301
 
1302
 
1303
/////////////////////////////////////////////////////////////////////////////
134 tk 1304
// Encoder handler
1305
/////////////////////////////////////////////////////////////////////////////
1306
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
1307
{
625 tk 1308
  // send MIDI event in remote mode and exit
626 tk 1309
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 1310
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendEncoder(encoder, incrementer);
1311
 
496 tk 1312
  // ignore so long hardware config hasn't been read
1313
  if( !SEQ_FILE_HW_ConfigLocked() )
1314
    return -1;
1315
 
634 tk 1316
  // ignore during a backup is created
1317
  if( seq_ui_backup_req )
1318
    return -1;
1319
 
134 tk 1320
  if( encoder > 16 )
1321
    return -1; // encoder doesn't exist
1322
 
328 tk 1323
  // ensure that selections are matching with track constraints
1324
  SEQ_UI_CheckSelections();
1325
 
596 tk 1326
  // stop current message
1327
  SEQ_UI_MsgStop();
1328
 
134 tk 1329
  // limit incrementer
1330
  if( incrementer > 3 )
1331
    incrementer = 3;
1332
  else if( incrementer < -3 )
1333
    incrementer = -3;
1334
 
607 tk 1335
  if( seq_ui_button_state.SCRUB && encoder == 0 ) {
1336
    // if sequencer isn't already running, continue it (don't restart)
1337
    if( !SEQ_BPM_IsRunning() )
1338
      SEQ_BPM_Cont();
1339
    ui_seq_pause = 0; // clear pause mode
1340
    // Scrub sequence back or forth
1341
    portENTER_CRITICAL(); // should be atomic
1342
    SEQ_CORE_Scrub(incrementer);
1343
    portEXIT_CRITICAL();
1344
  } else if( !seq_ui_button_state.MENU_PRESSED && ui_encoder_callback != NULL ) {
173 tk 1345
    ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
1346
    ui_cursor_flash_ctr = 0; // ensure that value is visible when it has been changed
134 tk 1347
  }
1348
 
1349
  // request display update
159 tk 1350
  seq_ui_display_update_req = 1;
134 tk 1351
 
1352
  return 0; // no error
1353
}
1354
 
1355
 
353 tk 1356
 
134 tk 1357
/////////////////////////////////////////////////////////////////////////////
626 tk 1358
// Receives a MIDI package from APP_NotifyReceivedEvent (-> app.c)
1359
/////////////////////////////////////////////////////////////////////////////
1360
s32 SEQ_UI_REMOTE_MIDI_Receive(mios32_midi_port_t port, mios32_midi_package_t midi_package)
1361
{
1362
#if 1
1363
  // check for active remote mode
1364
  if( seq_ui_remote_active_mode != SEQ_UI_REMOTE_MODE_SERVER )
1365
    return 0; // no error
1366
#endif
1367
 
1368
  if( (seq_ui_remote_port == DEFAULT && seq_ui_remote_active_port != port) ||
1369
      (seq_ui_remote_port != DEFAULT && port != seq_ui_remote_port) )
1370
    return 0; // wrong port
1371
 
1372
  // for easier parsing: convert Note Off -> Note On with velocity 0
1373
  if( midi_package.event == NoteOff ) {
1374
    midi_package.event = NoteOn;
1375
    midi_package.velocity = 0;
1376
  }
1377
 
1378
  switch( midi_package.event ) {
1379
    case NoteOn: {
1380
      switch( midi_package.chn ) {
1381
        case Chn1:
1382
      SEQ_UI_Button_Handler(midi_package.note + 0x00, midi_package.velocity ? 0 : 1);
1383
      break;
1384
        case Chn2:
1385
      SEQ_UI_Button_Handler(midi_package.note + 0x80, midi_package.velocity ? 0 : 1);
1386
      break;
1387
        case Chn3:
1388
      SEQ_UI_BLM_Button_Handler(midi_package.note >> 5, midi_package.note & 0x1f, midi_package.velocity ? 0 : 1);
1389
      break;
1390
      }
1391
    } break;
1392
 
1393
    case CC: {
1394
      if( midi_package.cc_number >= 15 && midi_package.cc_number <= 31 )
1395
    SEQ_UI_Encoder_Handler(midi_package.cc_number-15, (int)midi_package.value - 0x40);
1396
    } break;
1397
  }
1398
 
632 tk 1399
  return 1; // MIDI event has been taken for remote function -> don't forward to router/MIDI event parser
626 tk 1400
}
1401
 
1402
 
1403
/////////////////////////////////////////////////////////////////////////////
134 tk 1404
// Update LCD messages
1405
// Usually called from background task
1406
/////////////////////////////////////////////////////////////////////////////
1407
s32 SEQ_UI_LCD_Handler(void)
1408
{
728 tk 1409
  static u8 boot_animation_wait_ctr = 0;
1410
  static u8 boot_animation_lcd_pos = 0;
1411
 
625 tk 1412
  // special handling in remote client mode
626 tk 1413
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 1414
    return SEQ_UI_LCD_Update();
1415
 
159 tk 1416
  if( seq_ui_display_init_req ) {
1417
    seq_ui_display_init_req = 0; // clear request
134 tk 1418
 
278 tk 1419
    // clear force update of LCD
1420
    SEQ_LCD_Clear();
1421
    SEQ_LCD_Update(1);
134 tk 1422
 
168 tk 1423
    // select first menu item
1424
    ui_selected_item = 0;
1425
 
167 tk 1426
    // call init function of current page
272 tk 1427
    if( ui_menu_pages[ui_page].init_callback != NULL )
1428
      ui_menu_pages[ui_page].init_callback(0); // mode
134 tk 1429
 
1430
    // request display update
159 tk 1431
    seq_ui_display_update_req = 1;
134 tk 1432
  }
1433
 
496 tk 1434
  // print boot screen so long hardware config hasn't been read
1435
  if( !SEQ_FILE_HW_ConfigLocked() ) {
728 tk 1436
    if( boot_animation_lcd_pos < (40-3) ) {
1437
      if( ++boot_animation_wait_ctr >= 75 ) {
1438
    boot_animation_wait_ctr = 0;
637 tk 1439
 
728 tk 1440
    if( boot_animation_lcd_pos == 0 ) {
1441
      SEQ_LCD_Clear();
1442
      SEQ_LCD_CursorSet(0, 0);
1443
      SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE1 " " MIOS32_LCD_BOOT_MSG_LINE2);
1444
      SEQ_LCD_CursorSet(0, 1);
1445
      SEQ_LCD_PrintString("Searching for SD Card...");
1446
    }
1447
 
1448
    // logo is print on second LCD
1449
    SEQ_LCD_LOGO_Print(boot_animation_lcd_pos++);
1450
      }
1451
    }
634 tk 1452
  } else if( seq_ui_backup_req ) {
1453
    SEQ_LCD_Clear();
1454
    SEQ_LCD_CursorSet(0, 0);
1455
    //                   <-------------------------------------->
1456
    //                   0123456789012345678901234567890123456789
637 tk 1457
    SEQ_LCD_PrintString("Creating File Backup - be patient!!!");
1458
 
1459
    if( seq_file_backup_notification != NULL ) {
1460
      int i;
1461
 
1462
      SEQ_LCD_CursorSet(0, 1);
634 tk 1463
      SEQ_LCD_PrintFormattedString("Creating '%s'", seq_file_backup_notification);
637 tk 1464
 
1465
      SEQ_LCD_CursorSet(40+3, 0);
1466
      SEQ_LCD_PrintString("Total: [");
1467
      for(i=0; i<20; ++i)
1468
    SEQ_LCD_PrintChar((i>(seq_file_backup_percentage/5)) ? ' ' : '#');
1469
      SEQ_LCD_PrintFormattedString("] %3d%%", seq_file_backup_percentage);
1470
 
1471
      SEQ_LCD_CursorSet(40+3, 1);
1472
      SEQ_LCD_PrintString("File:  [");
1473
      for(i=0; i<20; ++i)
1474
    SEQ_LCD_PrintChar((i>(seq_file_copy_percentage/5)) ? ' ' : '#');
1475
      SEQ_LCD_PrintFormattedString("] %3d%%", seq_file_copy_percentage);
1476
    }
1477
 
496 tk 1478
  } else if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
1479
    SEQ_LCD_CursorSet(0, 0);
1480
    //                   <-------------------------------------->
1481
    //                   0123456789012345678901234567890123456789
306 tk 1482
    SEQ_LCD_PrintString("Menu Shortcuts:");
1483
    SEQ_LCD_PrintSpaces(25 + 40);
1484
    SEQ_LCD_CursorSet(0, 1);
1485
    SEQ_LCD_PrintString(UI_SHORTCUT_STR); // defined in seq_ui_pages.inc
1486
  } else {
1487
    // perform high priority LCD update request
1488
    if( ui_lcd_callback != NULL )
1489
      ui_lcd_callback(1); // high_prio
167 tk 1490
 
306 tk 1491
    // perform low priority LCD update request if requested
1492
    if( seq_ui_display_update_req ) {
1493
      seq_ui_display_update_req = 0; // clear request
328 tk 1494
 
1495
      // ensure that selections are matching with track constraints
1496
      SEQ_UI_CheckSelections();
1497
 
306 tk 1498
      if( ui_lcd_callback != NULL )
1499
    ui_lcd_callback(0); // no high_prio
1500
    }
134 tk 1501
  }
1502
 
353 tk 1503
  // transfer all changed characters to LCD
1504
  SEQ_UI_LCD_Update();
1505
 
1506
  return 0; // no error
1507
}
1508
 
1509
 
1510
/////////////////////////////////////////////////////////////////////////////
1511
// Called from SEQ_UI_LCD_Handler(), but optionally also from other tasks
1512
// to update the LCD screen immediately
1513
/////////////////////////////////////////////////////////////////////////////
1514
s32 SEQ_UI_LCD_Update(void)
1515
{
625 tk 1516
  // special handling in remote client mode
626 tk 1517
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT ) {
1518
    MIOS32_IRQ_Disable();
1519
    u8 force = seq_ui_remote_force_lcd_update;
1520
    seq_ui_remote_force_lcd_update = 0;
1521
    MIOS32_IRQ_Enable();
1522
    return SEQ_LCD_Update(force);
625 tk 1523
  }
1524
 
596 tk 1525
  // if UI message active: copy over the text
1526
  if( ui_msg_ctr ) {
1527
    const char *animation_l_ptr;
1528
    const char *animation_r_ptr;
1529
    u8 msg_x = 0;
1530
    u8 right_aligned = 0;
299 tk 1531
 
596 tk 1532
    switch( ui_msg_type ) {
1533
      case SEQ_UI_MSG_SDCARD: {
1534
    //                             00112233
1535
    const char animation_l[2*4] = "   >>>> ";
1536
    //                             00112233
1537
    const char animation_r[2*4] = "  < << <";
1538
    animation_l_ptr = animation_l;
1539
    animation_r_ptr = animation_r;
1540
    msg_x = 0; // MEMO: print such important information at first LCD for the case the user hasn't connected the second LCD yet
1541
    right_aligned = 0;
1542
      } break;
1543
 
1544
      default: {
1545
    //                             00112233
1546
    const char animation_l[2*4] = "   **** ";
1547
    //                             00112233
1548
    const char animation_r[2*4] = "  * ** *";
1549
    animation_l_ptr = animation_l;
1550
    animation_r_ptr = animation_r;
1551
    msg_x = 39;
1552
    right_aligned = 1;
1553
      } break;
1554
 
1555
    }
1556
    int anum = (ui_msg_ctr % 1000) / 250;
1557
 
1558
    int len[2];
1559
    len[0] = strlen((char *)ui_msg[0]);
1560
    len[1] = strlen((char *)ui_msg[1]);
1561
    int len_max = len[0];
1562
    if( len[1] > len_max )
1563
      len_max = len[1];
1564
 
1565
    if( right_aligned )
1566
      msg_x -= (9 + len_max);
1567
 
299 tk 1568
    int line;
1569
    for(line=0; line<2; ++line) {
596 tk 1570
      SEQ_LCD_CursorSet(msg_x, line);
1571
 
1572
      // ensure that both lines are padded with same number of spaces
1573
      int end_pos = len[line];
1574
      while( end_pos < len_max )
1575
    ui_msg[line][end_pos++] = ' ';
1576
      ui_msg[line][end_pos] = 0;
1577
 
1578
      SEQ_LCD_PrintFormattedString(" %c%c| %s |%c%c ",
1579
                   *(animation_l_ptr + 2*anum + 0), *(animation_l_ptr + 2*anum + 1),
1580
                   (char *)ui_msg[line],
1581
                   *(animation_r_ptr + 2*anum + 0), *(animation_r_ptr + 2*anum + 1));
299 tk 1582
    }
1583
  }
1584
 
637 tk 1585
  // MSD USB notification at right corner if not in Disk page
1586
  // to warn user that USB MIDI is disabled and seq performance is bad now!
638 tk 1587
  if( (TASK_MSD_EnableGet() > 0) && ui_page != SEQ_UI_PAGE_DISK ) {
637 tk 1588
    SEQ_LCD_CursorSet(80-11, 0);
1589
    if( ui_cursor_flash ) SEQ_LCD_PrintSpaces(13); else SEQ_LCD_PrintString(" [MSD USB] ");
1590
    SEQ_LCD_CursorSet(80-11, 1);
1591
    char str[5];
1592
    TASK_MSD_FlagStrGet(str);
1593
    if( ui_cursor_flash ) SEQ_LCD_PrintSpaces(13); else SEQ_LCD_PrintFormattedString(" [ %s  ] ", str);
1594
  }
596 tk 1595
 
278 tk 1596
  // transfer all changed characters to LCD
353 tk 1597
  // SEQ_LCD_Update provides a MUTEX handling to allow updates from different tasks
1598
  return SEQ_LCD_Update(0);
134 tk 1599
}
1600
 
1601
 
1602
/////////////////////////////////////////////////////////////////////////////
1603
// Update all LEDs
1604
// Usually called from background task
1605
/////////////////////////////////////////////////////////////////////////////
1606
s32 SEQ_UI_LED_Handler(void)
1607
{
626 tk 1608
  static u8 remote_led_sr[SEQ_LED_NUM_SR];
1609
 
524 tk 1610
  int i;
1611
 
625 tk 1612
  // ignore in remote client mode
626 tk 1613
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 1614
    return 0; // no error
1615
 
496 tk 1616
  // ignore so long hardware config hasn't been read
1617
  if( !SEQ_FILE_HW_ConfigLocked() )
1618
    return -1;
1619
 
134 tk 1620
  // track LEDs
484 tk 1621
  u8 selected_tracks = ui_selected_tracks >> (4*ui_selected_group);
492 tk 1622
  SEQ_LED_PinSet(seq_hwcfg_led.track[0], (selected_tracks & (1 << 0)));
1623
  SEQ_LED_PinSet(seq_hwcfg_led.track[1], (selected_tracks & (1 << 1)));
1624
  SEQ_LED_PinSet(seq_hwcfg_led.track[2], (selected_tracks & (1 << 2)));
1625
  SEQ_LED_PinSet(seq_hwcfg_led.track[3], (selected_tracks & (1 << 3)));
678 tk 1626
  SEQ_LED_PinSet(seq_hwcfg_led.track_sel, ui_page == SEQ_UI_PAGE_TRACKSEL);
134 tk 1627
 
1628
  // parameter layer LEDs
492 tk 1629
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], (ui_selected_par_layer == 0));
1630
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], (ui_selected_par_layer == 1));
1631
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], (ui_selected_par_layer >= 2) || seq_ui_button_state.PAR_LAYER_SEL);
678 tk 1632
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer_sel, ui_page == SEQ_UI_PAGE_PARSEL);
134 tk 1633
 
1634
  // group LEDs
492 tk 1635
  SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_group == 0));
1636
  SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_group == 1));
1637
  SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_group == 2));
1638
  SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_group == 3));
134 tk 1639
 
1640
  // trigger layer LEDs
492 tk 1641
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[0], (ui_selected_trg_layer == 0));
1642
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[1], (ui_selected_trg_layer == 1));
1643
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[2], (ui_selected_trg_layer >= 2) || seq_ui_button_state.TRG_LAYER_SEL);
678 tk 1644
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer_sel, ui_page == SEQ_UI_PAGE_TRGSEL);
134 tk 1645
 
1646
  // remaining LEDs
492 tk 1647
  SEQ_LED_PinSet(seq_hwcfg_led.edit, ui_page == SEQ_UI_PAGE_EDIT);
1648
  SEQ_LED_PinSet(seq_hwcfg_led.mute, ui_page == SEQ_UI_PAGE_MUTE);
1649
  SEQ_LED_PinSet(seq_hwcfg_led.pattern, ui_page == SEQ_UI_PAGE_PATTERN);
399 tk 1650
  if( SEQ_SONG_ActiveGet() )
492 tk 1651
    SEQ_LED_PinSet(seq_hwcfg_led.song, 1);
399 tk 1652
  else
492 tk 1653
    SEQ_LED_PinSet(seq_hwcfg_led.song, ui_cursor_flash ? 0 : (ui_page == SEQ_UI_PAGE_SONG));
134 tk 1654
 
492 tk 1655
  SEQ_LED_PinSet(seq_hwcfg_led.solo, seq_ui_button_state.SOLO);
1656
  SEQ_LED_PinSet(seq_hwcfg_led.fast, seq_ui_button_state.FAST_ENCODERS);
1657
  SEQ_LED_PinSet(seq_hwcfg_led.all, seq_ui_button_state.CHANGE_ALL_STEPS);
134 tk 1658
 
492 tk 1659
  SEQ_LED_PinSet(seq_hwcfg_led.play, SEQ_BPM_IsRunning());
1660
  SEQ_LED_PinSet(seq_hwcfg_led.stop, !SEQ_BPM_IsRunning() && !ui_seq_pause);
1661
  SEQ_LED_PinSet(seq_hwcfg_led.pause, ui_seq_pause);
240 tk 1662
 
492 tk 1663
  SEQ_LED_PinSet(seq_hwcfg_led.rew, seq_ui_button_state.REW);
1664
  SEQ_LED_PinSet(seq_hwcfg_led.fwd, seq_ui_button_state.FWD);
596 tk 1665
 
1666
  SEQ_LED_PinSet(seq_hwcfg_led.loop, seq_core_state.LOOP);
134 tk 1667
 
678 tk 1668
  SEQ_LED_PinSet(seq_hwcfg_led.step_view, ui_page == SEQ_UI_PAGE_STEPSEL);
134 tk 1669
 
591 tk 1670
  SEQ_LED_PinSet(seq_hwcfg_led.exit, seq_ui_button_state.EXIT_PRESSED);
1671
  SEQ_LED_PinSet(seq_hwcfg_led.select, seq_ui_button_state.SELECT_PRESSED);
492 tk 1672
  SEQ_LED_PinSet(seq_hwcfg_led.menu, seq_ui_button_state.MENU_PRESSED);
134 tk 1673
 
596 tk 1674
  // handle double functions
1675
  if( seq_ui_button_state.MENU_PRESSED ) {
1676
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_core_state.LOOP);
1677
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.EXT_RESTART_REQ);
1678
  } else {
1679
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_ui_button_state.SCRUB);
1680
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.METRONOME);
1681
  }
1682
 
630 tk 1683
  SEQ_LED_PinSet(seq_hwcfg_led.record, ui_page == SEQ_UI_PAGE_TRKREC);
1684
 
492 tk 1685
  SEQ_LED_PinSet(seq_hwcfg_led.utility, ui_page == SEQ_UI_PAGE_UTIL);
1686
  SEQ_LED_PinSet(seq_hwcfg_led.copy, seq_ui_button_state.COPY);
1687
  SEQ_LED_PinSet(seq_hwcfg_led.paste, seq_ui_button_state.PASTE);
1688
  SEQ_LED_PinSet(seq_hwcfg_led.clear, seq_ui_button_state.CLEAR);
240 tk 1689
 
513 tk 1690
  SEQ_LED_PinSet(seq_hwcfg_led.tap_tempo, seq_ui_button_state.TAP_TEMPO);
678 tk 1691
  SEQ_LED_PinSet(seq_hwcfg_led.tempo_preset, ui_page == SEQ_UI_PAGE_BPM_PRESETS);
524 tk 1692
  SEQ_LED_PinSet(seq_hwcfg_led.ext_restart, seq_core_state.EXT_RESTART_REQ);
240 tk 1693
 
492 tk 1694
  SEQ_LED_PinSet(seq_hwcfg_led.down, seq_ui_button_state.DOWN);
1695
  SEQ_LED_PinSet(seq_hwcfg_led.up, seq_ui_button_state.UP);
240 tk 1696
 
167 tk 1697
 
306 tk 1698
  // in MENU page: overrule GP LEDs so long MENU button is pressed/active
1699
  if( seq_ui_button_state.MENU_PRESSED ) {
1700
    if( ui_cursor_flash ) // if flashing flag active: no LED flag set
1701
      ui_gp_leds = 0x0000;
1702
    else {
1703
      int i;
1704
      u16 new_ui_gp_leds = 0x0000;
1705
      for(i=0; i<16; ++i)
1706
    if( ui_page == ui_shortcut_menu_pages[i] )
1707
      new_ui_gp_leds |= (1 << i);
1708
      ui_gp_leds = new_ui_gp_leds;
1709
    }
1710
  } else {
1711
    // note: the background function is permanently interrupted - therefore we write the GP pattern
1712
    // into a temporary variable, and take it over once completed
1713
    u16 new_ui_gp_leds = 0x0000;
1714
    // request GP LED values from current menu page
1715
    // will be transfered to DOUT registers in SEQ_UI_LED_Handler_Periodic
1716
    new_ui_gp_leds = 0x0000;
206 tk 1717
 
306 tk 1718
    if( ui_led_callback != NULL )
1719
      ui_led_callback(&new_ui_gp_leds);
167 tk 1720
 
306 tk 1721
    ui_gp_leds = new_ui_gp_leds;
1722
  }
1723
 
524 tk 1724
 
1725
  // BLM LEDs
1726
  u8 visible_track0 = 4*ui_selected_group;
1727
  u8 visible_sr0  = 2*ui_selected_step_view;
1728
 
1729
  for(i=0; i<NUM_BLM_LED_SRS; ++i)
1730
    ui_blm_leds[i] = SEQ_TRG_Get8(visible_track0+(i>>1), visible_sr0+(i&1), ui_selected_trg_layer, ui_selected_instrument);
1731
 
626 tk 1732
 
1733
  // send LED changes in remote server mode
1734
  if( seq_ui_remote_mode == SEQ_UI_REMOTE_MODE_SERVER || seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_SERVER ) {
1735
    int first_sr = -1;
1736
    int last_sr = -1;
1737
    int sr;
1738
    for(sr=0; sr<SEQ_LED_NUM_SR; ++sr) {
1739
      u8 value = SEQ_LED_SRGet(sr);
1740
      if( value != remote_led_sr[sr] ) {
1741
    if( first_sr == -1 )
1742
      first_sr = sr;
1743
    last_sr = sr;
1744
    remote_led_sr[sr] = value;
1745
      }
1746
    }
1747
 
1748
    MIOS32_IRQ_Disable();
1749
    if( seq_ui_remote_force_led_update ) {
1750
      first_sr = 0;
1751
      last_sr = SEQ_LED_NUM_SR-1;
1752
    }
1753
    seq_ui_remote_force_led_update = 0;
1754
    MIOS32_IRQ_Enable();
1755
 
1756
    if( first_sr >= 0 )
1757
      SEQ_MIDI_SYSEX_REMOTE_Server_SendLED(first_sr, (u8 *)&remote_led_sr[first_sr], last_sr-first_sr+1);
1758
  }
1759
 
1760
 
134 tk 1761
  return 0; // no error
1762
}
1763
 
1764
 
1765
/////////////////////////////////////////////////////////////////////////////
1766
// updates high-prio LED functions (GP LEDs and Beat LED)
168 tk 1767
// called each mS
134 tk 1768
/////////////////////////////////////////////////////////////////////////////
1769
s32 SEQ_UI_LED_Handler_Periodic()
1770
{
625 tk 1771
  // ignore in remote client mode
626 tk 1772
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 1773
    return 0; // no error
1774
 
496 tk 1775
  // ignore so long hardware config hasn't been read
1776
  if( !SEQ_FILE_HW_ConfigLocked() )
1777
    return -1;
1778
 
134 tk 1779
  // GP LEDs are only updated when ui_gp_leds or pos_marker_mask has changed
1780
  static u16 prev_ui_gp_leds = 0x0000;
1781
  static u16 prev_pos_marker_mask = 0x0000;
1782
 
1783
  // beat LED: tmp. for demo w/o real sequencer
193 tk 1784
  u8 sequencer_running = SEQ_BPM_IsRunning();
492 tk 1785
  SEQ_LED_PinSet(seq_hwcfg_led.beat, sequencer_running && ((seq_core_state.ref_step & 3) == 0));
134 tk 1786
 
1787
  // for song position marker (supports 16 LEDs, check for selected step view)
1788
  u16 pos_marker_mask = 0x0000;
325 tk 1789
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1790
  u8 played_step = seq_core_trk[visible_track].step;
513 tk 1791
  if( seq_ui_button_state.STEP_VIEW ) {
1792
    // if STEP_VIEW button pressed: pos marker correlated to zoom ratio
325 tk 1793
    if( sequencer_running )
1794
      pos_marker_mask = 1 << (played_step / (SEQ_TRG_NumStepsGet(visible_track)/16));
1795
  } else {
1796
    if( sequencer_running && (played_step >> 4) == ui_selected_step_view )
1797
      pos_marker_mask = 1 << (played_step & 0xf);
1798
  }
134 tk 1799
 
1800
  // exit of pattern hasn't changed
173 tk 1801
  if( prev_ui_gp_leds == ui_gp_leds && prev_pos_marker_mask == pos_marker_mask )
134 tk 1802
    return 0;
173 tk 1803
  prev_ui_gp_leds = ui_gp_leds;
134 tk 1804
  prev_pos_marker_mask = pos_marker_mask;
1805
 
1806
  // transfer to GP LEDs
514 tk 1807
  if( seq_hwcfg_led.gp_dout_l_sr ) {
1808
    if( seq_hwcfg_led.gp_dout_l2_sr )
1809
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_l_sr-1, (ui_gp_leds >> 0) & 0xff);
496 tk 1810
    else
514 tk 1811
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_l_sr-1, ((ui_gp_leds ^ pos_marker_mask) >> 0) & 0xff);
496 tk 1812
  }
134 tk 1813
 
514 tk 1814
  if( seq_hwcfg_led.gp_dout_r_sr ) {
1815
    if( seq_hwcfg_led.gp_dout_r2_sr )
1816
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_r_sr-1, (ui_gp_leds >> 8) & 0xff);
496 tk 1817
    else
514 tk 1818
      SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_r_sr-1, ((ui_gp_leds ^ pos_marker_mask) >> 8) & 0xff);
496 tk 1819
  }
134 tk 1820
 
514 tk 1821
  if( seq_hwcfg_led.gp_dout_l2_sr )
1822
    SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_l2_sr-1, (pos_marker_mask >> 0) & 0xff);
1823
  if( seq_hwcfg_led.gp_dout_r2_sr )
1824
    SEQ_LED_SRSet(seq_hwcfg_led.gp_dout_r2_sr-1, (pos_marker_mask >> 8) & 0xff);
496 tk 1825
 
524 tk 1826
 
1827
  if( seq_hwcfg_blm.enabled ) {
1828
    // Red LEDs (position marker)
1829
    int track_ix;
1830
    for(track_ix=0; track_ix<(NUM_BLM_LED_SRS/2); ++track_ix) {
1831
      u16 pos_marker_mask = 0x0000;
1832
      if( sequencer_running ) {
1833
    u8 track = ui_selected_group + track_ix;
1834
    u8 played_step = seq_core_trk[track].step;
1835
    if( (played_step >> 4) == ui_selected_step_view )
1836
      pos_marker_mask = 1 << (played_step & 0xf);
1837
      }
1838
 
1839
      // Prepare Green LEDs (triggers)
1840
      u8 green_l = ui_blm_leds[2*track_ix+0];
1841
      u8 green_r = ui_blm_leds[2*track_ix+1];
1842
 
1843
      // Red LEDs (position marker)
1844
      if( seq_hwcfg_blm.dout_duocolour ) {
1845
    BLM_DOUT_SRSet(1, 2*track_ix+0, pos_marker_mask & 0xff);
1846
    BLM_DOUT_SRSet(1, 2*track_ix+1, (pos_marker_mask >> 8) & 0xff);
1847
 
1848
    if( seq_hwcfg_blm.dout_duocolour == 2 ) {
1849
      // Colour Mode 2: clear green LED, so that only one LED is lit
1850
      if( pos_marker_mask & 0x00ff )
1851
        green_l &= ~pos_marker_mask;
1852
      else if( pos_marker_mask & 0xff00 )
1853
        green_r &= ~(pos_marker_mask >> 8);
1854
    }
1855
      } else {
1856
    // If Duo-LEDs not enabled: invert Green LEDs
1857
    if( pos_marker_mask & 0x00ff )
1858
      green_l ^= pos_marker_mask;
1859
    else if( pos_marker_mask & 0xff00 )
1860
      green_r ^= (pos_marker_mask >> 8);
1861
      }
1862
 
1863
      // Set Green LEDs
1864
      BLM_DOUT_SRSet(0, 2*track_ix+0, green_l);
1865
      BLM_DOUT_SRSet(0, 2*track_ix+1, green_r);
1866
    }
1867
  }
1868
 
1869
 
514 tk 1870
  if( seq_hwcfg_blm8x8.enabled && seq_hwcfg_blm8x8.dout_gp_mapping ) {
513 tk 1871
    // for wilba's frontpanel
134 tk 1872
 
513 tk 1873
    // BLM_X DOUT -> GP LED mapping
1874
    // 0 = 15,16    1 = 13,14   2 = 11,12   3 = 9,10
1875
    // 4 = 1,2  5 = 3,4     6 = 5,6     7 = 7,8
134 tk 1876
 
513 tk 1877
    // bit 7: first green (i.e. GP1-G)
1878
    // bit 6: first red (i.e. GP1-R)
1879
    // bit 5: second green (i.e. GP2-G)
1880
    // bit 4: second red (i.e. GP2-R)
134 tk 1881
 
513 tk 1882
    // this mapping routine takes ca. 5 uS
1883
    // since it's only executed when ui_gp_leds or gp_mask has changed, it doesn't really hurt
134 tk 1884
 
513 tk 1885
    u16 modified_gp_leds = ui_gp_leds;
134 tk 1886
#if 1
513 tk 1887
    // extra: red LED is lit exclusively for higher contrast
1888
    modified_gp_leds &= ~pos_marker_mask;
134 tk 1889
#endif
1890
 
513 tk 1891
    int sr;
1892
    const u8 blm_x_sr_map[8] = {4, 5, 6, 7, 3, 2, 1, 0};
1893
    u16 gp_mask = 1 << 0;
1894
    for(sr=0; sr<8; ++sr) {
1895
      u8 pattern = 0;
134 tk 1896
 
513 tk 1897
      if( modified_gp_leds & gp_mask )
1898
    pattern |= 0x80;
1899
      if( pos_marker_mask & gp_mask )
1900
    pattern |= 0x40;
1901
      gp_mask <<= 1;
1902
      if( modified_gp_leds & gp_mask )
1903
    pattern |= 0x20;
1904
      if( pos_marker_mask & gp_mask )
1905
    pattern |= 0x10;
1906
      gp_mask <<= 1;
134 tk 1907
 
513 tk 1908
      u8 mapped_sr = blm_x_sr_map[sr];
1909
      BLM_X_LED_rows[mapped_sr][0] = (BLM_X_LED_rows[mapped_sr][0] & 0x0f) | pattern;
1910
    }
134 tk 1911
  }
1912
 
184 tk 1913
  return 0; // no error
134 tk 1914
}
1915
 
1916
 
1917
/////////////////////////////////////////////////////////////////////////////
168 tk 1918
// for menu handling (e.g. flashing cursor, doubleclick counter, etc...)
1919
// called each mS
1920
/////////////////////////////////////////////////////////////////////////////
1921
s32 SEQ_UI_MENU_Handler_Periodic()
1922
{
625 tk 1923
  // ignore in remote client mode
626 tk 1924
  if( seq_ui_remote_active_mode == SEQ_UI_REMOTE_MODE_CLIENT )
625 tk 1925
    return 0; // no error
1926
 
652 tk 1927
  if( ++ui_cursor_flash_ctr >= SEQ_UI_CURSOR_FLASH_CTR_MAX )
168 tk 1928
    ui_cursor_flash_ctr = 0;
173 tk 1929
  // important: flash flag has to be recalculated on each invocation of this
1930
  // handler, since counter could also be reseted outside this function
652 tk 1931
  u8 old_ui_cursor_flash = ui_cursor_flash;
173 tk 1932
  ui_cursor_flash = ui_cursor_flash_ctr >= SEQ_UI_CURSOR_FLASH_CTR_LED_OFF;
652 tk 1933
  if( old_ui_cursor_flash != ui_cursor_flash )
1934
    seq_ui_display_update_req = 1;
168 tk 1935
 
240 tk 1936
  // used in some pages for temporary messages
416 tk 1937
  if( ui_hold_msg_ctr ) {
240 tk 1938
    --ui_hold_msg_ctr;
1939
 
416 tk 1940
    if( !ui_hold_msg_ctr )
1941
      seq_ui_display_update_req = 1;
1942
  }
1943
 
596 tk 1944
  // used for temporary messages
1945
  if( ui_msg_ctr )
1946
    --ui_msg_ctr;
299 tk 1947
 
184 tk 1948
  // VU meters (used in MUTE menu, could also be available as LED matrix...)
1949
  static u8 vu_meter_prediv = 0; // predivider for VU meters
1950
 
1951
  if( ++vu_meter_prediv >= 4 ) {
1952
    vu_meter_prediv = 0;
1953
 
333 tk 1954
 
1955
    portENTER_CRITICAL();
1956
 
184 tk 1957
    u8 track;
1958
    seq_core_trk_t *t = &seq_core_trk[0];
1959
    for(track=0; track<SEQ_CORE_NUM_TRACKS; ++t, ++track)
1960
      if( t->vu_meter )
1961
    --t->vu_meter;
333 tk 1962
 
1963
    int i;
1964
    u8 *vu_meter = (u8 *)&seq_layer_vu_meter[0];
1965
    for(i=0; i<sizeof(seq_layer_vu_meter); ++i, ++vu_meter) {
1966
      if( *vu_meter && !(*vu_meter & 0x80) ) // if bit 7 set: static value
1967
    *vu_meter -= 1;
1968
    }
1969
 
318 tk 1970
    portEXIT_CRITICAL();
184 tk 1971
  }
1972
 
168 tk 1973
  return 0;
1974
}
1975
 
1976
 
1977
/////////////////////////////////////////////////////////////////////////////
328 tk 1978
// Should be regulary called to check if the layer/instrument/step selection
1979
// is valid for the current track
1980
// At least executed before button/encoder and LCD function calls
1981
/////////////////////////////////////////////////////////////////////////////
1982
s32 SEQ_UI_CheckSelections(void)
1983
{
492 tk 1984
  if( (ui_selected_tracks >> (4*ui_selected_group)) == 0 )
1985
    ui_selected_tracks = 1 << (4*ui_selected_group);
1986
 
328 tk 1987
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1988
 
1989
  if( ui_selected_instrument >= SEQ_PAR_NumInstrumentsGet(visible_track) )
1990
    ui_selected_instrument = 0;
1991
 
1992
  if( ui_selected_par_layer >= SEQ_PAR_NumLayersGet(visible_track) )
1993
    ui_selected_par_layer = 0;
1994
 
1995
  if( ui_selected_trg_layer >= SEQ_TRG_NumLayersGet(visible_track) )
1996
    ui_selected_trg_layer = 0;
1997
 
1998
  if( ui_selected_step >= SEQ_TRG_NumStepsGet(visible_track) )
1999
    ui_selected_step = 0;
2000
 
2001
  if( ui_selected_step_view >= (SEQ_TRG_NumStepsGet(visible_track)/16) ) {
2002
    ui_selected_step_view = 0;
2003
    ui_selected_step %= 16;
2004
  }
2005
 
336 tk 2006
  if( ui_selected_step < (16*ui_selected_step_view) ||
2007
      ui_selected_step >= (16*(ui_selected_step_view+1)) )
328 tk 2008
    ui_selected_step_view = ui_selected_step / 16;
2009
 
2010
  return 0; // no error
2011
}
2012
 
2013
 
2014
/////////////////////////////////////////////////////////////////////////////
134 tk 2015
// Returns the currently visible track
2016
/////////////////////////////////////////////////////////////////////////////
2017
u8 SEQ_UI_VisibleTrackGet(void)
2018
{
2019
  u8 offset = 0;
2020
 
484 tk 2021
  u8 selected_tracks = ui_selected_tracks >> (4*ui_selected_group);
2022
  if( selected_tracks & (1 << 3) )
134 tk 2023
    offset = 3;
484 tk 2024
  if( selected_tracks & (1 << 2) )
134 tk 2025
    offset = 2;
484 tk 2026
  if( selected_tracks & (1 << 1) )
134 tk 2027
    offset = 1;
484 tk 2028
  if( selected_tracks & (1 << 0) )
134 tk 2029
    offset = 0;
2030
 
2031
  return 4*ui_selected_group + offset;
2032
}
2033
 
168 tk 2034
 
2035
/////////////////////////////////////////////////////////////////////////////
178 tk 2036
// Returns 1 if 'track' is selected
2037
/////////////////////////////////////////////////////////////////////////////
2038
s32 SEQ_UI_IsSelectedTrack(u8 track)
2039
{
484 tk 2040
  return (ui_selected_tracks & (1 << track)) ? 1 : 0;
178 tk 2041
}
2042
 
2043
 
2044
/////////////////////////////////////////////////////////////////////////////
240 tk 2045
// Sets a new selected step and updates the step view
2046
/////////////////////////////////////////////////////////////////////////////
2047
s32 SEQ_UI_SelectedStepSet(u8 step)
2048
{
2049
  ui_selected_step = step;
328 tk 2050
  SEQ_UI_CheckSelections();
2051
 
240 tk 2052
  return 0; // no error
2053
}
2054
 
2055
 
2056
/////////////////////////////////////////////////////////////////////////////
168 tk 2057
// Increments the selected tracks/groups
2058
// OUT: 1 if value has been changed, otherwise 0
2059
/////////////////////////////////////////////////////////////////////////////
2060
s32 SEQ_UI_GxTyInc(s32 incrementer)
2061
{
2062
  int gxty = SEQ_UI_VisibleTrackGet();
2063
  int prev_gxty = gxty;
2064
 
2065
  if( incrementer >= 0 ) {
2066
    if( (gxty += incrementer) >= SEQ_CORE_NUM_TRACKS )
2067
      gxty = SEQ_CORE_NUM_TRACKS-1;
2068
  } else {
2069
    if( (gxty += incrementer) < 0 )
2070
      gxty = 0;
2071
  }
2072
 
2073
  if( gxty == prev_gxty )
2074
    return 0; // no change
2075
 
484 tk 2076
  ui_selected_tracks = 1 << gxty;
168 tk 2077
  ui_selected_group = gxty / 4;
2078
 
2079
  return 1; // value changed
2080
}
2081
 
2082
 
2083
/////////////////////////////////////////////////////////////////////////////
236 tk 2084
// Increments a 16bit variable within given min/max range
2085
// OUT: 1 if value has been changed, otherwise 0
2086
/////////////////////////////////////////////////////////////////////////////
240 tk 2087
s32 SEQ_UI_Var16_Inc(u16 *value, u16 min, u16 max, s32 incrementer)
236 tk 2088
{
2089
  int new_value = *value;
2090
  int prev_value = new_value;
2091
 
2092
  if( incrementer >= 0 ) {
2093
    if( (new_value += incrementer) >= max )
2094
      new_value = max;
2095
  } else {
2096
    if( (new_value += incrementer) < min )
2097
      new_value = min;
2098
  }
2099
 
2100
  if( new_value == prev_value )
2101
    return 0; // no change
2102
 
2103
  *value = new_value;
2104
 
2105
  return 1; // value changed
2106
}
2107
 
240 tk 2108
/////////////////////////////////////////////////////////////////////////////
2109
// Increments an 8bit variable within given min/max range
2110
// OUT: 1 if value has been changed, otherwise 0
2111
/////////////////////////////////////////////////////////////////////////////
2112
s32 SEQ_UI_Var8_Inc(u8 *value, u16 min, u16 max, s32 incrementer)
2113
{
2114
  u16 tmp = *value;
2115
  if( SEQ_UI_Var16_Inc(&tmp, min, max, incrementer) ) {
2116
    *value = tmp;
2117
    return 1; // value changed
2118
  }
236 tk 2119
 
240 tk 2120
  return 0; // value hasn't been changed
2121
}
2122
 
2123
 
236 tk 2124
/////////////////////////////////////////////////////////////////////////////
168 tk 2125
// Increments a CC within given min/max range
2126
// OUT: 1 if value has been changed, otherwise 0
2127
/////////////////////////////////////////////////////////////////////////////
248 tk 2128
s32 SEQ_UI_CC_Inc(u8 cc, u8 min, u8 max, s32 incrementer)
168 tk 2129
{
2130
  u8 visible_track = SEQ_UI_VisibleTrackGet();
173 tk 2131
  int new_value = SEQ_CC_Get(visible_track, cc);
2132
  int prev_value = new_value;
168 tk 2133
 
2134
  if( incrementer >= 0 ) {
173 tk 2135
    if( (new_value += incrementer) >= max )
2136
      new_value = max;
168 tk 2137
  } else {
173 tk 2138
    if( (new_value += incrementer) < min )
2139
      new_value = min;
168 tk 2140
  }
2141
 
173 tk 2142
  if( new_value == prev_value )
168 tk 2143
    return 0; // no change
2144
 
173 tk 2145
  SEQ_CC_Set(visible_track, cc, new_value);
168 tk 2146
 
179 tk 2147
  // set same value for all selected tracks
2148
  u8 track;
2149
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
2150
    if( track != visible_track && SEQ_UI_IsSelectedTrack(track) )
2151
      SEQ_CC_Set(track, cc, new_value);
2152
 
168 tk 2153
  return 1; // value changed
2154
}
2155
 
173 tk 2156
 
2157
/////////////////////////////////////////////////////////////////////////////
179 tk 2158
// Sets a CC value on all selected tracks
2159
// OUT: 1 if value has been changed, otherwise 0
2160
/////////////////////////////////////////////////////////////////////////////
248 tk 2161
s32 SEQ_UI_CC_Set(u8 cc, u8 value)
179 tk 2162
{
2163
  u8 visible_track = SEQ_UI_VisibleTrackGet();
2164
  int prev_value = SEQ_CC_Get(visible_track, cc);
2165
 
2166
  if( value == prev_value )
2167
    return 0; // no change
2168
 
2169
  SEQ_CC_Set(visible_track, cc, value);
2170
 
2171
  // set same value for all selected tracks
2172
  u8 track;
2173
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
2174
    if( track != visible_track && SEQ_UI_IsSelectedTrack(track) )
2175
      SEQ_CC_Set(track, cc, value);
2176
 
2177
  return 1; // value changed
2178
}
2179
 
2180
/////////////////////////////////////////////////////////////////////////////
173 tk 2181
// Modifies a bitfield in a CC value to a given value
2182
// OUT: 1 if value has been changed, otherwise 0
2183
/////////////////////////////////////////////////////////////////////////////
248 tk 2184
s32 SEQ_UI_CC_SetFlags(u8 cc, u8 flag_mask, u8 value)
173 tk 2185
{
2186
  u8 visible_track = SEQ_UI_VisibleTrackGet();
2187
  int new_value = SEQ_CC_Get(visible_track, cc);
2188
  int prev_value = new_value;
2189
 
2190
  new_value = (new_value & ~flag_mask) | value;
2191
 
2192
  if( new_value == prev_value )
2193
    return 0; // no change
2194
 
2195
  SEQ_CC_Set(visible_track, cc, new_value);
2196
 
179 tk 2197
  // do same modification for all selected tracks
2198
  u8 track;
2199
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
2200
    if( track != visible_track && SEQ_UI_IsSelectedTrack(track) ) {
2201
      int new_value = SEQ_CC_Get(track, cc);
2202
      new_value = (new_value & ~flag_mask) | value;
2203
      SEQ_CC_Set(track, cc, new_value);
2204
    }
2205
 
173 tk 2206
  return 1; // value changed
2207
}
2208
 
2209
 
299 tk 2210
/////////////////////////////////////////////////////////////////////////////
596 tk 2211
// Print temporary user messages (e.g. warnings, errors)
299 tk 2212
// expects mS delay and two lines, each up to 20 characters
2213
/////////////////////////////////////////////////////////////////////////////
596 tk 2214
s32 SEQ_UI_Msg(seq_ui_msg_type_t msg_type, u16 delay, char *line1, char *line2)
299 tk 2215
{
596 tk 2216
  ui_msg_type = msg_type;
2217
  ui_msg_ctr = delay;
2218
  strncpy((char *)ui_msg[0], line1, UI_MSG_MAX_CHAR);
2219
  strncpy((char *)ui_msg[1], line2, UI_MSG_MAX_CHAR);
299 tk 2220
 
2221
  return 0; // no error
2222
}
2223
 
2224
/////////////////////////////////////////////////////////////////////////////
596 tk 2225
// Stops temporary message if no SD card warning
2226
/////////////////////////////////////////////////////////////////////////////
2227
s32 SEQ_UI_MsgStop(void)
2228
{
2229
  if( ui_msg_type != SEQ_UI_MSG_SDCARD )
2230
    ui_msg_ctr = 0;
2231
 
2232
  return 0; // no error
2233
}
2234
 
2235
/////////////////////////////////////////////////////////////////////////////
299 tk 2236
// Prints a temporary error messages after file operation
2237
// Expects error status number (as defined in seq_file.h)
2238
/////////////////////////////////////////////////////////////////////////////
2239
s32 SEQ_UI_SDCardErrMsg(u16 delay, s32 status)
2240
{
2241
  // TODO: add more verbose error messages, they are clearly defined in seq_file.h)
2242
  char str[21];
2243
  sprintf(str, "E%3d (DOSFS: D%3d)", -status, seq_file_dfs_errno < 1000 ? seq_file_dfs_errno : 999);
596 tk 2244
  return SEQ_UI_Msg(SEQ_UI_MSG_SDCARD, delay, "!! SD Card Error !!!", str);
299 tk 2245
}