Subversion Repositories svn.mios32

Rev

Rev 1454 | Rev 1523 | 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 1488 2012-07-16 18:10:24Z 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>
26
#include <seq_bpm.h>
134 tk 27
 
290 tk 28
#include "tasks.h"
134 tk 29
#include "seq_ui.h"
728 tk 30
#include "seq_lcd.h"
31
#include "seq_lcd_logo.h"
492 tk 32
#include "seq_hwcfg.h"
134 tk 33
#include "seq_lcd.h"
34
#include "seq_led.h"
186 tk 35
#include "seq_midply.h"
134 tk 36
#include "seq_core.h"
399 tk 37
#include "seq_song.h"
333 tk 38
#include "seq_par.h"
178 tk 39
#include "seq_layer.h"
184 tk 40
#include "seq_cc.h"
1313 tk 41
#include "seq_record.h"
785 tk 42
#include "seq_midi_sysex.h"
1336 tk 43
#include "seq_midi_port.h"
1020 tk 44
#include "seq_blm.h"
1261 tk 45
 
46
#include "file.h"
299 tk 47
#include "seq_file.h"
1281 tk 48
#include "seq_file_t.h"
690 tk 49
#include "seq_file_hw.h"
134 tk 50
 
51
 
52
/////////////////////////////////////////////////////////////////////////////
53
// Global variables
54
/////////////////////////////////////////////////////////////////////////////
55
 
159 tk 56
u8 seq_ui_display_update_req;
57
u8 seq_ui_display_init_req;
134 tk 58
 
167 tk 59
seq_ui_button_state_t seq_ui_button_state;
60
 
134 tk 61
u8 ui_selected_group;
484 tk 62
u16 ui_selected_tracks;
134 tk 63
u8 ui_selected_par_layer;
64
u8 ui_selected_trg_layer;
328 tk 65
u8 ui_selected_instrument;
134 tk 66
u8 ui_selected_step_view;
67
u8 ui_selected_step;
168 tk 68
u8 ui_selected_item;
1319 tk 69
u16 ui_selected_gp_buttons;
134 tk 70
 
168 tk 71
u8 ui_selected_item;
134 tk 72
 
240 tk 73
u16 ui_hold_msg_ctr;
74
 
206 tk 75
seq_ui_page_t ui_page;
272 tk 76
seq_ui_page_t ui_selected_page;
600 tk 77
seq_ui_page_t ui_stepview_prev_page;
78
seq_ui_page_t ui_trglayer_prev_page;
79
seq_ui_page_t ui_parlayer_prev_page;
206 tk 80
 
173 tk 81
volatile u8 ui_cursor_flash;
740 tk 82
volatile u8 ui_cursor_flash_overrun_ctr;
173 tk 83
u16 ui_cursor_flash_ctr;
134 tk 84
 
316 tk 85
u8 ui_edit_name_cursor;
86
u8 ui_edit_preset_num_category;
87
u8 ui_edit_preset_num_label;
729 tk 88
u8 ui_edit_preset_num_drum;
316 tk 89
 
193 tk 90
u8 ui_seq_pause;
91
 
1421 tk 92
u8 ui_song_edit_pos;
93
 
634 tk 94
u8 seq_ui_backup_req;
740 tk 95
u8 seq_ui_format_req;
974 tk 96
u8 seq_ui_saveall_req;
625 tk 97
 
744 tk 98
// to display directories via SEQ_UI_SelectListItem() and SEQ_LCD_PrintList() -- see seq_ui_sysex.c as example
746 tk 99
char ui_global_dir_list[80];
634 tk 100
 
1203 tk 101
seq_ui_bookmark_t seq_ui_bookmarks[SEQ_UI_BOOKMARKS_NUM];
744 tk 102
 
1349 tk 103
 
134 tk 104
/////////////////////////////////////////////////////////////////////////////
105
// Local variables
106
/////////////////////////////////////////////////////////////////////////////
107
 
168 tk 108
static s32 (*ui_button_callback)(seq_ui_button_t button, s32 depressed);
109
static s32 (*ui_encoder_callback)(seq_ui_encoder_t encoder, s32 incrementer);
173 tk 110
static s32 (*ui_led_callback)(u16 *gp_leds);
167 tk 111
static s32 (*ui_lcd_callback)(u8 high_prio);
352 tk 112
static s32 (*ui_exit_callback)(void);
752 tk 113
static s32 (*ui_delayed_action_callback)(u32 parameter);
114
static u32 ui_delayed_action_parameter;
167 tk 115
 
168 tk 116
static u16 ui_gp_leds;
167 tk 117
 
1040 tk 118
#define UI_MSG_MAX_CHAR 31
596 tk 119
static char ui_msg[2][UI_MSG_MAX_CHAR];
120
static u16 ui_msg_ctr;
121
static seq_ui_msg_type_t ui_msg_type;
299 tk 122
 
740 tk 123
static u16 ui_delayed_action_ctr;
299 tk 124
 
1203 tk 125
static seq_ui_page_t ui_page_before_bookmark;
752 tk 126
 
1454 midilab 127
mios32_sys_time_t seq_play_timer;
752 tk 128
 
134 tk 129
/////////////////////////////////////////////////////////////////////////////
130
// Initialisation
131
/////////////////////////////////////////////////////////////////////////////
132
s32 SEQ_UI_Init(u32 mode)
133
{
626 tk 134
  int i;
135
  // clear all LEDs
136
  for(i=0; i<SEQ_LED_NUM_SR; ++i)
137
    SEQ_LED_SRSet(i, 0x00);
138
 
134 tk 139
  // init selection variables
140
  ui_selected_group = 0;
141
  ui_selected_tracks = (1 << 0);
142
  ui_selected_par_layer = 0;
143
  ui_selected_trg_layer = 0;
328 tk 144
  ui_selected_instrument = 0;
134 tk 145
  ui_selected_step_view = 0;
146
  ui_selected_step = 0;
168 tk 147
  ui_selected_item = 0;
1319 tk 148
  ui_selected_gp_buttons = 0;
134 tk 149
 
240 tk 150
  ui_hold_msg_ctr = 0;
596 tk 151
  ui_msg_ctr = 0;
740 tk 152
  ui_delayed_action_ctr = 0;
240 tk 153
 
740 tk 154
  ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
173 tk 155
  ui_cursor_flash = 0;
168 tk 156
 
167 tk 157
  seq_ui_button_state.ALL = 0;
158
 
193 tk 159
  ui_seq_pause = 0;
160
 
1421 tk 161
  ui_song_edit_pos = 0;
162
 
134 tk 163
  // visible GP pattern
164
  ui_gp_leds = 0x0000;
165
 
634 tk 166
  // misc
167
  seq_ui_backup_req = 0;
740 tk 168
  seq_ui_format_req = 0;
974 tk 169
  seq_ui_saveall_req = 0;
634 tk 170
 
167 tk 171
  // change to edit page
172
  ui_page = SEQ_UI_PAGE_NONE;
173
  SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
134 tk 174
 
1203 tk 175
  // finally init bookmarks
176
  ui_page_before_bookmark = SEQ_UI_PAGE_EDIT;
177
  for(i=0; i<SEQ_UI_BOOKMARKS_NUM; ++i) {
178
    char buffer[10];
179
    seq_ui_bookmark_t *bm = (seq_ui_bookmark_t *)&seq_ui_bookmarks[i];
596 tk 180
 
1203 tk 181
    sprintf(buffer, "BM%2d ", i+1);
182
    memcpy((char *)bm->name, buffer, 6);
183
    bm->enable.ALL = ~0;
184
    bm->flags.LOCKED = 0;
185
    SEQ_UI_Bookmark_Store(i);
186
  }
187
 
134 tk 188
  return 0; // no error
189
}
190
 
191
 
192
/////////////////////////////////////////////////////////////////////////////
178 tk 193
// Inits the speed mode of all encoders
194
// Auto mode should be used whenever:
195
//    - the edit screen is entered
196
//    - the group is changed
197
//    - a track is changed
198
//    - a layer is changed
199
/////////////////////////////////////////////////////////////////////////////
200
s32 SEQ_UI_InitEncSpeed(u32 auto_config)
201
{
202
  mios32_enc_config_t enc_config;
203
 
204
  if( auto_config ) {
513 tk 205
 
206
    if( !seq_hwcfg_enc.auto_fast )
207
      return 0; // auto mode not enabled - ignore auto reconfiguration request
208
 
333 tk 209
    switch( SEQ_PAR_AssignmentGet(SEQ_UI_VisibleTrackGet(), ui_selected_par_layer) ) {
210
      case SEQ_PAR_Type_Velocity:
211
      case SEQ_PAR_Type_Length:
212
      case SEQ_PAR_Type_CC:
213
      case SEQ_PAR_Type_PitchBend:
214
      case SEQ_PAR_Type_Probability:
215
      case SEQ_PAR_Type_Delay:
1422 tk 216
      case SEQ_PAR_Type_ProgramChange:
1420 tk 217
        seq_ui_button_state.FAST_ENCODERS = 1;
218
        break;
178 tk 219
 
220
      default:
1420 tk 221
        seq_ui_button_state.FAST_ENCODERS = 0;
178 tk 222
    }
223
  }
224
 
225
  // change for datawheel and GP encoders
226
  int enc;
1341 tk 227
  for(enc=0; enc<SEQ_HWCFG_NUM_ENCODERS; ++enc) {
178 tk 228
    enc_config = MIOS32_ENC_ConfigGet(enc);
1121 tk 229
    enc_config.cfg.speed = (seq_ui_button_state.FAST_ENCODERS || seq_ui_button_state.FAST2_ENCODERS) ? FAST : NORMAL;
1341 tk 230
    enc_config.cfg.speed_par =
231
        (enc == 0)  ? seq_hwcfg_enc.datawheel_fast_speed
232
      : (enc == 17) ? seq_hwcfg_enc.bpm_fast_speed
233
      : seq_hwcfg_enc.gp_fast_speed;
178 tk 234
    MIOS32_ENC_ConfigSet(enc, enc_config);
235
  }
236
 
237
  return 0; // no error
238
}
239
 
240
 
241
/////////////////////////////////////////////////////////////////////////////
167 tk 242
// Various installation routines for menu page LCD handlers
243
/////////////////////////////////////////////////////////////////////////////
168 tk 244
s32 SEQ_UI_InstallButtonCallback(void *callback)
167 tk 245
{
168 tk 246
  ui_button_callback = callback;
167 tk 247
  return 0; // no error
248
}
249
 
168 tk 250
s32 SEQ_UI_InstallEncoderCallback(void *callback)
167 tk 251
{
168 tk 252
  ui_encoder_callback = callback;
167 tk 253
  return 0; // no error
254
}
255
 
168 tk 256
s32 SEQ_UI_InstallLEDCallback(void *callback)
167 tk 257
{
168 tk 258
  ui_led_callback = callback;
167 tk 259
  return 0; // no error
260
}
261
 
168 tk 262
s32 SEQ_UI_InstallLCDCallback(void *callback)
167 tk 263
{
264
  ui_lcd_callback = callback;
265
  return 0; // no error
266
}
267
 
352 tk 268
s32 SEQ_UI_InstallExitCallback(void *callback)
269
{
270
  ui_exit_callback = callback;
271
  return 0; // no error
272
}
167 tk 273
 
352 tk 274
 
752 tk 275
s32 SEQ_UI_InstallDelayedActionCallback(void *callback, u16 delay_mS, u32 parameter)
740 tk 276
{
752 tk 277
  // must be atomic
278
  MIOS32_IRQ_Disable();
279
  ui_delayed_action_parameter = parameter;
740 tk 280
  ui_delayed_action_callback = callback;
752 tk 281
  ui_delayed_action_ctr = delay_mS;
282
  MIOS32_IRQ_Enable();
740 tk 283
 
284
  return 0; // no error
285
}
286
 
287
s32 SEQ_UI_UnInstallDelayedActionCallback(void *callback)
288
{
752 tk 289
  // must be atomic
290
  MIOS32_IRQ_Disable();
740 tk 291
  if( ui_delayed_action_callback == callback )
292
    ui_delayed_action_callback = 0;
752 tk 293
  MIOS32_IRQ_Enable();
294
 
740 tk 295
  return 0; // no error
296
}
297
 
298
 
167 tk 299
/////////////////////////////////////////////////////////////////////////////
300
// Change the menu page
301
/////////////////////////////////////////////////////////////////////////////
302
s32 SEQ_UI_PageSet(seq_ui_page_t page)
303
{
304
  if( page != ui_page ) {
352 tk 305
 
306
    // call page exit callback
307
    if( ui_exit_callback != NULL )
308
      ui_exit_callback();
309
 
167 tk 310
    // disable hooks of previous page and request re-initialisation
318 tk 311
    portENTER_CRITICAL();
167 tk 312
    ui_page = page;
168 tk 313
    ui_button_callback = NULL;
314
    ui_encoder_callback = NULL;
315
    ui_led_callback = NULL;
167 tk 316
    ui_lcd_callback = NULL;
352 tk 317
    ui_exit_callback = NULL;
740 tk 318
    ui_delayed_action_callback = NULL;
318 tk 319
    portEXIT_CRITICAL();
167 tk 320
 
1420 tk 321
    // always disable ALL button when changing page
322
    seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE = 0;
323
    seq_ui_button_state.CHANGE_ALL_STEPS = 0;
324
 
167 tk 325
    // request display initialisation
326
    seq_ui_display_init_req = 1;
327
  }
173 tk 328
 
306 tk 329
  // for MENU button:
1024 tk 330
  if( seq_hwcfg_button_beh.menu )
331
    seq_ui_button_state.MENU_PRESSED = 0; // MENU page selection finished
1420 tk 332
 
306 tk 333
  // first page has been selected - display new screen
334
  seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 1;
335
 
272 tk 336
  // for SEQ_UI_MENU which is accessible with EXIT button
337
  // remember the current selectable page
338
  if( ui_page >= SEQ_UI_FIRST_MENU_SELECTION_PAGE )
339
    ui_selected_page = ui_page;
340
 
184 tk 341
  return 0; // no error
167 tk 342
}
343
 
344
 
345
/////////////////////////////////////////////////////////////////////////////
272 tk 346
// Returns name of menu page (18 characters)
347
/////////////////////////////////////////////////////////////////////////////
348
char *SEQ_UI_PageNameGet(seq_ui_page_t page)
349
{
690 tk 350
  return (char *)ui_menu_pages[page].name;
272 tk 351
}
352
 
353
 
354
/////////////////////////////////////////////////////////////////////////////
134 tk 355
// Dedicated button functions
356
// Mapped to physical buttons in SEQ_UI_Button_Handler()
357
// Will also be mapped to MIDI keys later (for MIDI remote function)
358
/////////////////////////////////////////////////////////////////////////////
359
static s32 SEQ_UI_Button_GP(s32 depressed, u32 gp)
360
{
1044 tk 361
  // in MENU page: overrule GP buttons as long as MENU button is pressed/active
306 tk 362
  if( seq_ui_button_state.MENU_PRESSED ) {
363
    if( depressed ) return -1;
364
    SEQ_UI_PageSet(ui_shortcut_menu_pages[gp]);
365
  } else {
1319 tk 366
    if( depressed )
367
      ui_selected_gp_buttons &= ~(1 << gp);
368
    else
369
      ui_selected_gp_buttons |= (1 << gp);
370
 
306 tk 371
    // forward to menu page
740 tk 372
    if( ui_button_callback != NULL ) {
306 tk 373
      ui_button_callback(gp, depressed);
740 tk 374
      ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
375
    }
306 tk 376
  }
134 tk 377
 
378
  return 0; // no error
379
}
380
 
381
static s32 SEQ_UI_Button_Left(s32 depressed)
382
{
168 tk 383
  // forward to menu page
740 tk 384
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL ) {
168 tk 385
    ui_button_callback(SEQ_UI_BUTTON_Left, depressed);
740 tk 386
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
387
  }
134 tk 388
 
389
  return 0; // no error
390
}
391
 
392
static s32 SEQ_UI_Button_Right(s32 depressed)
393
{
168 tk 394
  // forward to menu page
740 tk 395
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL ) {
168 tk 396
    ui_button_callback(SEQ_UI_BUTTON_Right, depressed);
740 tk 397
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
398
  }
134 tk 399
 
400
  return 0; // no error
401
}
402
 
168 tk 403
static s32 SEQ_UI_Button_Down(s32 depressed)
404
{
240 tk 405
  seq_ui_button_state.DOWN = depressed ? 0 : 1;
406
 
168 tk 407
  // forward to menu page
740 tk 408
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL ) {
168 tk 409
    ui_button_callback(SEQ_UI_BUTTON_Down, depressed);
740 tk 410
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
411
  }
168 tk 412
 
413
  return 0; // no error
414
}
415
 
416
static s32 SEQ_UI_Button_Up(s32 depressed)
417
{
240 tk 418
  seq_ui_button_state.UP = depressed ? 0 : 1;
419
 
168 tk 420
  // forward to menu page
740 tk 421
  if( !seq_ui_button_state.MENU_PRESSED && ui_button_callback != NULL ) {
168 tk 422
    ui_button_callback(SEQ_UI_BUTTON_Up, depressed);
740 tk 423
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
424
  }
168 tk 425
 
426
  return 0; // no error
427
}
428
 
1068 tk 429
s32 SEQ_UI_Button_Stop(s32 depressed)
134 tk 430
{
431
  if( depressed ) return -1; // ignore when button depressed
432
 
159 tk 433
  // if sequencer running: stop it
434
  // if sequencer already stopped: reset song position
1206 tk 435
  if( SEQ_BPM_IsRunning() ) {
436
#if 0
437
    // TK: maybe to complicated to understand: STOP sequencer in slave mode if stop button pressed twice
438
    u8 enable_slaveclk_mute = !SEQ_BPM_IsMaster() && seq_core_slaveclk_mute != SEQ_CORE_SLAVECLK_MUTE_Enabled;
439
#else
440
    // always mute tracks, never stop sequencer (can only be done from external)
441
    u8 enable_slaveclk_mute = !SEQ_BPM_IsMaster();
442
#endif
443
    if( enable_slaveclk_mute ) {
444
      seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_Enabled;
445
    } else {
446
      seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_Off;
447
      SEQ_BPM_Stop();
448
    }
449
  } else {
450
    seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_Off;
1145 tk 451
    SEQ_SONG_Reset(0);
452
    SEQ_CORE_Reset(0);
759 tk 453
    SEQ_MIDPLY_Reset();
454
  }
159 tk 455
 
1454 midilab 456
    seq_play_timer.seconds = 0;
457
 
134 tk 458
  return 0; // no error
459
}
460
 
461
static s32 SEQ_UI_Button_Pause(s32 depressed)
462
{
463
  if( depressed ) return -1; // ignore when button depressed
464
 
1206 tk 465
  // if in auto mode and BPM generator is not clocked in slave mode:
193 tk 466
  // change to master mode
467
  SEQ_BPM_CheckAutoMaster();
159 tk 468
 
1206 tk 469
  // toggle pause
193 tk 470
  ui_seq_pause ^= 1;
471
 
472
  // execute stop/continue depending on new mode
1206 tk 473
  MIOS32_IRQ_Disable();
474
  if( ui_seq_pause ) {
475
    if( !SEQ_BPM_IsMaster() ) {
476
      seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_Enabled;
477
    } else {
478
      SEQ_BPM_Stop();
479
    }
480
  } else {
481
    if( !SEQ_BPM_IsMaster() ) {
482
      seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_Off;
483
    }
193 tk 484
 
1206 tk 485
    if( !SEQ_BPM_IsRunning() )
486
      SEQ_BPM_Cont();
487
  }
488
  MIOS32_IRQ_Enable();
489
 
134 tk 490
  return 0; // no error
491
}
492
 
1068 tk 493
s32 SEQ_UI_Button_Play(s32 depressed)
134 tk 494
{
495
  if( depressed ) return -1; // ignore when button depressed
496
 
1090 tk 497
  // if MENU button pressed -> tap tempo
498
  if( seq_ui_button_state.MENU_PRESSED )
499
    return SEQ_UI_BPM_TapTempo();
500
 
1206 tk 501
  // if in auto mode and BPM generator is not clocked in slave mode:
186 tk 502
  // change to master mode
503
  SEQ_BPM_CheckAutoMaster();
504
 
1206 tk 505
  // slave mode and tracks muted: enable on next measure
506
  if( !SEQ_BPM_IsMaster() && SEQ_BPM_IsRunning() ) {
507
    if( seq_core_slaveclk_mute != SEQ_CORE_SLAVECLK_MUTE_Off )
508
      seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_OffOnNextMeasure;
509
    // TK: note - in difference to master mode pressing PLAY twice won't reset the sequencer!
510
  } else {
193 tk 511
#if 0
1206 tk 512
    // if sequencer running: restart it
513
    // if sequencer stopped: continue at last song position
514
    if( SEQ_BPM_IsRunning() )
515
      SEQ_BPM_Start();
516
    else
517
      SEQ_BPM_Cont();
518
#else
519
    // always restart sequencer
520
    seq_core_slaveclk_mute = SEQ_CORE_SLAVECLK_MUTE_Off;
193 tk 521
    SEQ_BPM_Start();
186 tk 522
#endif
1206 tk 523
  }
159 tk 524
 
1454 midilab 525
    seq_play_timer = MIOS32_SYS_TimeGet();
526
 
134 tk 527
  return 0; // no error
528
}
529
 
530
static s32 SEQ_UI_Button_Rew(s32 depressed)
531
{
240 tk 532
  seq_ui_button_state.REW = depressed ? 0 : 1;
533
 
134 tk 534
  if( depressed ) return -1; // ignore when button depressed
535
 
607 tk 536
  if( SEQ_SONG_ActiveGet() ) {
537
    portENTER_CRITICAL();
538
    SEQ_SONG_Rew();
539
    portEXIT_CRITICAL();
540
  } else
541
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "We are not", "in Song Mode!");
542
 
134 tk 543
  return 0; // no error
544
}
545
 
546
static s32 SEQ_UI_Button_Fwd(s32 depressed)
547
{
240 tk 548
  seq_ui_button_state.FWD = depressed ? 0 : 1;
549
 
134 tk 550
  if( depressed ) return -1; // ignore when button depressed
551
 
607 tk 552
  if( SEQ_SONG_ActiveGet() ) {
553
    portENTER_CRITICAL();
554
    SEQ_SONG_Fwd();
555
    portEXIT_CRITICAL();
556
  } else
557
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "We are not", "in Song Mode!");
558
 
134 tk 559
  return 0; // no error
560
}
561
 
596 tk 562
static s32 SEQ_UI_Button_Loop(s32 depressed)
563
{
564
  if( seq_hwcfg_button_beh.loop ) {
565
    // toggle mode
566
    if( depressed ) return -1; // ignore when button depressed
567
    // should be atomic
568
    portENTER_CRITICAL();
569
    seq_core_state.LOOP ^= 1;
570
  } else {
571
    // should be atomic
572
    portENTER_CRITICAL();
573
    // set mode
574
    seq_core_state.LOOP = depressed ? 0 : 1;
575
  }
576
  portEXIT_CRITICAL();
577
 
578
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Loop Mode", seq_core_state.LOOP ? "    on" : "   off");
579
 
580
  return 0; // no error
581
}
582
 
951 tk 583
static s32 SEQ_UI_Button_Follow(s32 depressed)
584
{
585
  if( seq_hwcfg_button_beh.follow ) {
586
    // toggle mode
587
    if( depressed ) return -1; // ignore when button depressed
588
    // should be atomic
589
    portENTER_CRITICAL();
590
    seq_core_state.FOLLOW ^= 1;
591
  } else {
592
    // should be atomic
593
    portENTER_CRITICAL();
594
    // set mode
595
    seq_core_state.FOLLOW = depressed ? 0 : 1;
596
  }
597
  portEXIT_CRITICAL();
598
 
599
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Follow Mode", seq_core_state.FOLLOW ? "    on" : "   off");
600
 
601
  return 0; // no error
602
}
603
 
596 tk 604
static s32 SEQ_UI_Button_Scrub(s32 depressed)
605
{
606
  // double function: -> Loop if menu button pressed
607
  if( seq_ui_button_state.MENU_PRESSED )
608
    return SEQ_UI_Button_Loop(depressed);
609
 
610
  if( seq_hwcfg_button_beh.scrub ) {
611
    // toggle mode
612
    if( depressed ) return -1; // ignore when button depressed
613
    seq_ui_button_state.SCRUB ^= 1;
614
  } else {
615
    // set mode
616
    seq_ui_button_state.SCRUB = depressed ? 0 : 1;
617
  }
618
 
619
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Scrub Mode", seq_ui_button_state.SCRUB ? "    on" : "   off");
620
 
621
  return 0; // no error
622
}
623
 
513 tk 624
static s32 SEQ_UI_Button_TempoPreset(s32 depressed)
134 tk 625
{
513 tk 626
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
240 tk 627
 
513 tk 628
  if( seq_hwcfg_button_beh.tempo_preset ) {
629
    if( depressed ) return -1; // ignore when button depressed
678 tk 630
    if( !seq_ui_button_state.TEMPO_PRESET ) // due to page change: button going to be set, clear other toggle buttons
631
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 632
    seq_ui_button_state.TEMPO_PRESET ^= 1; // toggle TEMPO_PRESET pressed (will also be released once GP button has been pressed)
633
  } else {
634
    // set mode
635
    seq_ui_button_state.TEMPO_PRESET = depressed ? 0 : 1;
636
  }
134 tk 637
 
513 tk 638
  if( seq_ui_button_state.TEMPO_PRESET ) {
639
    prev_page = ui_page;
640
    SEQ_UI_PageSet(SEQ_UI_PAGE_BPM_PRESETS);
641
  } else {
524 tk 642
    if( ui_page == SEQ_UI_PAGE_BPM_PRESETS )
643
      SEQ_UI_PageSet(prev_page);
513 tk 644
  }
240 tk 645
 
134 tk 646
  return 0; // no error
647
}
648
 
513 tk 649
static s32 SEQ_UI_Button_TapTempo(s32 depressed)
134 tk 650
{
513 tk 651
  seq_ui_button_state.TAP_TEMPO = depressed ? 0 : 1;
240 tk 652
 
134 tk 653
  if( depressed ) return -1; // ignore when button depressed
654
 
1142 tk 655
  return SEQ_UI_BPM_TapTempo();
134 tk 656
}
657
 
524 tk 658
static s32 SEQ_UI_Button_ExtRestart(s32 depressed)
134 tk 659
{
660
  if( depressed ) return -1; // ignore when button depressed
661
 
596 tk 662
  // should be atomic
524 tk 663
  portENTER_CRITICAL();
664
  seq_core_state.EXT_RESTART_REQ = 1;
665
  portEXIT_CRITICAL();
666
 
596 tk 667
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "External Restart", "requested");
668
 
134 tk 669
  return 0; // no error
670
}
671
 
596 tk 672
static s32 SEQ_UI_Button_Metronome(s32 depressed)
673
{
674
  // double function: -> ExtRestart if menu button pressed
675
  if( seq_ui_button_state.MENU_PRESSED )
676
    return SEQ_UI_Button_ExtRestart(depressed);
677
 
678
  if( seq_hwcfg_button_beh.metronome ) {
679
    // toggle mode
680
    if( depressed ) return -1; // ignore when button depressed
681
    // should be atomic
682
    portENTER_CRITICAL();
683
    seq_core_state.METRONOME ^= 1;
684
  } else {
685
    // should be atomic
686
    portENTER_CRITICAL();
687
    // set mode
688
    seq_core_state.METRONOME = depressed ? 0 : 1;
689
  }
690
  portEXIT_CRITICAL();
691
 
692
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Metronome", seq_core_state.METRONOME ? "    on" : "   off");
693
 
599 tk 694
#if 0
695
  // metronome button can be used to trigger pattern file fixes
696
  if( !depressed )
697
    SEQ_PATTERN_FixAll();
698
#endif
699
 
596 tk 700
  return 0; // no error
701
}
702
 
630 tk 703
static s32 SEQ_UI_Button_Record(s32 depressed)
704
{
705
  if( depressed ) return -1; // ignore when button depressed
706
 
1219 tk 707
  // change to record page
630 tk 708
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKREC);
709
 
710
  return 0; // no error
711
}
712
 
1219 tk 713
static s32 SEQ_UI_Button_Live(s32 depressed)
714
{
715
  if( depressed ) return -1; // ignore when button depressed
716
 
717
  // change to live page
718
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKLIVE);
719
 
720
  return 0; // no error
721
}
722
 
134 tk 723
static s32 SEQ_UI_Button_Utility(s32 depressed)
724
{
725
  if( depressed ) return -1; // ignore when button depressed
726
 
240 tk 727
  // change to utility page
728
  SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
729
 
134 tk 730
  return 0; // no error
731
}
732
 
1281 tk 733
static s32 SEQ_UI_Button_MultiCopy(s32 depressed)
734
{
735
  if( depressed ) return 1;
736
 
737
  s32 status = 0;
738
  char path[30];
739
 
740
  // create directory if it doesn't exist
741
  strcpy(path, "/PRESETS");
742
  MUTEX_SDCARD_TAKE;
743
  status = FILE_MakeDir(path);
744
  status = FILE_DirExists(path);
745
  MUTEX_SDCARD_GIVE;
746
 
747
  if( status < 0 ) {
748
    SEQ_UI_SDCardErrMsg(2000, status);
749
    return -3;
750
  }
751
 
752
  if( status == 0 ) {
753
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "/PRESETS directory", "cannot be created!");
754
    return -4;
755
  }
756
 
757
  // copy all selected patterns to preset directory
758
  u8 track, track_id;
759
  for(track=0, track_id=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
760
    if( ui_selected_tracks & (1 << track) ) {
761
      ++track_id;
762
      sprintf(path, "/PRESETS/COPY%d.v4t", track_id);
763
 
764
      char str[30];
765
      sprintf(str, "Exporting G%dT%d to:", (track/4)+1, (track%4)+1);
766
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, str, path);
767
 
768
      MUTEX_SDCARD_TAKE;
1282 tk 769
      status=SEQ_FILE_T_Write(path, track);
1281 tk 770
      MUTEX_SDCARD_GIVE;
771
 
772
      if( status < 0 ) {
773
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "Error during Export!", "see MIOS Terminal!");
774
    return -6;
775
      }
776
    }
777
  }
778
 
779
  if( !track_id ) {
780
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "No Track selected", "for Multi-Copy!");
781
  }
782
 
783
  return 0; // no error
784
}
785
 
134 tk 786
static s32 SEQ_UI_Button_Copy(s32 depressed)
787
{
240 tk 788
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 789
 
240 tk 790
  seq_ui_button_state.COPY = depressed ? 0 : 1;
791
 
1281 tk 792
  if( seq_ui_button_state.MENU_PRESSED ) {
793
    return SEQ_UI_Button_MultiCopy(depressed);
794
  }
795
 
280 tk 796
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
797
    if( depressed ) return -1;
798
    SEQ_UI_MIXER_Copy();
729 tk 799
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Mixer Map", "copied");
280 tk 800
    return 1;
729 tk 801
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
802
    if( depressed ) return -1;
803
    SEQ_UI_SONG_Copy();
804
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Song Position", "copied");
805
    return 1;
280 tk 806
  } else {
807
    if( !depressed ) {
808
      prev_page = ui_page;
809
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
810
    }
240 tk 811
 
280 tk 812
    s32 status = SEQ_UI_UTIL_CopyButton(depressed);
240 tk 813
 
596 tk 814
    if( depressed ) {
815
      if( prev_page != SEQ_UI_PAGE_UTIL )
816
    SEQ_UI_PageSet(prev_page);
240 tk 817
 
596 tk 818
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "copied");
819
    }
820
 
280 tk 821
    return status;
822
  }
134 tk 823
}
824
 
1281 tk 825
static s32 SEQ_UI_Button_MultiPaste(s32 depressed)
826
{
827
  if( depressed ) return 1;
828
 
829
  s32 status = 0;
830
  char path[30];
831
 
832
  // paste multi copy presets into selected tracks
833
  u8 track, track_id;
834
  for(track=0, track_id=0; track<SEQ_CORE_NUM_TRACKS; ++track) {
835
    if( ui_selected_tracks & (1 << track) ) {
836
      ++track_id;
837
      sprintf(path, "/PRESETS/COPY%d.v4t", track_id);
838
 
839
      char str[30];
840
      sprintf(str, "Importing to G%dT%d:", (track/4)+1, (track%4)+1);
841
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, str, path);
842
 
843
      // mute track to avoid random effects while loading the file
844
      MIOS32_IRQ_Disable(); // this operation should be atomic!
845
      u8 muted = seq_core_trk_muted & (1 << track);
846
      if( !muted )
847
    seq_core_trk_muted |= (1 << track);
848
      MIOS32_IRQ_Enable();
849
 
850
      static seq_file_t_import_flags_t import_flags;
851
      import_flags.ALL = 0xff;
852
 
853
      // read file
854
      MUTEX_SDCARD_TAKE;
855
      status = SEQ_FILE_T_Read(path, track, import_flags);
856
      MUTEX_SDCARD_GIVE;
857
 
858
      // unmute track if it wasn't muted before
859
      MIOS32_IRQ_Disable(); // this operation should be atomic!
860
      if( !muted )
861
    seq_core_trk_muted &= ~(1 << track);
862
      MIOS32_IRQ_Enable();
863
 
864
      if( status == FILE_ERR_OPEN_READ ) {
865
    char str[30];
866
    sprintf(str, "File for G%dT%d missing:", (track/4)+1, (track%4)+1);
867
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, str, path);
868
      } else if( status < 0 ) {
869
    SEQ_UI_SDCardErrMsg(2000, status);
870
      } else {
871
    sprintf(str, "Imported to G%dT%d:", (track/4)+1, (track%4)+1);
872
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, str, path);
873
      }
874
    }
875
  }
876
 
877
  if( !track_id ) {
878
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "No Track selected", "for Multi-Paste!");
879
  }
880
 
881
  return 0; // no error
882
}
883
 
134 tk 884
static s32 SEQ_UI_Button_Paste(s32 depressed)
885
{
240 tk 886
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 887
 
240 tk 888
  seq_ui_button_state.PASTE = depressed ? 0 : 1;
889
 
1281 tk 890
  if( seq_ui_button_state.MENU_PRESSED ) {
891
    return SEQ_UI_Button_MultiPaste(depressed);
892
  }
893
 
280 tk 894
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
895
    if( depressed ) return -1;
896
    SEQ_UI_MIXER_Paste();
729 tk 897
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Mixer Map", "pasted");
280 tk 898
    return 1;
729 tk 899
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
900
    if( depressed ) return -1;
901
    SEQ_UI_SONG_Paste();
902
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Song Position", "pasted");
903
    return 1;
280 tk 904
  } else {
905
    if( !depressed ) {
906
      prev_page = ui_page;
907
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
908
    }
240 tk 909
 
280 tk 910
    s32 status = SEQ_UI_UTIL_PasteButton(depressed);
240 tk 911
 
596 tk 912
    if( depressed ) {
913
      if( prev_page != SEQ_UI_PAGE_UTIL )
914
    SEQ_UI_PageSet(prev_page);
240 tk 915
 
596 tk 916
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "pasted");
917
    }
918
 
280 tk 919
    return status;
920
  }
134 tk 921
}
922
 
740 tk 923
 
924
// callback function for delayed Clear Mixer function
752 tk 925
static void SEQ_UI_Button_Clear_Mixer(u32 dummy)
740 tk 926
{
927
  SEQ_UI_MIXER_Clear();
928
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Mixer Map", "cleared");
929
}
930
 
931
// callback function for delayed Clear SongPos function
752 tk 932
static void SEQ_UI_Button_Clear_SongPos(u32 dummy)
740 tk 933
{
934
  SEQ_UI_SONG_Clear();
935
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Song Position", "cleared");
936
}
937
 
938
// callback function for clear track
752 tk 939
static void SEQ_UI_Button_Clear_Track(u32 dummy)
740 tk 940
{
941
  SEQ_UI_UTIL_ClearButton(0); // button pressed
942
  SEQ_UI_UTIL_ClearButton(1); // button depressed
943
  SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "cleared");
944
}
945
 
134 tk 946
static s32 SEQ_UI_Button_Clear(s32 depressed)
947
{
240 tk 948
  seq_ui_button_state.CLEAR = depressed ? 0 : 1;
280 tk 949
 
950
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
740 tk 951
    if( depressed )
952
      SEQ_UI_UnInstallDelayedActionCallback(SEQ_UI_Button_Clear_Mixer);
752 tk 953
    else {
954
      SEQ_UI_InstallDelayedActionCallback(SEQ_UI_Button_Clear_Mixer, 2000, 0);
955
      SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION, 2001, "", "to clear Mixer Map");
956
    }
729 tk 957
    return 1;
958
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
740 tk 959
    if( depressed )
960
      SEQ_UI_UnInstallDelayedActionCallback(SEQ_UI_Button_Clear_SongPos);
752 tk 961
    else {
962
      SEQ_UI_InstallDelayedActionCallback(SEQ_UI_Button_Clear_SongPos, 2000, 0);
963
      SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION, 2001, "", "to clear SongPos");
964
    }
729 tk 965
    return 1;
966
  } else {
740 tk 967
    if( depressed )
968
      SEQ_UI_UnInstallDelayedActionCallback(SEQ_UI_Button_Clear_Track);
752 tk 969
    else {
970
      SEQ_UI_InstallDelayedActionCallback(SEQ_UI_Button_Clear_Track, 2000, 0);
971
      SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION, 2001, "", "to clear Track");
972
    }
280 tk 973
    return 1;
974
  }
134 tk 975
}
976
 
1014 tk 977
 
978
static s32 SEQ_UI_Button_Undo(s32 depressed)
979
{
980
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
981
 
982
  seq_ui_button_state.UNDO = depressed ? 0 : 1;
983
 
984
  if( ui_page == SEQ_UI_PAGE_MIXER ) {
985
    if( depressed ) return -1;
986
    SEQ_UI_MIXER_Undo();
987
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Mixer Map", "Undo applied");
988
    return 1;
989
  } else {
990
    if( !depressed ) {
991
      prev_page = ui_page;
992
      SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
993
    }
994
 
995
    s32 status = SEQ_UI_UTIL_UndoButton(depressed);
996
 
997
    if( depressed ) {
998
      if( prev_page != SEQ_UI_PAGE_UTIL )
999
    SEQ_UI_PageSet(prev_page);
1000
 
1001
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Track", "Undo applied");
1002
    }
1003
 
1004
    return status;
1005
  }
1006
}
1007
 
1008
 
134 tk 1009
static s32 SEQ_UI_Button_Menu(s32 depressed)
1010
{
513 tk 1011
  if( seq_hwcfg_button_beh.menu ) {
1012
    // toggle mode
1013
    if( depressed ) return -1; // ignore when button depressed
1014
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
678 tk 1015
    if( !seq_ui_button_state.MENU_PRESSED ) // due to page change: button going to be set, clear other toggle buttons
1016
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1017
    seq_ui_button_state.MENU_PRESSED ^= 1; // toggle MENU pressed (will also be released once GP button has been pressed)
1018
  } else {
1019
    // set mode
1020
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
1021
    seq_ui_button_state.MENU_PRESSED = depressed ? 0 : 1;
1022
  }
134 tk 1023
 
1024
  return 0; // no error
1025
}
1026
 
1203 tk 1027
 
1028
static s32 SEQ_UI_Button_Bookmark(s32 depressed)
1029
{
1030
  if( seq_hwcfg_button_beh.bookmark ) {
1031
    if( depressed ) return -1; // ignore when button depressed
1032
    if( !seq_ui_button_state.BOOKMARK ) // due to page change: button going to be set, clear other toggle buttons
1033
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
1034
#if 0
1035
    seq_ui_button_state.BOOKMARK ^= 1; // toggle BOOKMARK pressed (will also be released once GP button has been pressed)
1036
#else
1037
    seq_ui_button_state.BOOKMARK = 1; // seems that it's better *not* to toggle!
1038
#endif
1039
  } else {
1040
    // set mode
1041
    seq_ui_button_state.BOOKMARK = depressed ? 0 : 1;
1042
  }
1043
 
1044
  if( seq_ui_button_state.BOOKMARK ) {
1045
    if( ui_page != SEQ_UI_PAGE_BOOKMARKS )
1046
      ui_page_before_bookmark = ui_page;
1047
    SEQ_UI_PageSet(SEQ_UI_PAGE_BOOKMARKS);
1048
  } else {
1049
    if( ui_page == SEQ_UI_PAGE_BOOKMARKS )
1050
      SEQ_UI_PageSet(ui_page_before_bookmark);
1051
  }
1052
 
1053
  return 0; // no error
1054
}
1055
 
1056
 
1205 tk 1057
static s32 SEQ_UI_Button_DirectBookmark(s32 depressed, u32 bookmark_button)
1058
{
1059
  if( !depressed )
1060
    ui_page_before_bookmark = ui_page;
1061
 
1062
  return SEQ_UI_BOOKMARKS_Button_Handler(bookmark_button, depressed);
1063
}
1064
 
1065
 
134 tk 1066
static s32 SEQ_UI_Button_Select(s32 depressed)
1067
{
1203 tk 1068
  // double function: -> Bookmark if menu button pressed
1069
  if( seq_ui_button_state.MENU_PRESSED )
1070
    return SEQ_UI_Button_Bookmark(depressed);
1071
 
168 tk 1072
  // forward to menu page
591 tk 1073
  if( !seq_ui_button_state.MENU_PRESSED ) {
1074
    seq_ui_button_state.SELECT_PRESSED = depressed ? 0 : 1;
740 tk 1075
    if( ui_button_callback != NULL ) {
591 tk 1076
      ui_button_callback(SEQ_UI_BUTTON_Select, depressed);
740 tk 1077
      ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1078
    }
591 tk 1079
  }
134 tk 1080
 
1081
  return 0; // no error
1082
}
1083
 
1084
static s32 SEQ_UI_Button_Exit(s32 depressed)
1085
{
951 tk 1086
  // double function: -> Follow if menu button pressed
1087
  if( seq_ui_button_state.MENU_PRESSED )
1088
    return SEQ_UI_Button_Follow(depressed);
1089
 
272 tk 1090
  if( depressed ) return -1; // ignore when button depressed
1091
 
1092
  u8 prev_ui_page = ui_page;
1093
 
168 tk 1094
  // forward to menu page
1123 tk 1095
  if( ui_button_callback != NULL ) {
1096
    if( ui_button_callback(SEQ_UI_BUTTON_Exit, depressed) >= 1 )
1097
      return 1; // page has already handled exit button
740 tk 1098
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1099
  }
134 tk 1100
 
167 tk 1101
  // release all button states
984 tk 1102
  // seq_ui_button_state.ALL = 0;
1103
  // clashes with SOLO/ALL/etc.
167 tk 1104
 
272 tk 1105
  // enter menu page if we were not there before
1106
  if( prev_ui_page != SEQ_UI_PAGE_MENU )
1107
    SEQ_UI_PageSet(SEQ_UI_PAGE_MENU);
1108
 
134 tk 1109
  return 0; // no error
1110
}
1111
 
1112
static s32 SEQ_UI_Button_Edit(s32 depressed)
1113
{
741 tk 1114
  seq_ui_button_state.EDIT_PRESSED = depressed ? 0 : 1;
591 tk 1115
 
167 tk 1116
  // change to edit page
1350 tk 1117
  if( !depressed ) {
1118
    SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
167 tk 1119
 
1350 tk 1120
    // set/clear encoder fast function if required
1121
    SEQ_UI_InitEncSpeed(1); // auto config
1122
  }
178 tk 1123
 
1350 tk 1124
  // EDIT button notification to button callback
1125
  // currently only used in EDIT page itself!
1126
  if( depressed && ui_page != SEQ_UI_PAGE_EDIT )
1127
    return -1;
1128
 
1129
  if( ui_button_callback != NULL ) {
1130
    ui_button_callback(SEQ_UI_BUTTON_Edit, depressed);
1131
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1132
  }
1133
 
134 tk 1134
  return 0; // no error
1135
}
1136
 
1137
static s32 SEQ_UI_Button_Mute(s32 depressed)
1138
{
591 tk 1139
  seq_ui_button_state.MUTE_PRESSED = depressed ? 0 : 1;
1140
 
134 tk 1141
  if( depressed ) return -1; // ignore when button depressed
1142
 
184 tk 1143
  SEQ_UI_PageSet(SEQ_UI_PAGE_MUTE);
1144
 
134 tk 1145
  return 0; // no error
1146
}
1147
 
1148
static s32 SEQ_UI_Button_Pattern(s32 depressed)
1149
{
591 tk 1150
  seq_ui_button_state.PATTERN_PRESSED = depressed ? 0 : 1;
1151
 
134 tk 1152
  if( depressed ) return -1; // ignore when button depressed
1153
 
184 tk 1154
  SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN);
1155
 
134 tk 1156
  return 0; // no error
1157
}
1158
 
1454 midilab 1159
static s32 SEQ_UI_Button_Pattern_Remix(s32 depressed)
1160
{
1161
 
1162
    if ( ui_page == SEQ_UI_PAGE_PATTERN_RMX ) {
1163
        // to avoid race conditions using the same button(any other way of solving that?)
1164
        vTaskDelay(60);
1165
        // a trick to use the same button with 2 functionalitys
1166
        ui_button_callback(SEQ_UI_BUTTON_Edit, depressed);
1167
    } else {
1168
        SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN_RMX);
1169
    }
1170
 
1171
    return 0; // no error
1172
 
1173
}
1174
 
134 tk 1175
static s32 SEQ_UI_Button_Song(s32 depressed)
1176
{
591 tk 1177
  seq_ui_button_state.SONG_PRESSED = depressed ? 0 : 1;
1178
 
134 tk 1179
  if( depressed ) return -1; // ignore when button depressed
1180
 
399 tk 1181
  SEQ_UI_PageSet(SEQ_UI_PAGE_SONG);
1182
 
134 tk 1183
  return 0; // no error
1184
}
1185
 
1186
static s32 SEQ_UI_Button_Solo(s32 depressed)
1187
{
513 tk 1188
  if( seq_hwcfg_button_beh.solo ) {
1189
    // toggle mode
1190
    if( depressed ) return -1; // ignore when button depressed
1191
    seq_ui_button_state.SOLO ^= 1;
1192
  } else {
1193
    // set mode
1194
    seq_ui_button_state.SOLO = depressed ? 0 : 1;
1195
  }
134 tk 1196
 
1197
  return 0; // no error
1198
}
1199
 
1200
static s32 SEQ_UI_Button_Fast(s32 depressed)
1201
{
513 tk 1202
  if( seq_hwcfg_button_beh.fast ) {
1203
    // toggle mode
1204
    if( depressed ) return -1; // ignore when button depressed
1205
    seq_ui_button_state.FAST_ENCODERS ^= 1;
1206
  } else {
1207
    // set mode
1208
    seq_ui_button_state.FAST_ENCODERS = depressed ? 0 : 1;
1209
  }
134 tk 1210
 
178 tk 1211
  SEQ_UI_InitEncSpeed(0); // no auto config
1212
 
134 tk 1213
  return 0; // no error
1214
}
1215
 
1121 tk 1216
static s32 SEQ_UI_Button_Fast2(s32 depressed)
1217
{
1218
  if( seq_hwcfg_button_beh.fast2 ) {
1219
    // toggle mode
1220
    if( depressed ) return -1; // ignore when button depressed
1221
    seq_ui_button_state.FAST2_ENCODERS ^= 1;
1222
  } else {
1223
    // set mode
1224
    seq_ui_button_state.FAST2_ENCODERS = depressed ? 0 : 1;
1225
  }
1226
 
1227
  SEQ_UI_InitEncSpeed(0); // no auto config
1228
 
1229
  return 0; // no error
1230
}
1231
 
134 tk 1232
static s32 SEQ_UI_Button_All(s32 depressed)
1233
{
178 tk 1234
  seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE = depressed ? 0 : 1;
134 tk 1235
 
513 tk 1236
  if( seq_hwcfg_button_beh.all ) {
1237
    // toggle mode
1238
    if( depressed ) return -1;
1239
    seq_ui_button_state.CHANGE_ALL_STEPS ^= 1;
1240
  } else {
1241
    // set mode
1242
    seq_ui_button_state.CHANGE_ALL_STEPS = depressed ? 0 : 1;
1243
  }
178 tk 1244
 
134 tk 1245
  return 0; // no error
1246
}
1247
 
1248
static s32 SEQ_UI_Button_StepView(s32 depressed)
1249
{
600 tk 1250
  //  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1251
  // also used by seq_ui_stepsel
1252
 
513 tk 1253
  if( seq_hwcfg_button_beh.step_view ) {
1254
    if( depressed ) return -1; // ignore when button depressed
678 tk 1255
    if( !seq_ui_button_state.STEP_VIEW ) // due to page change: button going to be set, clear other toggle buttons
1256
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1257
    seq_ui_button_state.STEP_VIEW ^= 1; // toggle STEP_VIEW pressed (will also be released once GP button has been pressed)
1258
  } else {
1259
    // set mode
1260
    seq_ui_button_state.STEP_VIEW = depressed ? 0 : 1;
1261
  }
134 tk 1262
 
513 tk 1263
  if( seq_ui_button_state.STEP_VIEW ) {
600 tk 1264
    ui_stepview_prev_page = ui_page;
303 tk 1265
    SEQ_UI_PageSet(SEQ_UI_PAGE_STEPSEL);
1266
  } else {
524 tk 1267
    if( ui_page == SEQ_UI_PAGE_STEPSEL )
600 tk 1268
      SEQ_UI_PageSet(ui_stepview_prev_page);
303 tk 1269
  }
134 tk 1270
 
1271
  return 0; // no error
1272
}
1273
 
513 tk 1274
static s32 SEQ_UI_Button_TrackSel(s32 depressed)
134 tk 1275
{
513 tk 1276
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 1277
 
513 tk 1278
  if( seq_hwcfg_button_beh.track_sel ) {
1279
    if( depressed ) return -1; // ignore when button depressed
678 tk 1280
    if( !seq_ui_button_state.TRACK_SEL ) // due to page change: button going to be set, clear other toggle buttons
1281
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1282
    seq_ui_button_state.TRACK_SEL ^= 1; // toggle TRACKSEL status (will also be released once GP button has been pressed)
1283
  } else {
1284
    seq_ui_button_state.TRACK_SEL = depressed ? 0 : 1;
1285
  }
1286
 
1287
  if( seq_ui_button_state.TRACK_SEL ) {
1288
    prev_page = ui_page;
1289
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRACKSEL);
1290
  } else {
524 tk 1291
    if( ui_page == SEQ_UI_PAGE_TRACKSEL )
1292
      SEQ_UI_PageSet(prev_page);
513 tk 1293
  }
1294
 
134 tk 1295
  return 0; // no error
1296
}
1297
 
987 tk 1298
static s32 SEQ_UI_Button_Group(s32 depressed, u32 group)
1299
{
1300
  if( depressed ) return -1; // ignore when button depressed
1301
 
1302
  if( group >= 4 ) return -2; // max. 4 group buttons
1303
 
1304
  // in song page: track and group buttons are used to select the cursor position
1305
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1306
    ui_selected_item = 3 + group;
1307
    return 0;
1308
  }
1309
 
1310
  // if group has changed:
1311
  if( group != ui_selected_group ) {
1312
    // get current track selection
1313
    u16 old_tracks = ui_selected_tracks >> (4*ui_selected_group);
1314
 
1315
    // select new group
1316
    ui_selected_group = group;
1317
 
1318
    // take over old track selection
1319
    ui_selected_tracks = old_tracks << (4*ui_selected_group);
1320
  }
1321
 
1322
  // set/clear encoder fast function if required
1323
  SEQ_UI_InitEncSpeed(1); // auto config
1324
 
1325
  return 0; // no error
1326
}
1327
 
484 tk 1328
static s32 SEQ_UI_Button_Track(s32 depressed, u32 track_button)
134 tk 1329
{
484 tk 1330
  static u8 button_state = 0x0f; // all 4 buttons depressed
134 tk 1331
 
484 tk 1332
  if( track_button >= 4 ) return -2; // max. 4 track buttons
134 tk 1333
 
484 tk 1334
  if( depressed ) {
1335
    button_state |= (1 << track_button);
1336
    return 0; // no error
1337
  }
134 tk 1338
 
484 tk 1339
  button_state &= ~(1 << track_button);
1340
 
987 tk 1341
  // in pattern and song page: use track buttons as group buttons
1342
  if( ui_page == SEQ_UI_PAGE_PATTERN || ui_page == SEQ_UI_PAGE_SONG ) {
1343
    return SEQ_UI_Button_Group(depressed, track_button);
1344
  }
1345
 
484 tk 1346
  if( button_state == (~(1 << track_button) & 0xf) ) {
1347
    // if only one select button pressed: radio-button function (1 of 4)
1348
    ui_selected_tracks = 1 << (track_button + 4*ui_selected_group);
1349
  } else {
1350
    // if more than one select button pressed: toggle function (4 of 4)
1351
    ui_selected_tracks ^= 1 << (track_button + 4*ui_selected_group);
1352
  }
1353
 
178 tk 1354
  // set/clear encoder fast function if required
1355
  SEQ_UI_InitEncSpeed(1); // auto config
1356
 
134 tk 1357
  return 0; // no error
1358
}
1359
 
1146 tk 1360
static s32 SEQ_UI_Button_DirectTrack(s32 depressed, u32 track_button)
1361
{
1362
  static u16 button_state = 0xffff; // all 16 buttons depressed
1363
 
1364
  if( track_button >= 16 ) return -2; // max. 16 direct track buttons
1365
 
1366
  if( depressed ) {
1367
    button_state |= (1 << track_button);
1368
    return 0; // no error
1369
  }
1370
 
1371
  button_state &= ~(1 << track_button);
1372
 
1373
  if( button_state == (~(1 << track_button) & 0xffff) ) {
1374
    // if only one select button pressed: radio-button function (1 of 16)
1375
    ui_selected_tracks = 1 << track_button;
1488 tk 1376
    ui_selected_group = track_button / 4;
1146 tk 1377
  } else {
1378
    // if more than one select button pressed: toggle function (16 of 16)
1379
    ui_selected_tracks ^= 1 << track_button;
1380
  }
1381
 
1382
  // set/clear encoder fast function if required
1383
  SEQ_UI_InitEncSpeed(1); // auto config
1384
 
1385
  return 0; // no error
1386
}
1387
 
513 tk 1388
static s32 SEQ_UI_Button_ParLayerSel(s32 depressed)
1389
{
600 tk 1390
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1391
  // also used by seq_ui_parsel.c
513 tk 1392
 
1393
  if( seq_hwcfg_button_beh.par_layer ) {
1394
    if( depressed ) return -1; // ignore when button depressed
678 tk 1395
    if( !seq_ui_button_state.PAR_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1396
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1397
    seq_ui_button_state.PAR_LAYER_SEL ^= 1; // toggle PARSEL status (will also be released once GP button has been pressed)
1398
  } else {
1399
    seq_ui_button_state.PAR_LAYER_SEL = depressed ? 0 : 1;
1400
  }
1401
 
1402
  if( seq_ui_button_state.PAR_LAYER_SEL ) {
600 tk 1403
    ui_parlayer_prev_page = ui_page;
513 tk 1404
    SEQ_UI_PageSet(SEQ_UI_PAGE_PARSEL);
1405
  } else {
524 tk 1406
    if( ui_page == SEQ_UI_PAGE_PARSEL )
600 tk 1407
      SEQ_UI_PageSet(ui_parlayer_prev_page);
513 tk 1408
  }
1409
 
1410
  // set/clear encoder fast function if required
1411
  SEQ_UI_InitEncSpeed(1); // auto config
1412
 
1413
  return 0; // no error
1414
}
1415
 
134 tk 1416
static s32 SEQ_UI_Button_ParLayer(s32 depressed, u32 par_layer)
1417
{
1117 tk 1418
  static u8 layer_c_pressed = 0;
784 tk 1419
 
134 tk 1420
  if( par_layer >= 3 ) return -2; // max. 3 parlayer buttons
1421
 
1205 tk 1422
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1423
  u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1424
 
987 tk 1425
  // in song page: parameter layer buttons are used to select the cursor position
1426
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1427
    ui_selected_item = par_layer;
1428
    return 0;
1429
  }
1430
 
1205 tk 1431
  // drum mode in edit page: print parameter layer as long as button is pressed
1432
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1433
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1434
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1435
      ui_hold_msg_ctr = depressed ? 0 : ~0; // show value for at least 65 seconds... enough?
1436
    }
1437
  }
134 tk 1438
 
784 tk 1439
  // holding Layer C button allows to increment/decrement layer with A/B button
1440
  if( par_layer == 2 )
1441
    layer_c_pressed = !depressed;
1442
 
1443
  if( layer_c_pressed && par_layer == 0 ) {
333 tk 1444
    if( depressed ) return -1; // ignore when button depressed
784 tk 1445
    // increment layer
1446
    if( ++ui_selected_par_layer >= num_p_layers )
1447
      ui_selected_par_layer = 0;
1448
  } else if( layer_c_pressed && par_layer == 1 ) {
333 tk 1449
    if( depressed ) return -1; // ignore when button depressed
784 tk 1450
    // decrement layer
1451
    if( ui_selected_par_layer == 0 )
1452
      ui_selected_par_layer = num_p_layers - 1;
333 tk 1453
    else
784 tk 1454
      --ui_selected_par_layer;
333 tk 1455
  } else {
784 tk 1456
    if( num_p_layers <= 3 ) {
1457
      // 3 layers: direct selection with LayerA/B/C button
333 tk 1458
      if( depressed ) return -1; // ignore when button depressed
784 tk 1459
      if( par_layer >= num_p_layers ) {
1460
    char str1[21];
1461
    sprintf(str1, "Parameter Layer %c", 'A'+par_layer);
1462
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1463
      } else {
1464
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1465
    ui_selected_par_layer = par_layer;
1466
      }
1467
    } else if( num_p_layers <= 4 ) {
1468
      // 4 layers: LayerC Button toggles between C and D
1469
      if( depressed ) return -1; // ignore when button depressed
333 tk 1470
      seq_ui_button_state.PAR_LAYER_SEL = 0;
784 tk 1471
      if( par_layer == 2 )
1472
    ui_selected_par_layer = (ui_selected_par_layer == 2) ? 3 : 2;
1473
      else
1474
    ui_selected_par_layer = par_layer;
333 tk 1475
    } else {
784 tk 1476
      // >4 layers: LayerA/B button selects directly, Layer C button enters layer selection page
1477
      if( par_layer <= 1 ) {
1478
    if( depressed ) return -1; // ignore when button depressed
1479
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1480
    ui_selected_par_layer = par_layer;
1481
      } else {
1482
    return SEQ_UI_Button_ParLayerSel(depressed);
1483
      }
333 tk 1484
    }
1485
  }
1486
 
178 tk 1487
  // set/clear encoder fast function if required
1488
  SEQ_UI_InitEncSpeed(1); // auto config
1489
 
134 tk 1490
  return 0; // no error
1491
}
1492
 
513 tk 1493
static s32 SEQ_UI_Button_TrgLayerSel(s32 depressed)
1494
{
600 tk 1495
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1496
  // also used by seq_ui_trgsel.c
513 tk 1497
 
1498
  if( seq_hwcfg_button_beh.trg_layer ) {
1499
    if( depressed ) return -1; // ignore when button depressed
678 tk 1500
    if( !seq_ui_button_state.TRG_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1501
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1502
    seq_ui_button_state.TRG_LAYER_SEL ^= 1; // toggle TRGSEL status (will also be released once GP button has been pressed)
1503
  } else {
1504
    seq_ui_button_state.TRG_LAYER_SEL = depressed ? 0 : 1;
1505
  }
1506
 
1507
  if( seq_ui_button_state.TRG_LAYER_SEL ) {
600 tk 1508
    ui_trglayer_prev_page = ui_page;
513 tk 1509
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRGSEL);
1510
  } else {
524 tk 1511
    if( ui_page == SEQ_UI_PAGE_TRGSEL )
600 tk 1512
      SEQ_UI_PageSet(ui_trglayer_prev_page);
513 tk 1513
  }
1514
 
1515
  return 0; // no error
1516
}
1517
 
134 tk 1518
static s32 SEQ_UI_Button_TrgLayer(s32 depressed, u32 trg_layer)
1519
{
1117 tk 1520
  static u8 layer_c_pressed = 0;
784 tk 1521
 
134 tk 1522
  if( trg_layer >= 3 ) return -2; // max. 3 trglayer buttons
1523
 
326 tk 1524
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1525
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1526
  u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
134 tk 1527
 
1205 tk 1528
  // drum mode in edit page: ensure that trigger layer is print again
1529
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1530
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1531
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1532
      if( !depressed )
1533
    ui_hold_msg_ctr = 0;
1534
    }
1535
  }
1536
 
784 tk 1537
  // holding Layer C button allows to increment/decrement layer with A/B button
1538
  if( trg_layer == 2 )
1539
    layer_c_pressed = !depressed;
1540
 
1541
  if( layer_c_pressed && trg_layer == 0 ) {
326 tk 1542
    if( depressed ) return -1; // ignore when button depressed
784 tk 1543
    // increment layer
1544
    if( ++ui_selected_trg_layer >= num_t_layers )
1545
      ui_selected_trg_layer = 0;
1546
  } else if( layer_c_pressed && trg_layer == 1 ) {
326 tk 1547
    if( depressed ) return -1; // ignore when button depressed
784 tk 1548
    // decrement layer
1549
    if( ui_selected_trg_layer == 0 )
1550
      ui_selected_trg_layer = num_t_layers - 1;
326 tk 1551
    else
784 tk 1552
      --ui_selected_trg_layer;
326 tk 1553
  } else {
784 tk 1554
    if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 3 ) {
1555
      // 3 layers: direct selection with LayerA/B/C button
326 tk 1556
      if( depressed ) return -1; // ignore when button depressed
784 tk 1557
      if( trg_layer >= num_t_layers ) {
1558
    char str1[21];
1559
    sprintf(str1, "Trigger Layer %c", 'A'+trg_layer);
1560
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1561
      } else {
1562
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1563
    ui_selected_trg_layer = trg_layer;
1564
      }
1565
    } else if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 4 ) {
1566
      // 4 layers: LayerC Button toggles between C and D
1567
      if( depressed ) return -1; // ignore when button depressed
328 tk 1568
      seq_ui_button_state.TRG_LAYER_SEL = 0;
784 tk 1569
      if( trg_layer == 2 )
1570
    ui_selected_trg_layer = (ui_selected_trg_layer == 2) ? 3 : 2;
1571
      else
1572
    ui_selected_trg_layer = trg_layer;
326 tk 1573
    } else {
784 tk 1574
      // >4 layers or drum mode: LayerA/B button selects directly, Layer C button enters trigger selection page
1575
      // also used for drum tracks
1576
      if( trg_layer <= 1 ) {
1577
    if( depressed ) return -1; // ignore when button depressed
1578
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1579
    ui_selected_trg_layer = trg_layer;
1580
      } else {
1581
    return SEQ_UI_Button_TrgLayerSel(depressed);
1582
      }
326 tk 1583
    }
1584
  }
1585
 
134 tk 1586
  return 0; // no error
1587
}
1588
 
1589
 
1119 tk 1590
static s32 SEQ_UI_Button_Mixer(s32 depressed)
544 tk 1591
{
1592
  if( depressed ) return -1; // ignore when button depressed
134 tk 1593
 
1119 tk 1594
  SEQ_UI_PageSet(SEQ_UI_PAGE_MIXER);
544 tk 1595
 
1596
  return 0; // no error
1597
}
1598
 
1119 tk 1599
static s32 SEQ_UI_Button_TrackMode(s32 depressed)
544 tk 1600
{
1601
  if( depressed ) return -1; // ignore when button depressed
1602
 
1119 tk 1603
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMODE);
544 tk 1604
 
1605
  return 0; // no error
1606
}
1607
 
1119 tk 1608
static s32 SEQ_UI_Button_TrackGroove(s32 depressed)
544 tk 1609
{
1610
  if( depressed ) return -1; // ignore when button depressed
1611
 
1119 tk 1612
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKGRV);
1613
 
1614
  return 0; // no error
1615
}
1616
 
1617
static s32 SEQ_UI_Button_TrackLength(s32 depressed)
1618
{
1619
  if( depressed ) return -1; // ignore when button depressed
1620
 
1621
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKLEN);
1622
 
1623
  return 0; // no error
1624
}
1625
 
1626
static s32 SEQ_UI_Button_TrackDirection(s32 depressed)
1627
{
1628
  if( depressed ) return -1; // ignore when button depressed
1629
 
1630
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKDIR);
1631
 
1632
  return 0; // no error
1633
}
1634
 
1635
static s32 SEQ_UI_Button_TrackMorph(s32 depressed)
1636
{
1637
  if( depressed ) return -1; // ignore when button depressed
1638
 
1639
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMORPH);
1640
 
1641
  return 0; // no error
1642
}
1643
 
1644
static s32 SEQ_UI_Button_TrackTranspose(s32 depressed)
1645
{
1646
  if( depressed ) return -1; // ignore when button depressed
1647
 
544 tk 1648
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKTRAN);
1649
 
1650
  return 0; // no error
1651
}
1652
 
1653
 
742 tk 1654
// only used by keyboard remote function
1655
static s32 SEQ_UI_Button_ToggleGate(s32 depressed)
1656
{
1657
  if( depressed ) return -1; // ignore when button depressed
544 tk 1658
 
742 tk 1659
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1660
  u8 gate = SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? 0 : 1;
1661
  SEQ_TRG_GateSet(visible_track, ui_selected_step, ui_selected_instrument, gate);
544 tk 1662
 
742 tk 1663
  return 0; // no error
1664
}
1665
 
1349 tk 1666
static s32 SEQ_UI_Button_FootSwitch(s32 depressed)
1667
{
1668
  // static variables (only used here, therefore local)
1669
  static u32 fs_time_control = 0; // timestamp of last operation
1670
  static u8  fs_mode = 0; // mode
742 tk 1671
 
1349 tk 1672
  // this is used as a constant value
1673
  u32 fs_time_delay = 1000; // mS - should this be configurable?
742 tk 1674
 
1349 tk 1675
 
1676
  // PUNCH_IN, PUNCH_OUT and Delete track data control
1677
  if( !depressed ) {
1678
    if( ( fs_time_control > (seq_core_timestamp_ms - fs_time_delay) ) && ( fs_time_control != 0 ) )
1679
    {
1680
      // that confirms the delete function
1681
      fs_mode = 1; // delete
1682
    } else {
1683
      // start time in count
1684
      fs_time_control = seq_core_timestamp_ms;
1685
    }
1686
  } else {
1687
    // if time pressed is less than fs_time_delay miliseconds, we got a possible delete function activation
1688
    if( fs_time_control > (seq_core_timestamp_ms - fs_time_delay) )
1689
    {
1690
      switch( fs_mode ) {
1691
      case 1: { // delete
1692
        SEQ_UI_Button_Clear_Track(0);
1693
        fs_mode = 0; // back to normal mode, later we would increment the value
1694
      } break;
1695
      default:
1696
        fs_mode = 0; // for the case that an invalid mode is selected
1697
      }
1698
 
1699
      fs_time_control = seq_core_timestamp_ms;
1700
    }
1701
  }
1702
 
1703
  if( depressed ) {
1704
    // disable recording
1705
    seq_record_state.ENABLED = 0;
1706
  } else {
1707
    // enable recording
1708
    seq_record_state.ENABLED = 1;
1709
    seq_record_state.ARMED_TRACKS = ui_selected_tracks; // not used yet, just preparation for future changes
1710
  }
1711
 
1712
  return 0; // no error
1713
}
1714
 
1715
 
134 tk 1716
/////////////////////////////////////////////////////////////////////////////
1717
// Button handler
1718
/////////////////////////////////////////////////////////////////////////////
1719
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
1720
{
492 tk 1721
  int i;
1722
 
625 tk 1723
  // send MIDI event in remote mode and exit
1316 tk 1724
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 1725
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendButton(pin, pin_value);
1726
 
1044 tk 1727
  // ignore as long as hardware config hasn't been read
496 tk 1728
  if( !SEQ_FILE_HW_ConfigLocked() )
1729
    return -1;
1730
 
740 tk 1731
  // ignore during a backup or format is created
1732
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1733
    return -1;
1734
 
328 tk 1735
  // ensure that selections are matching with track constraints
1736
  SEQ_UI_CheckSelections();
1737
 
492 tk 1738
  // request display update
1739
  seq_ui_display_update_req = 1;
134 tk 1740
 
596 tk 1741
  // stop current message if (new) button has been pressed
1742
  if( pin_value == 0 )
1743
    SEQ_UI_MsgStop();
134 tk 1744
 
596 tk 1745
 
492 tk 1746
  // MEMO: we could also use a jump table with references to the functions
1747
  // here, but this "spagetthi code" simplifies the configuration and
1748
  // the resulting ASM doesn't look that bad!
168 tk 1749
 
492 tk 1750
  for(i=0; i<SEQ_HWCFG_NUM_GP; ++i)
1751
    if( pin == seq_hwcfg_button.gp[i] )
1752
      return SEQ_UI_Button_GP(pin_value, i);
134 tk 1753
 
492 tk 1754
  for(i=0; i<SEQ_HWCFG_NUM_TRACK; ++i)
1755
    if( pin == seq_hwcfg_button.track[i] )
1756
      return SEQ_UI_Button_Track(pin_value, i);
1146 tk 1757
 
1758
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_TRACK; ++i)
1759
    if( pin == seq_hwcfg_button.direct_track[i] )
1760
      return SEQ_UI_Button_DirectTrack(pin_value, i);
1761
 
1205 tk 1762
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_BOOKMARK; ++i)
1763
    if( pin == seq_hwcfg_button.direct_bookmark[i] )
1764
      return SEQ_UI_Button_DirectBookmark(pin_value, i);
1765
 
513 tk 1766
  if( pin == seq_hwcfg_button.track_sel )
1767
    return SEQ_UI_Button_TrackSel(pin_value);
134 tk 1768
 
492 tk 1769
  for(i=0; i<SEQ_HWCFG_NUM_GROUP; ++i)
1770
    if( pin == seq_hwcfg_button.group[i] )
1771
      return SEQ_UI_Button_Group(pin_value, i);
134 tk 1772
 
492 tk 1773
  for(i=0; i<SEQ_HWCFG_NUM_PAR_LAYER; ++i)
1774
    if( pin == seq_hwcfg_button.par_layer[i] )
1775
      return SEQ_UI_Button_ParLayer(pin_value, i);
513 tk 1776
  if( pin == seq_hwcfg_button.par_layer_sel )
1777
    return SEQ_UI_Button_ParLayerSel(pin_value);
134 tk 1778
 
492 tk 1779
  for(i=0; i<SEQ_HWCFG_NUM_TRG_LAYER; ++i)
1780
    if( pin == seq_hwcfg_button.trg_layer[i] )
1781
      return SEQ_UI_Button_TrgLayer(pin_value, i);
513 tk 1782
  if( pin == seq_hwcfg_button.trg_layer_sel )
1783
    return SEQ_UI_Button_TrgLayerSel(pin_value);
134 tk 1784
 
492 tk 1785
  if( pin == seq_hwcfg_button.left )
1786
    return SEQ_UI_Button_Left(pin_value);
1787
  if( pin == seq_hwcfg_button.right )
1788
    return SEQ_UI_Button_Right(pin_value);
1789
  if( pin == seq_hwcfg_button.down )
1790
    return SEQ_UI_Button_Down(pin_value);
1791
  if( pin == seq_hwcfg_button.up )
1792
    return SEQ_UI_Button_Up(pin_value);
134 tk 1793
 
492 tk 1794
  if( pin == seq_hwcfg_button.scrub )
1795
    return SEQ_UI_Button_Scrub(pin_value);
1796
  if( pin == seq_hwcfg_button.metronome )
1797
    return SEQ_UI_Button_Metronome(pin_value);
134 tk 1798
 
630 tk 1799
  if( pin == seq_hwcfg_button.record )
1800
    return SEQ_UI_Button_Record(pin_value);
1219 tk 1801
  if( pin == seq_hwcfg_button.live )
1802
    return SEQ_UI_Button_Live(pin_value);
630 tk 1803
 
492 tk 1804
  if( pin == seq_hwcfg_button.stop )
1805
    return SEQ_UI_Button_Stop(pin_value);
1806
  if( pin == seq_hwcfg_button.pause )
1807
    return SEQ_UI_Button_Pause(pin_value);
1808
  if( pin == seq_hwcfg_button.play )
1809
    return SEQ_UI_Button_Play(pin_value);
1810
  if( pin == seq_hwcfg_button.rew )
1811
    return SEQ_UI_Button_Rew(pin_value);
1812
  if( pin == seq_hwcfg_button.fwd )
1813
    return SEQ_UI_Button_Fwd(pin_value);
596 tk 1814
  if( pin == seq_hwcfg_button.loop )
1815
    return SEQ_UI_Button_Loop(pin_value);
973 tk 1816
  if( pin == seq_hwcfg_button.follow )
1817
    return SEQ_UI_Button_Follow(pin_value);
134 tk 1818
 
492 tk 1819
  if( pin == seq_hwcfg_button.utility )
1820
    return SEQ_UI_Button_Utility(pin_value);
1821
  if( pin == seq_hwcfg_button.copy )
1822
    return SEQ_UI_Button_Copy(pin_value);
1823
  if( pin == seq_hwcfg_button.paste )
1824
    return SEQ_UI_Button_Paste(pin_value);
1825
  if( pin == seq_hwcfg_button.clear )
1826
    return SEQ_UI_Button_Clear(pin_value);
1014 tk 1827
  if( pin == seq_hwcfg_button.undo )
1828
    return SEQ_UI_Button_Undo(pin_value);
134 tk 1829
 
492 tk 1830
  if( pin == seq_hwcfg_button.menu )
1831
    return SEQ_UI_Button_Menu(pin_value);
1203 tk 1832
  if( pin == seq_hwcfg_button.bookmark )
1833
    return SEQ_UI_Button_Bookmark(pin_value);
492 tk 1834
  if( pin == seq_hwcfg_button.select )
1835
    return SEQ_UI_Button_Select(pin_value);
1836
  if( pin == seq_hwcfg_button.exit )
1837
    return SEQ_UI_Button_Exit(pin_value);
134 tk 1838
 
513 tk 1839
  if( pin == seq_hwcfg_button.tap_tempo )
1840
    return SEQ_UI_Button_TapTempo(pin_value);
1841
  if( pin == seq_hwcfg_button.tempo_preset )
1842
    return SEQ_UI_Button_TempoPreset(pin_value);
524 tk 1843
  if( pin == seq_hwcfg_button.ext_restart )
1844
    return SEQ_UI_Button_ExtRestart(pin_value);
134 tk 1845
 
492 tk 1846
  if( pin == seq_hwcfg_button.edit )
1847
    return SEQ_UI_Button_Edit(pin_value);
1848
  if( pin == seq_hwcfg_button.mute )
1849
    return SEQ_UI_Button_Mute(pin_value);
1850
  if( pin == seq_hwcfg_button.pattern )
1851
    return SEQ_UI_Button_Pattern(pin_value);
1852
  if( pin == seq_hwcfg_button.song )
1853
    return SEQ_UI_Button_Song(pin_value);
134 tk 1854
 
492 tk 1855
  if( pin == seq_hwcfg_button.solo )
1856
    return SEQ_UI_Button_Solo(pin_value);
1857
  if( pin == seq_hwcfg_button.fast )
1858
    return SEQ_UI_Button_Fast(pin_value);
1121 tk 1859
  if( pin == seq_hwcfg_button.fast2 )
1860
    return SEQ_UI_Button_Fast2(pin_value);
492 tk 1861
  if( pin == seq_hwcfg_button.all )
1862
    return SEQ_UI_Button_All(pin_value);
134 tk 1863
 
492 tk 1864
  if( pin == seq_hwcfg_button.step_view )
1865
    return SEQ_UI_Button_StepView(pin_value);
134 tk 1866
 
544 tk 1867
  if( pin == seq_hwcfg_button.mixer )
1868
    return SEQ_UI_Button_Mixer(pin_value);
1869
 
1119 tk 1870
  if( pin == seq_hwcfg_button.track_mode )
1871
    return SEQ_UI_Button_TrackMode(pin_value);
1872
  if( pin == seq_hwcfg_button.track_groove )
1873
    return SEQ_UI_Button_TrackGroove(pin_value);
1874
  if( pin == seq_hwcfg_button.track_length )
1875
    return SEQ_UI_Button_TrackLength(pin_value);
1876
  if( pin == seq_hwcfg_button.track_direction )
1877
    return SEQ_UI_Button_TrackDirection(pin_value);
1878
  if( pin == seq_hwcfg_button.track_morph )
1879
    return SEQ_UI_Button_TrackMorph(pin_value);
1880
  if( pin == seq_hwcfg_button.track_transpose )
1881
    return SEQ_UI_Button_TrackTranspose(pin_value);
1349 tk 1882
  if( pin == seq_hwcfg_button.footswitch )
1883
    return SEQ_UI_Button_FootSwitch(pin_value);
1454 midilab 1884
  if( pin == seq_hwcfg_button.pattern_remix )
1885
    return SEQ_UI_Button_Pattern_Remix(pin_value);
625 tk 1886
  // always print debugging message
1887
#if 1
1081 tk 1888
  MUTEX_MIDIOUT_TAKE;
1889
  DEBUG_MSG("[SEQ_UI_Button_Handler] Button SR:%d, Pin:%d not mapped, it has been %s.\n",
1890
        (pin >> 3) + 1,
1891
        pin & 7,
1892
        pin_value ? "depressed" : "pressed");
1893
  MUTEX_MIDIOUT_GIVE;
625 tk 1894
#endif
1895
 
492 tk 1896
  return -1; // button not mapped
134 tk 1897
}
1898
 
1899
 
1900
/////////////////////////////////////////////////////////////////////////////
524 tk 1901
// BLM Button handler
1902
/////////////////////////////////////////////////////////////////////////////
1903
s32 SEQ_UI_BLM_Button_Handler(u32 row, u32 pin, u32 pin_value)
1904
{
625 tk 1905
  // send MIDI event in remote mode and exit
1316 tk 1906
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 1907
    return SEQ_MIDI_SYSEX_REMOTE_Client_Send_BLM_Button(row, pin, pin_value);
1908
 
1044 tk 1909
  // ignore as long as hardware config hasn't been read
524 tk 1910
  if( !SEQ_FILE_HW_ConfigLocked() )
1911
    return -1;
1912
 
740 tk 1913
  // ignore during a backup or format is created
1914
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1915
    return -1;
1916
 
524 tk 1917
  if( row >= SEQ_CORE_NUM_TRACKS_PER_GROUP )
1918
    return -1; // more than 4 tracks not supported (yet) - could be done in this function w/o much effort
1919
 
1920
  if( pin >= 16 )
1921
    return -1; // more than 16 step buttons not supported (yet) - could be done by selecting the step view
1922
 
1923
  // select track depending on row
1924
  ui_selected_tracks = 1 << (row + 4*ui_selected_group);
1925
 
1926
  // ensure that selections are matching with track constraints
1927
  SEQ_UI_CheckSelections();
1928
 
1929
  // request display update
1930
  seq_ui_display_update_req = 1;
1931
 
1932
  // emulate general purpose button
758 tk 1933
  if( seq_hwcfg_blm.buttons_no_ui ) {
763 tk 1934
    s32 status = SEQ_UI_EDIT_Button_Handler(pin, pin_value);
758 tk 1935
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1936
    return status;
763 tk 1937
  }
1938
 
1939
  return SEQ_UI_Button_GP(pin_value, pin); // no error, pin_value and pin are swapped for this function due to consistency reasons
524 tk 1940
}
1941
 
1942
 
1943
/////////////////////////////////////////////////////////////////////////////
134 tk 1944
// Encoder handler
1945
/////////////////////////////////////////////////////////////////////////////
1946
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
1947
{
625 tk 1948
  // send MIDI event in remote mode and exit
1316 tk 1949
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 1950
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendEncoder(encoder, incrementer);
1951
 
1044 tk 1952
  // ignore as long as hardware config hasn't been read
496 tk 1953
  if( !SEQ_FILE_HW_ConfigLocked() )
1954
    return -1;
1955
 
740 tk 1956
  // ignore during a backup or format is created
1957
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1958
    return -1;
1959
 
1341 tk 1960
  if( encoder >= SEQ_HWCFG_NUM_ENCODERS )
134 tk 1961
    return -1; // encoder doesn't exist
1962
 
328 tk 1963
  // ensure that selections are matching with track constraints
1964
  SEQ_UI_CheckSelections();
1965
 
596 tk 1966
  // stop current message
1967
  SEQ_UI_MsgStop();
1968
 
134 tk 1969
  // limit incrementer
1970
  if( incrementer > 3 )
1971
    incrementer = 3;
1972
  else if( incrementer < -3 )
1973
    incrementer = -3;
1974
 
1341 tk 1975
  // encoder 17 increments BPM
1976
  if( encoder == 17 ) {
1977
    u16 value = (u16)(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num]*10);
1978
    if( SEQ_UI_Var16_Inc(&value, 25, 3000, incrementer) ) { // at 384ppqn, the minimum BPM rate is ca. 2.5
1979
      // set new BPM
1980
      seq_core_bpm_preset_tempo[seq_core_bpm_preset_num] = (float)value/10.0;
1981
      SEQ_CORE_BPM_Update(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num], seq_core_bpm_preset_ramp[seq_core_bpm_preset_num]);
1982
      //store_file_required = 1;
1983
      seq_ui_display_update_req = 1;      
1984
    }
1985
    return 0;
1986
  }
1987
 
607 tk 1988
  if( seq_ui_button_state.SCRUB && encoder == 0 ) {
1989
    // if sequencer isn't already running, continue it (don't restart)
1990
    if( !SEQ_BPM_IsRunning() )
1991
      SEQ_BPM_Cont();
1992
    ui_seq_pause = 0; // clear pause mode
1278 tk 1993
 
607 tk 1994
    // Scrub sequence back or forth
1995
    portENTER_CRITICAL(); // should be atomic
1996
    SEQ_CORE_Scrub(incrementer);
1997
    portEXIT_CRITICAL();
1998
  } else if( !seq_ui_button_state.MENU_PRESSED && ui_encoder_callback != NULL ) {
173 tk 1999
    ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
740 tk 2000
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0; // ensure that value is visible when it has been changed
134 tk 2001
  }
2002
 
2003
  // request display update
159 tk 2004
  seq_ui_display_update_req = 1;
134 tk 2005
 
2006
  return 0; // no error
2007
}
2008
 
2009
 
353 tk 2010
 
134 tk 2011
/////////////////////////////////////////////////////////////////////////////
626 tk 2012
// Receives a MIDI package from APP_NotifyReceivedEvent (-> app.c)
2013
/////////////////////////////////////////////////////////////////////////////
2014
s32 SEQ_UI_REMOTE_MIDI_Receive(mios32_midi_port_t port, mios32_midi_package_t midi_package)
2015
{
2016
#if 1
2017
  // check for active remote mode
1316 tk 2018
  if( seq_midi_sysex_remote_active_mode != SEQ_MIDI_SYSEX_REMOTE_MODE_SERVER )
626 tk 2019
    return 0; // no error
2020
#endif
2021
 
1316 tk 2022
  if( (seq_midi_sysex_remote_port == DEFAULT && seq_midi_sysex_remote_active_port != port) ||
2023
      (seq_midi_sysex_remote_port != DEFAULT && port != seq_midi_sysex_remote_port) )
626 tk 2024
    return 0; // wrong port
2025
 
2026
  // for easier parsing: convert Note Off -> Note On with velocity 0
2027
  if( midi_package.event == NoteOff ) {
2028
    midi_package.event = NoteOn;
2029
    midi_package.velocity = 0;
2030
  }
2031
 
2032
  switch( midi_package.event ) {
2033
    case NoteOn: {
2034
      switch( midi_package.chn ) {
2035
        case Chn1:
2036
      SEQ_UI_Button_Handler(midi_package.note + 0x00, midi_package.velocity ? 0 : 1);
2037
      break;
2038
        case Chn2:
2039
      SEQ_UI_Button_Handler(midi_package.note + 0x80, midi_package.velocity ? 0 : 1);
2040
      break;
2041
        case Chn3:
2042
      SEQ_UI_BLM_Button_Handler(midi_package.note >> 5, midi_package.note & 0x1f, midi_package.velocity ? 0 : 1);
2043
      break;
2044
      }
2045
    } break;
2046
 
2047
    case CC: {
2048
      if( midi_package.cc_number >= 15 && midi_package.cc_number <= 31 )
2049
    SEQ_UI_Encoder_Handler(midi_package.cc_number-15, (int)midi_package.value - 0x40);
2050
    } break;
2051
  }
2052
 
632 tk 2053
  return 1; // MIDI event has been taken for remote function -> don't forward to router/MIDI event parser
626 tk 2054
}
2055
 
2056
 
2057
/////////////////////////////////////////////////////////////////////////////
741 tk 2058
// MIDI Remote Keyboard Function (called from SEQ_MIDI_IN)
2059
/////////////////////////////////////////////////////////////////////////////
742 tk 2060
s32 SEQ_UI_REMOTE_MIDI_Keyboard(u8 key, u8 depressed)
741 tk 2061
{
742 tk 2062
#if 0
1316 tk 2063
  MIOS32_MIDI_SendDebugMessage("SEQ_MIDI_SYSEX_REMOTE_MIDI_Keyboard(%d, %d)\n", key, depressed);
741 tk 2064
#endif
742 tk 2065
 
2066
  switch( key ) {
2067
    case 0x24: // C-2
2068
      return SEQ_UI_Button_GP(depressed, 0);
2069
    case 0x25: // C#2
2070
      return SEQ_UI_Button_Track(depressed, 0);
2071
    case 0x26: // D-2
2072
      return SEQ_UI_Button_GP(depressed, 1);
2073
    case 0x27: // D#2
2074
      return SEQ_UI_Button_Track(depressed, 1);
2075
    case 0x28: // E-2
2076
      return SEQ_UI_Button_GP(depressed, 2);
2077
    case 0x29: // F-2
2078
      return SEQ_UI_Button_GP(depressed, 3);
2079
    case 0x2a: // F#2
2080
      return SEQ_UI_Button_Track(depressed, 2);
2081
    case 0x2b: // G-2
2082
      return SEQ_UI_Button_GP(depressed, 4);
2083
    case 0x2c: // G#2
2084
      return SEQ_UI_Button_Track(depressed, 3);
2085
    case 0x2d: // A-2
2086
      return SEQ_UI_Button_GP(depressed, 5);
2087
    case 0x2e: // A#2
2088
      return SEQ_UI_Button_ParLayer(depressed, 0);
2089
    case 0x2f: // B-2
2090
      return SEQ_UI_Button_GP(depressed, 6);
2091
 
2092
    case 0x30: // C-3
2093
      return SEQ_UI_Button_GP(depressed, 7);
2094
    case 0x31: // C#3
2095
      return SEQ_UI_Button_ParLayer(depressed, 1);
2096
    case 0x32: // D-3
2097
      return SEQ_UI_Button_GP(depressed, 8);
2098
    case 0x33: // D#3
2099
      return SEQ_UI_Button_ParLayer(depressed, 2);
2100
    case 0x34: // E-3
2101
      return SEQ_UI_Button_GP(depressed, 9);
2102
    case 0x35: // F-3
2103
      return SEQ_UI_Button_GP(depressed, 10);
2104
    case 0x36: // F#3
2105
      return SEQ_UI_Button_TrgLayer(depressed, 0);
2106
    case 0x37: // G-3
2107
      return SEQ_UI_Button_GP(depressed, 11);
2108
    case 0x38: // G#3
2109
      return SEQ_UI_Button_TrgLayer(depressed, 1);
2110
    case 0x39: // A-3
2111
      return SEQ_UI_Button_GP(depressed, 12);
2112
    case 0x3a: // A#3
2113
      return SEQ_UI_Button_TrgLayer(depressed, 2);
2114
    case 0x3b: // B-3
2115
      return SEQ_UI_Button_GP(depressed, 13);
2116
 
2117
    case 0x3c: // C-4
2118
      return SEQ_UI_Button_GP(depressed, 14);
2119
    case 0x3d: // C#4
2120
      return SEQ_UI_Button_Group(depressed, 0);
2121
    case 0x3e: // D-4
2122
      return SEQ_UI_Button_GP(depressed, 15);
2123
    case 0x3f: // D#4
2124
      return SEQ_UI_Button_Group(depressed, 1);
2125
    case 0x40: // E-4
2126
      return 0; // ignore
2127
    case 0x41: // F-4
2128
      return SEQ_UI_Button_StepView(depressed);
2129
    case 0x42: // F#4
2130
      return SEQ_UI_Button_Group(depressed, 1);
2131
    case 0x43: // G-4
2132
      return 0; // ignore
2133
    case 0x44: // G#4
2134
      return SEQ_UI_Button_Group(depressed, 2);
2135
    case 0x45: // A-4
2136
      return SEQ_UI_Button_Left(depressed);
2137
    case 0x46: // A#4
2138
      return SEQ_UI_Button_ToggleGate(depressed);
2139
    case 0x47: // B-4
2140
      return SEQ_UI_Button_Right(depressed);
2141
 
2142
    case 0x48: // C-5
2143
      return SEQ_UI_Button_Edit(depressed);
2144
    case 0x49: // C#5
2145
      return SEQ_UI_Button_Solo(depressed);
2146
    case 0x4a: // D-5
2147
      return SEQ_UI_Button_Mute(depressed);
2148
    case 0x4b: // D#5
2149
      return SEQ_UI_Button_All(depressed);
2150
    case 0x4c: // E-5
2151
      return SEQ_UI_Button_Pattern(depressed);
2152
    case 0x4d: // F-5
2153
      return SEQ_UI_Button_Song(depressed);
2154
    case 0x4e: // F#5
2155
      return SEQ_UI_Button_Fast(depressed);
2156
    case 0x4f: // G-5
2157
      return SEQ_UI_Button_Metronome(depressed);
2158
    case 0x50: // G#5
2159
      return SEQ_UI_Button_ExtRestart(depressed);
2160
    case 0x51: // A-5
2161
      return SEQ_UI_Button_ParLayerSel(depressed);
2162
    case 0x52: // A#5
2163
      return SEQ_UI_Button_TrackSel(depressed);
2164
    case 0x53: // B-5
2165
      return SEQ_UI_Button_Stop(depressed);
2166
 
2167
    case 0x54: // C-6
2168
      return SEQ_UI_Button_Play(depressed);
2169
    case 0x55: // C#6
2170
      return SEQ_UI_Button_Pause(depressed);
2171
    case 0x56: // D-6
2172
      return SEQ_UI_Button_Rew(depressed);
2173
    case 0x57: // D#6
2174
      return SEQ_UI_Button_Fwd(depressed);
2175
    case 0x58: // E-6
2176
      return SEQ_UI_Button_Utility(depressed);
2177
    case 0x59: // F-6
2178
      return SEQ_UI_Button_TempoPreset(depressed);
2179
    case 0x5a: // F#6
2180
      return 0; // ignore
2181
    case 0x5b: // G-6
2182
      return SEQ_UI_Button_Menu(depressed);
2183
    case 0x5c: // G#6
2184
      return SEQ_UI_Button_Select(depressed);
2185
    case 0x5d: // A-6
2186
      return SEQ_UI_Button_Exit(depressed);
2187
    case 0x5e: // A#6
2188
      return SEQ_UI_Button_Down(depressed);
2189
    case 0x5f: // B-6
2190
      return SEQ_UI_Button_Up(depressed);
2191
  }
2192
 
741 tk 2193
  return 0; // no error
2194
}
2195
 
2196
 
2197
/////////////////////////////////////////////////////////////////////////////
134 tk 2198
// Update LCD messages
2199
// Usually called from background task
2200
/////////////////////////////////////////////////////////////////////////////
2201
s32 SEQ_UI_LCD_Handler(void)
2202
{
728 tk 2203
  static u8 boot_animation_wait_ctr = 0;
2204
  static u8 boot_animation_lcd_pos = 0;
2205
 
625 tk 2206
  // special handling in remote client mode
1316 tk 2207
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2208
    return SEQ_UI_LCD_Update();
2209
 
159 tk 2210
  if( seq_ui_display_init_req ) {
2211
    seq_ui_display_init_req = 0; // clear request
134 tk 2212
 
278 tk 2213
    // clear force update of LCD
2214
    SEQ_LCD_Clear();
2215
    SEQ_LCD_Update(1);
134 tk 2216
 
168 tk 2217
    // select first menu item
2218
    ui_selected_item = 0;
2219
 
167 tk 2220
    // call init function of current page
272 tk 2221
    if( ui_menu_pages[ui_page].init_callback != NULL )
2222
      ui_menu_pages[ui_page].init_callback(0); // mode
134 tk 2223
 
2224
    // request display update
159 tk 2225
    seq_ui_display_update_req = 1;
134 tk 2226
  }
2227
 
1044 tk 2228
  // print boot screen as long as hardware config hasn't been read
496 tk 2229
  if( !SEQ_FILE_HW_ConfigLocked() ) {
728 tk 2230
    if( boot_animation_lcd_pos < (40-3) ) {
2231
      if( ++boot_animation_wait_ctr >= 75 ) {
2232
    boot_animation_wait_ctr = 0;
637 tk 2233
 
728 tk 2234
    if( boot_animation_lcd_pos == 0 ) {
2235
      SEQ_LCD_Clear();
2236
      SEQ_LCD_CursorSet(0, 0);
2237
      SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE1 " " MIOS32_LCD_BOOT_MSG_LINE2);
2238
      SEQ_LCD_CursorSet(0, 1);
2239
      SEQ_LCD_PrintString("Searching for SD Card...");
2240
    }
2241
 
2242
    // logo is print on second LCD
2243
    SEQ_LCD_LOGO_Print(boot_animation_lcd_pos++);
2244
      }
2245
    }
740 tk 2246
  } else if( seq_ui_backup_req || seq_ui_format_req ) {
634 tk 2247
    SEQ_LCD_Clear();
2248
    SEQ_LCD_CursorSet(0, 0);
740 tk 2249
    //                     <-------------------------------------->
2250
    //                     0123456789012345678901234567890123456789
2251
    if( seq_ui_backup_req )
959 tk 2252
      SEQ_LCD_PrintString("Copy Files - be patient!!!");
740 tk 2253
    else if( seq_ui_format_req )
959 tk 2254
      SEQ_LCD_PrintString("Creating Files - be patient!!!");
740 tk 2255
    else
2256
      SEQ_LCD_PrintString("Don't know what I'm doing! :-/");
637 tk 2257
 
2258
    if( seq_file_backup_notification != NULL ) {
2259
      int i;
2260
 
2261
      SEQ_LCD_CursorSet(0, 1);
959 tk 2262
      SEQ_LCD_PrintFormattedString("Creating %s", seq_file_backup_notification);
637 tk 2263
 
2264
      SEQ_LCD_CursorSet(40+3, 0);
2265
      SEQ_LCD_PrintString("Total: [");
2266
      for(i=0; i<20; ++i)
2267
    SEQ_LCD_PrintChar((i>(seq_file_backup_percentage/5)) ? ' ' : '#');
2268
      SEQ_LCD_PrintFormattedString("] %3d%%", seq_file_backup_percentage);
2269
 
2270
      SEQ_LCD_CursorSet(40+3, 1);
2271
      SEQ_LCD_PrintString("File:  [");
2272
      for(i=0; i<20; ++i)
1261 tk 2273
    SEQ_LCD_PrintChar((i>(file_copy_percentage/5)) ? ' ' : '#');
2274
      SEQ_LCD_PrintFormattedString("] %3d%%", file_copy_percentage);
637 tk 2275
    }
2276
 
496 tk 2277
  } else if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
2278
    SEQ_LCD_CursorSet(0, 0);
2279
    //                   <-------------------------------------->
2280
    //                   0123456789012345678901234567890123456789
306 tk 2281
    SEQ_LCD_PrintString("Menu Shortcuts:");
2282
    SEQ_LCD_PrintSpaces(25 + 40);
2283
    SEQ_LCD_CursorSet(0, 1);
2284
    SEQ_LCD_PrintString(UI_SHORTCUT_STR); // defined in seq_ui_pages.inc
2285
  } else {
2286
    // perform high priority LCD update request
2287
    if( ui_lcd_callback != NULL )
2288
      ui_lcd_callback(1); // high_prio
167 tk 2289
 
306 tk 2290
    // perform low priority LCD update request if requested
2291
    if( seq_ui_display_update_req ) {
2292
      seq_ui_display_update_req = 0; // clear request
328 tk 2293
 
2294
      // ensure that selections are matching with track constraints
2295
      SEQ_UI_CheckSelections();
2296
 
306 tk 2297
      if( ui_lcd_callback != NULL )
2298
    ui_lcd_callback(0); // no high_prio
2299
    }
134 tk 2300
  }
2301
 
353 tk 2302
  // transfer all changed characters to LCD
2303
  SEQ_UI_LCD_Update();
2304
 
2305
  return 0; // no error
2306
}
2307
 
2308
 
2309
/////////////////////////////////////////////////////////////////////////////
2310
// Called from SEQ_UI_LCD_Handler(), but optionally also from other tasks
2311
// to update the LCD screen immediately
2312
/////////////////////////////////////////////////////////////////////////////
1117 tk 2313
// for newer GCC versions it's important to declare constant arrays outside a function
2314
//                                             00112233
2315
static const char animation_l_arrows[2*4+1] = "   >>>> ";
2316
//                                             00112233
2317
static const char animation_r_arrows[2*4+1] = "  < << <";
2318
//                                               00112233
2319
static const char animation_l_brackets[2*4+1] = "   )))) ";
2320
//                                               00112233
2321
static const char animation_r_brackets[2*4+1] = "  ( (( (";
2322
//                                            00112233
2323
static const char animation_l_stars[2*4+1] = "   **** ";
2324
//                                            00112233
2325
static const char animation_r_stars[2*4+1] = "  * ** *";
353 tk 2326
s32 SEQ_UI_LCD_Update(void)
2327
{
625 tk 2328
  // special handling in remote client mode
1316 tk 2329
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT ) {
626 tk 2330
    MIOS32_IRQ_Disable();
1316 tk 2331
    u8 force = seq_midi_sysex_remote_force_lcd_update;
2332
    seq_midi_sysex_remote_force_lcd_update = 0;
626 tk 2333
    MIOS32_IRQ_Enable();
2334
    return SEQ_LCD_Update(force);
625 tk 2335
  }
2336
 
596 tk 2337
  // if UI message active: copy over the text
2338
  if( ui_msg_ctr ) {
774 tk 2339
    char *animation_l_ptr;
2340
    char *animation_r_ptr;
596 tk 2341
    u8 msg_x = 0;
2342
    u8 right_aligned = 0;
740 tk 2343
    u8 disable_message = 0;
299 tk 2344
 
596 tk 2345
    switch( ui_msg_type ) {
2346
      case SEQ_UI_MSG_SDCARD: {
1117 tk 2347
    animation_l_ptr = (char *)animation_l_arrows;
2348
    animation_r_ptr = (char *)animation_r_arrows;
596 tk 2349
    msg_x = 0; // MEMO: print such important information at first LCD for the case the user hasn't connected the second LCD yet
2350
    right_aligned = 0;
2351
      } break;
2352
 
756 tk 2353
      case SEQ_UI_MSG_DELAYED_ACTION:
2354
      case SEQ_UI_MSG_DELAYED_ACTION_R: {
1117 tk 2355
    animation_l_ptr = (char *)animation_l_brackets;
2356
    animation_r_ptr = (char *)animation_r_brackets;
756 tk 2357
    if( ui_msg_type == SEQ_UI_MSG_DELAYED_ACTION_R ) {
2358
      msg_x = 40; // right LCD
2359
      right_aligned = 0;
2360
    } else {
2361
      msg_x = 39; // left LCD
2362
      right_aligned = 1;
2363
    }
740 tk 2364
 
2365
    if( ui_delayed_action_callback == NULL ) {
2366
      disable_message = 1; // button has been depressed before delay
2367
    } else {
2368
      int seconds = (ui_delayed_action_ctr / 1000) + 1;
2369
      if( seconds == 1 )
2370
        sprintf(ui_msg[0], "Hold for 1 second ");
2371
      else
2372
        sprintf(ui_msg[0], "Hold for %d seconds", seconds);
2373
    }
2374
      } break;
2375
 
741 tk 2376
      case SEQ_UI_MSG_USER_R: {
1117 tk 2377
    animation_l_ptr = (char *)animation_l_stars;
2378
    animation_r_ptr = (char *)animation_r_stars;
741 tk 2379
    msg_x = 40; // right display
2380
    right_aligned = 0;
2381
      } break;
2382
 
596 tk 2383
      default: {
1117 tk 2384
    animation_l_ptr = (char *)animation_l_stars;
2385
    animation_r_ptr = (char *)animation_r_stars;
596 tk 2386
    msg_x = 39;
2387
    right_aligned = 1;
2388
      } break;
2389
 
2390
    }
2391
 
740 tk 2392
    if( !disable_message ) {
2393
      int anum = (ui_msg_ctr % 1000) / 250;
596 tk 2394
 
740 tk 2395
      int len[2];
2396
      len[0] = strlen((char *)ui_msg[0]);
2397
      len[1] = strlen((char *)ui_msg[1]);
2398
      int len_max = len[0];
2399
      if( len[1] > len_max )
2400
    len_max = len[1];
596 tk 2401
 
740 tk 2402
      if( right_aligned )
2403
    msg_x -= (9 + len_max);
596 tk 2404
 
740 tk 2405
      int line;
2406
      for(line=0; line<2; ++line) {
2407
    SEQ_LCD_CursorSet(msg_x, line);
596 tk 2408
 
740 tk 2409
    // ensure that both lines are padded with same number of spaces
2410
    int end_pos = len[line];
2411
    while( end_pos < len_max )
2412
      ui_msg[line][end_pos++] = ' ';
2413
    ui_msg[line][end_pos] = 0;
2414
 
2415
    SEQ_LCD_PrintFormattedString(" %c%c| %s |%c%c ",
2416
                     *(animation_l_ptr + 2*anum + 0), *(animation_l_ptr + 2*anum + 1),
2417
                     (char *)ui_msg[line],
2418
                     *(animation_r_ptr + 2*anum + 0), *(animation_r_ptr + 2*anum + 1));
2419
      }
299 tk 2420
    }
2421
  }
2422
 
637 tk 2423
  // MSD USB notification at right corner if not in Disk page
2424
  // to warn user that USB MIDI is disabled and seq performance is bad now!
638 tk 2425
  if( (TASK_MSD_EnableGet() > 0) && ui_page != SEQ_UI_PAGE_DISK ) {
637 tk 2426
    SEQ_LCD_CursorSet(80-11, 0);
2427
    if( ui_cursor_flash ) SEQ_LCD_PrintSpaces(13); else SEQ_LCD_PrintString(" [MSD USB] ");
2428
    SEQ_LCD_CursorSet(80-11, 1);
2429
    char str[5];
2430
    TASK_MSD_FlagStrGet(str);
2431
    if( ui_cursor_flash ) SEQ_LCD_PrintSpaces(13); else SEQ_LCD_PrintFormattedString(" [ %s  ] ", str);
2432
  }
596 tk 2433
 
278 tk 2434
  // transfer all changed characters to LCD
353 tk 2435
  // SEQ_LCD_Update provides a MUTEX handling to allow updates from different tasks
2436
  return SEQ_LCD_Update(0);
134 tk 2437
}
2438
 
2439
 
2440
/////////////////////////////////////////////////////////////////////////////
2441
// Update all LEDs
2442
// Usually called from background task
2443
/////////////////////////////////////////////////////////////////////////////
2444
s32 SEQ_UI_LED_Handler(void)
2445
{
626 tk 2446
  static u8 remote_led_sr[SEQ_LED_NUM_SR];
2447
 
625 tk 2448
  // ignore in remote client mode
1316 tk 2449
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2450
    return 0; // no error
2451
 
1044 tk 2452
  // ignore as long as hardware config hasn't been read
496 tk 2453
  if( !SEQ_FILE_HW_ConfigLocked() )
2454
    return -1;
2455
 
134 tk 2456
  // track LEDs
987 tk 2457
  // in pattern page: track buttons are used as group buttons
2458
  if( ui_page == SEQ_UI_PAGE_PATTERN ) {
2459
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (ui_selected_group == 0));
2460
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (ui_selected_group == 1));
2461
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (ui_selected_group == 2));
2462
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (ui_selected_group == 3));
2463
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
2464
    // in song page: track and group buttons are used to select the cursor position
2465
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (ui_selected_item == 3));
2466
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (ui_selected_item == 4));
2467
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (ui_selected_item == 5));
2468
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (ui_selected_item == 6));
2469
  } else {
2470
    u8 selected_tracks = ui_selected_tracks >> (4*ui_selected_group);
2471
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (selected_tracks & (1 << 0)));
2472
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (selected_tracks & (1 << 1)));
2473
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (selected_tracks & (1 << 2)));
2474
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (selected_tracks & (1 << 3)));
2475
  }
2476
 
678 tk 2477
  SEQ_LED_PinSet(seq_hwcfg_led.track_sel, ui_page == SEQ_UI_PAGE_TRACKSEL);
134 tk 2478
 
2479
  // parameter layer LEDs
987 tk 2480
  // in song page: layer buttons are used to select the cursor position
2481
  if( ui_page == SEQ_UI_PAGE_SONG ) {
2482
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], ui_selected_item == 0);
2483
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], ui_selected_item == 1);
2484
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], ui_selected_item == 2);
2485
  } else {
2486
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], (ui_selected_par_layer == 0));
2487
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], (ui_selected_par_layer == 1));
2488
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], (ui_selected_par_layer >= 2) || seq_ui_button_state.PAR_LAYER_SEL);
2489
  }
678 tk 2490
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer_sel, ui_page == SEQ_UI_PAGE_PARSEL);
134 tk 2491
 
2492
  // group LEDs
987 tk 2493
  // in song page: track and group buttons are used to select the cursor position
2494
  if( ui_page == SEQ_UI_PAGE_SONG ) {
2495
    SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_item == 3));
2496
    SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_item == 4));
2497
    SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_item == 5));
2498
    SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_item == 6));
2499
  } else {
2500
    SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_group == 0));
2501
    SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_group == 1));
2502
    SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_group == 2));
2503
    SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_group == 3));
2504
  }
134 tk 2505
 
2506
  // trigger layer LEDs
492 tk 2507
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[0], (ui_selected_trg_layer == 0));
2508
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[1], (ui_selected_trg_layer == 1));
2509
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[2], (ui_selected_trg_layer >= 2) || seq_ui_button_state.TRG_LAYER_SEL);
678 tk 2510
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer_sel, ui_page == SEQ_UI_PAGE_TRGSEL);
134 tk 2511
 
2512
  // remaining LEDs
492 tk 2513
  SEQ_LED_PinSet(seq_hwcfg_led.edit, ui_page == SEQ_UI_PAGE_EDIT);
2514
  SEQ_LED_PinSet(seq_hwcfg_led.mute, ui_page == SEQ_UI_PAGE_MUTE);
2515
  SEQ_LED_PinSet(seq_hwcfg_led.pattern, ui_page == SEQ_UI_PAGE_PATTERN);
399 tk 2516
  if( SEQ_SONG_ActiveGet() )
492 tk 2517
    SEQ_LED_PinSet(seq_hwcfg_led.song, 1);
399 tk 2518
  else
492 tk 2519
    SEQ_LED_PinSet(seq_hwcfg_led.song, ui_cursor_flash ? 0 : (ui_page == SEQ_UI_PAGE_SONG));
743 tk 2520
  SEQ_LED_PinSet(seq_hwcfg_led.mixer, ui_page == SEQ_UI_PAGE_MIXER);
1119 tk 2521
 
2522
  SEQ_LED_PinSet(seq_hwcfg_led.track_mode, ui_page == SEQ_UI_PAGE_TRKMODE);
2523
  SEQ_LED_PinSet(seq_hwcfg_led.track_groove, ui_page == SEQ_UI_PAGE_TRKGRV);
2524
  SEQ_LED_PinSet(seq_hwcfg_led.track_length, ui_page == SEQ_UI_PAGE_TRKLEN);
2525
  SEQ_LED_PinSet(seq_hwcfg_led.track_direction, ui_page == SEQ_UI_PAGE_TRKDIR);
2526
  SEQ_LED_PinSet(seq_hwcfg_led.track_morph, ui_page == SEQ_UI_PAGE_TRKMORPH);
2527
  SEQ_LED_PinSet(seq_hwcfg_led.track_transpose, ui_page == SEQ_UI_PAGE_TRKTRAN);
134 tk 2528
 
492 tk 2529
  SEQ_LED_PinSet(seq_hwcfg_led.solo, seq_ui_button_state.SOLO);
2530
  SEQ_LED_PinSet(seq_hwcfg_led.fast, seq_ui_button_state.FAST_ENCODERS);
1121 tk 2531
  SEQ_LED_PinSet(seq_hwcfg_led.fast2, seq_ui_button_state.FAST2_ENCODERS);
492 tk 2532
  SEQ_LED_PinSet(seq_hwcfg_led.all, seq_ui_button_state.CHANGE_ALL_STEPS);
134 tk 2533
 
1206 tk 2534
  u8 seq_running = SEQ_BPM_IsRunning() && (!seq_core_slaveclk_mute || ((seq_core_state.ref_step & 3) == 0));
2535
  // note: no bug: we added check for ref_step&3 for flashing the LEDs to give a sign of activity in slave mode with slaveclk_muted
2536
  SEQ_LED_PinSet(seq_hwcfg_led.play, seq_running);
2537
  SEQ_LED_PinSet(seq_hwcfg_led.stop, !seq_running && !ui_seq_pause);
2538
  SEQ_LED_PinSet(seq_hwcfg_led.pause, ui_seq_pause && (!seq_core_slaveclk_mute || ui_cursor_flash));
240 tk 2539
 
492 tk 2540
  SEQ_LED_PinSet(seq_hwcfg_led.rew, seq_ui_button_state.REW);
2541
  SEQ_LED_PinSet(seq_hwcfg_led.fwd, seq_ui_button_state.FWD);
596 tk 2542
 
2543
  SEQ_LED_PinSet(seq_hwcfg_led.loop, seq_core_state.LOOP);
951 tk 2544
  SEQ_LED_PinSet(seq_hwcfg_led.follow, seq_core_state.FOLLOW);
134 tk 2545
 
678 tk 2546
  SEQ_LED_PinSet(seq_hwcfg_led.step_view, ui_page == SEQ_UI_PAGE_STEPSEL);
134 tk 2547
 
591 tk 2548
  SEQ_LED_PinSet(seq_hwcfg_led.select, seq_ui_button_state.SELECT_PRESSED);
492 tk 2549
  SEQ_LED_PinSet(seq_hwcfg_led.menu, seq_ui_button_state.MENU_PRESSED);
1203 tk 2550
  SEQ_LED_PinSet(seq_hwcfg_led.bookmark, ui_page == SEQ_UI_PAGE_BOOKMARKS);
134 tk 2551
 
596 tk 2552
  // handle double functions
2553
  if( seq_ui_button_state.MENU_PRESSED ) {
2554
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_core_state.LOOP);
951 tk 2555
    SEQ_LED_PinSet(seq_hwcfg_led.exit, seq_core_state.FOLLOW);
596 tk 2556
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.EXT_RESTART_REQ);
2557
  } else {
2558
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_ui_button_state.SCRUB);
951 tk 2559
    SEQ_LED_PinSet(seq_hwcfg_led.exit, ui_page == SEQ_UI_PAGE_MENU);
596 tk 2560
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.METRONOME);
2561
  }
2562
 
1313 tk 2563
  SEQ_LED_PinSet(seq_hwcfg_led.record, seq_record_state.ENABLED);
1219 tk 2564
  SEQ_LED_PinSet(seq_hwcfg_led.live, ui_page == SEQ_UI_PAGE_TRKLIVE);
630 tk 2565
 
492 tk 2566
  SEQ_LED_PinSet(seq_hwcfg_led.utility, ui_page == SEQ_UI_PAGE_UTIL);
2567
  SEQ_LED_PinSet(seq_hwcfg_led.copy, seq_ui_button_state.COPY);
2568
  SEQ_LED_PinSet(seq_hwcfg_led.paste, seq_ui_button_state.PASTE);
1014 tk 2569
  SEQ_LED_PinSet(seq_hwcfg_led.undo, seq_ui_button_state.UNDO);
492 tk 2570
  SEQ_LED_PinSet(seq_hwcfg_led.clear, seq_ui_button_state.CLEAR);
240 tk 2571
 
513 tk 2572
  SEQ_LED_PinSet(seq_hwcfg_led.tap_tempo, seq_ui_button_state.TAP_TEMPO);
678 tk 2573
  SEQ_LED_PinSet(seq_hwcfg_led.tempo_preset, ui_page == SEQ_UI_PAGE_BPM_PRESETS);
524 tk 2574
  SEQ_LED_PinSet(seq_hwcfg_led.ext_restart, seq_core_state.EXT_RESTART_REQ);
240 tk 2575
 
492 tk 2576
  SEQ_LED_PinSet(seq_hwcfg_led.down, seq_ui_button_state.DOWN);
2577
  SEQ_LED_PinSet(seq_hwcfg_led.up, seq_ui_button_state.UP);
240 tk 2578
 
167 tk 2579
 
1044 tk 2580
  // in MENU page: overrule GP LEDs as long as MENU button is pressed/active
306 tk 2581
  if( seq_ui_button_state.MENU_PRESSED ) {
2582
    if( ui_cursor_flash ) // if flashing flag active: no LED flag set
2583
      ui_gp_leds = 0x0000;
2584
    else {
2585
      int i;
2586
      u16 new_ui_gp_leds = 0x0000;
2587
      for(i=0; i<16; ++i)
2588
    if( ui_page == ui_shortcut_menu_pages[i] )
2589
      new_ui_gp_leds |= (1 << i);
2590
      ui_gp_leds = new_ui_gp_leds;
2591
    }
2592
  } else {
2593
    // note: the background function is permanently interrupted - therefore we write the GP pattern
2594
    // into a temporary variable, and take it over once completed
2595
    u16 new_ui_gp_leds = 0x0000;
2596
    // request GP LED values from current menu page
2597
    // will be transfered to DOUT registers in SEQ_UI_LED_Handler_Periodic
2598
    new_ui_gp_leds = 0x0000;
206 tk 2599
 
306 tk 2600
    if( ui_led_callback != NULL )
2601
      ui_led_callback(&new_ui_gp_leds);
167 tk 2602
 
306 tk 2603
    ui_gp_leds = new_ui_gp_leds;
2604
  }
2605
 
1020 tk 2606
  // update BLM LEDs
2607
  SEQ_BLM_LED_Update();
524 tk 2608
 
626 tk 2609
  // send LED changes in remote server mode
1316 tk 2610
  if( seq_midi_sysex_remote_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_SERVER || seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_SERVER ) {
626 tk 2611
    int first_sr = -1;
2612
    int last_sr = -1;
2613
    int sr;
2614
    for(sr=0; sr<SEQ_LED_NUM_SR; ++sr) {
2615
      u8 value = SEQ_LED_SRGet(sr);
2616
      if( value != remote_led_sr[sr] ) {
2617
    if( first_sr == -1 )
2618
      first_sr = sr;
2619
    last_sr = sr;
2620
    remote_led_sr[sr] = value;
2621
      }
2622
    }
2623
 
2624
    MIOS32_IRQ_Disable();
1316 tk 2625
    if( seq_midi_sysex_remote_force_led_update ) {
626 tk 2626
      first_sr = 0;
2627
      last_sr = SEQ_LED_NUM_SR-1;
2628
    }
1316 tk 2629
    seq_midi_sysex_remote_force_led_update = 0;
626 tk 2630
    MIOS32_IRQ_Enable();
2631
 
2632
    if( first_sr >= 0 )
2633
      SEQ_MIDI_SYSEX_REMOTE_Server_SendLED(first_sr, (u8 *)&remote_led_sr[first_sr], last_sr-first_sr+1);
2634
  }
2635
 
2636
 
134 tk 2637
  return 0; // no error
2638
}
2639
 
2640
 
2641
/////////////////////////////////////////////////////////////////////////////
2642
// updates high-prio LED functions (GP LEDs and Beat LED)
168 tk 2643
// called each mS
134 tk 2644
/////////////////////////////////////////////////////////////////////////////
2645
s32 SEQ_UI_LED_Handler_Periodic()
2646
{
625 tk 2647
  // ignore in remote client mode
1316 tk 2648
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2649
    return 0; // no error
2650
 
1044 tk 2651
  // ig