Subversion Repositories svn.mios32

Rev

Rev 1422 | Rev 1488 | 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 1454 2012-04-03 22:54:57Z midilab $
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;
1376
  } else {
1377
    // if more than one select button pressed: toggle function (16 of 16)
1378
    ui_selected_tracks ^= 1 << track_button;
1379
  }
1380
 
1381
  // set/clear encoder fast function if required
1382
  SEQ_UI_InitEncSpeed(1); // auto config
1383
 
1384
  return 0; // no error
1385
}
1386
 
513 tk 1387
static s32 SEQ_UI_Button_ParLayerSel(s32 depressed)
1388
{
600 tk 1389
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1390
  // also used by seq_ui_parsel.c
513 tk 1391
 
1392
  if( seq_hwcfg_button_beh.par_layer ) {
1393
    if( depressed ) return -1; // ignore when button depressed
678 tk 1394
    if( !seq_ui_button_state.PAR_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1395
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1396
    seq_ui_button_state.PAR_LAYER_SEL ^= 1; // toggle PARSEL status (will also be released once GP button has been pressed)
1397
  } else {
1398
    seq_ui_button_state.PAR_LAYER_SEL = depressed ? 0 : 1;
1399
  }
1400
 
1401
  if( seq_ui_button_state.PAR_LAYER_SEL ) {
600 tk 1402
    ui_parlayer_prev_page = ui_page;
513 tk 1403
    SEQ_UI_PageSet(SEQ_UI_PAGE_PARSEL);
1404
  } else {
524 tk 1405
    if( ui_page == SEQ_UI_PAGE_PARSEL )
600 tk 1406
      SEQ_UI_PageSet(ui_parlayer_prev_page);
513 tk 1407
  }
1408
 
1409
  // set/clear encoder fast function if required
1410
  SEQ_UI_InitEncSpeed(1); // auto config
1411
 
1412
  return 0; // no error
1413
}
1414
 
134 tk 1415
static s32 SEQ_UI_Button_ParLayer(s32 depressed, u32 par_layer)
1416
{
1117 tk 1417
  static u8 layer_c_pressed = 0;
784 tk 1418
 
134 tk 1419
  if( par_layer >= 3 ) return -2; // max. 3 parlayer buttons
1420
 
1205 tk 1421
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1422
  u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1423
 
987 tk 1424
  // in song page: parameter layer buttons are used to select the cursor position
1425
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1426
    ui_selected_item = par_layer;
1427
    return 0;
1428
  }
1429
 
1205 tk 1430
  // drum mode in edit page: print parameter layer as long as button is pressed
1431
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1432
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1433
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1434
      ui_hold_msg_ctr = depressed ? 0 : ~0; // show value for at least 65 seconds... enough?
1435
    }
1436
  }
134 tk 1437
 
784 tk 1438
  // holding Layer C button allows to increment/decrement layer with A/B button
1439
  if( par_layer == 2 )
1440
    layer_c_pressed = !depressed;
1441
 
1442
  if( layer_c_pressed && par_layer == 0 ) {
333 tk 1443
    if( depressed ) return -1; // ignore when button depressed
784 tk 1444
    // increment layer
1445
    if( ++ui_selected_par_layer >= num_p_layers )
1446
      ui_selected_par_layer = 0;
1447
  } else if( layer_c_pressed && par_layer == 1 ) {
333 tk 1448
    if( depressed ) return -1; // ignore when button depressed
784 tk 1449
    // decrement layer
1450
    if( ui_selected_par_layer == 0 )
1451
      ui_selected_par_layer = num_p_layers - 1;
333 tk 1452
    else
784 tk 1453
      --ui_selected_par_layer;
333 tk 1454
  } else {
784 tk 1455
    if( num_p_layers <= 3 ) {
1456
      // 3 layers: direct selection with LayerA/B/C button
333 tk 1457
      if( depressed ) return -1; // ignore when button depressed
784 tk 1458
      if( par_layer >= num_p_layers ) {
1459
    char str1[21];
1460
    sprintf(str1, "Parameter Layer %c", 'A'+par_layer);
1461
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1462
      } else {
1463
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1464
    ui_selected_par_layer = par_layer;
1465
      }
1466
    } else if( num_p_layers <= 4 ) {
1467
      // 4 layers: LayerC Button toggles between C and D
1468
      if( depressed ) return -1; // ignore when button depressed
333 tk 1469
      seq_ui_button_state.PAR_LAYER_SEL = 0;
784 tk 1470
      if( par_layer == 2 )
1471
    ui_selected_par_layer = (ui_selected_par_layer == 2) ? 3 : 2;
1472
      else
1473
    ui_selected_par_layer = par_layer;
333 tk 1474
    } else {
784 tk 1475
      // >4 layers: LayerA/B button selects directly, Layer C button enters layer selection page
1476
      if( par_layer <= 1 ) {
1477
    if( depressed ) return -1; // ignore when button depressed
1478
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1479
    ui_selected_par_layer = par_layer;
1480
      } else {
1481
    return SEQ_UI_Button_ParLayerSel(depressed);
1482
      }
333 tk 1483
    }
1484
  }
1485
 
178 tk 1486
  // set/clear encoder fast function if required
1487
  SEQ_UI_InitEncSpeed(1); // auto config
1488
 
134 tk 1489
  return 0; // no error
1490
}
1491
 
513 tk 1492
static s32 SEQ_UI_Button_TrgLayerSel(s32 depressed)
1493
{
600 tk 1494
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1495
  // also used by seq_ui_trgsel.c
513 tk 1496
 
1497
  if( seq_hwcfg_button_beh.trg_layer ) {
1498
    if( depressed ) return -1; // ignore when button depressed
678 tk 1499
    if( !seq_ui_button_state.TRG_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1500
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1501
    seq_ui_button_state.TRG_LAYER_SEL ^= 1; // toggle TRGSEL status (will also be released once GP button has been pressed)
1502
  } else {
1503
    seq_ui_button_state.TRG_LAYER_SEL = depressed ? 0 : 1;
1504
  }
1505
 
1506
  if( seq_ui_button_state.TRG_LAYER_SEL ) {
600 tk 1507
    ui_trglayer_prev_page = ui_page;
513 tk 1508
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRGSEL);
1509
  } else {
524 tk 1510
    if( ui_page == SEQ_UI_PAGE_TRGSEL )
600 tk 1511
      SEQ_UI_PageSet(ui_trglayer_prev_page);
513 tk 1512
  }
1513
 
1514
  return 0; // no error
1515
}
1516
 
134 tk 1517
static s32 SEQ_UI_Button_TrgLayer(s32 depressed, u32 trg_layer)
1518
{
1117 tk 1519
  static u8 layer_c_pressed = 0;
784 tk 1520
 
134 tk 1521
  if( trg_layer >= 3 ) return -2; // max. 3 trglayer buttons
1522
 
326 tk 1523
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1524
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1525
  u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
134 tk 1526
 
1205 tk 1527
  // drum mode in edit page: ensure that trigger layer is print again
1528
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1529
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1530
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1531
      if( !depressed )
1532
    ui_hold_msg_ctr = 0;
1533
    }
1534
  }
1535
 
784 tk 1536
  // holding Layer C button allows to increment/decrement layer with A/B button
1537
  if( trg_layer == 2 )
1538
    layer_c_pressed = !depressed;
1539
 
1540
  if( layer_c_pressed && trg_layer == 0 ) {
326 tk 1541
    if( depressed ) return -1; // ignore when button depressed
784 tk 1542
    // increment layer
1543
    if( ++ui_selected_trg_layer >= num_t_layers )
1544
      ui_selected_trg_layer = 0;
1545
  } else if( layer_c_pressed && trg_layer == 1 ) {
326 tk 1546
    if( depressed ) return -1; // ignore when button depressed
784 tk 1547
    // decrement layer
1548
    if( ui_selected_trg_layer == 0 )
1549
      ui_selected_trg_layer = num_t_layers - 1;
326 tk 1550
    else
784 tk 1551
      --ui_selected_trg_layer;
326 tk 1552
  } else {
784 tk 1553
    if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 3 ) {
1554
      // 3 layers: direct selection with LayerA/B/C button
326 tk 1555
      if( depressed ) return -1; // ignore when button depressed
784 tk 1556
      if( trg_layer >= num_t_layers ) {
1557
    char str1[21];
1558
    sprintf(str1, "Trigger Layer %c", 'A'+trg_layer);
1559
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1560
      } else {
1561
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1562
    ui_selected_trg_layer = trg_layer;
1563
      }
1564
    } else if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 4 ) {
1565
      // 4 layers: LayerC Button toggles between C and D
1566
      if( depressed ) return -1; // ignore when button depressed
328 tk 1567
      seq_ui_button_state.TRG_LAYER_SEL = 0;
784 tk 1568
      if( trg_layer == 2 )
1569
    ui_selected_trg_layer = (ui_selected_trg_layer == 2) ? 3 : 2;
1570
      else
1571
    ui_selected_trg_layer = trg_layer;
326 tk 1572
    } else {
784 tk 1573
      // >4 layers or drum mode: LayerA/B button selects directly, Layer C button enters trigger selection page
1574
      // also used for drum tracks
1575
      if( trg_layer <= 1 ) {
1576
    if( depressed ) return -1; // ignore when button depressed
1577
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1578
    ui_selected_trg_layer = trg_layer;
1579
      } else {
1580
    return SEQ_UI_Button_TrgLayerSel(depressed);
1581
      }
326 tk 1582
    }
1583
  }
1584
 
134 tk 1585
  return 0; // no error
1586
}
1587
 
1588
 
1119 tk 1589
static s32 SEQ_UI_Button_Mixer(s32 depressed)
544 tk 1590
{
1591
  if( depressed ) return -1; // ignore when button depressed
134 tk 1592
 
1119 tk 1593
  SEQ_UI_PageSet(SEQ_UI_PAGE_MIXER);
544 tk 1594
 
1595
  return 0; // no error
1596
}
1597
 
1119 tk 1598
static s32 SEQ_UI_Button_TrackMode(s32 depressed)
544 tk 1599
{
1600
  if( depressed ) return -1; // ignore when button depressed
1601
 
1119 tk 1602
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMODE);
544 tk 1603
 
1604
  return 0; // no error
1605
}
1606
 
1119 tk 1607
static s32 SEQ_UI_Button_TrackGroove(s32 depressed)
544 tk 1608
{
1609
  if( depressed ) return -1; // ignore when button depressed
1610
 
1119 tk 1611
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKGRV);
1612
 
1613
  return 0; // no error
1614
}
1615
 
1616
static s32 SEQ_UI_Button_TrackLength(s32 depressed)
1617
{
1618
  if( depressed ) return -1; // ignore when button depressed
1619
 
1620
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKLEN);
1621
 
1622
  return 0; // no error
1623
}
1624
 
1625
static s32 SEQ_UI_Button_TrackDirection(s32 depressed)
1626
{
1627
  if( depressed ) return -1; // ignore when button depressed
1628
 
1629
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKDIR);
1630
 
1631
  return 0; // no error
1632
}
1633
 
1634
static s32 SEQ_UI_Button_TrackMorph(s32 depressed)
1635
{
1636
  if( depressed ) return -1; // ignore when button depressed
1637
 
1638
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMORPH);
1639
 
1640
  return 0; // no error
1641
}
1642
 
1643
static s32 SEQ_UI_Button_TrackTranspose(s32 depressed)
1644
{
1645
  if( depressed ) return -1; // ignore when button depressed
1646
 
544 tk 1647
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKTRAN);
1648
 
1649
  return 0; // no error
1650
}
1651
 
1652
 
742 tk 1653
// only used by keyboard remote function
1654
static s32 SEQ_UI_Button_ToggleGate(s32 depressed)
1655
{
1656
  if( depressed ) return -1; // ignore when button depressed
544 tk 1657
 
742 tk 1658
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1659
  u8 gate = SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? 0 : 1;
1660
  SEQ_TRG_GateSet(visible_track, ui_selected_step, ui_selected_instrument, gate);
544 tk 1661
 
742 tk 1662
  return 0; // no error
1663
}
1664
 
1349 tk 1665
static s32 SEQ_UI_Button_FootSwitch(s32 depressed)
1666
{
1667
  // static variables (only used here, therefore local)
1668
  static u32 fs_time_control = 0; // timestamp of last operation
1669
  static u8  fs_mode = 0; // mode
742 tk 1670
 
1349 tk 1671
  // this is used as a constant value
1672
  u32 fs_time_delay = 1000; // mS - should this be configurable?
742 tk 1673
 
1349 tk 1674
 
1675
  // PUNCH_IN, PUNCH_OUT and Delete track data control
1676
  if( !depressed ) {
1677
    if( ( fs_time_control > (seq_core_timestamp_ms - fs_time_delay) ) && ( fs_time_control != 0 ) )
1678
    {
1679
      // that confirms the delete function
1680
      fs_mode = 1; // delete
1681
    } else {
1682
      // start time in count
1683
      fs_time_control = seq_core_timestamp_ms;
1684
    }
1685
  } else {
1686
    // if time pressed is less than fs_time_delay miliseconds, we got a possible delete function activation
1687
    if( fs_time_control > (seq_core_timestamp_ms - fs_time_delay) )
1688
    {
1689
      switch( fs_mode ) {
1690
      case 1: { // delete
1691
        SEQ_UI_Button_Clear_Track(0);
1692
        fs_mode = 0; // back to normal mode, later we would increment the value
1693
      } break;
1694
      default:
1695
        fs_mode = 0; // for the case that an invalid mode is selected
1696
      }
1697
 
1698
      fs_time_control = seq_core_timestamp_ms;
1699
    }
1700
  }
1701
 
1702
  if( depressed ) {
1703
    // disable recording
1704
    seq_record_state.ENABLED = 0;
1705
  } else {
1706
    // enable recording
1707
    seq_record_state.ENABLED = 1;
1708
    seq_record_state.ARMED_TRACKS = ui_selected_tracks; // not used yet, just preparation for future changes
1709
  }
1710
 
1711
  return 0; // no error
1712
}
1713
 
1714
 
134 tk 1715
/////////////////////////////////////////////////////////////////////////////
1716
// Button handler
1717
/////////////////////////////////////////////////////////////////////////////
1718
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
1719
{
492 tk 1720
  int i;
1721
 
625 tk 1722
  // send MIDI event in remote mode and exit
1316 tk 1723
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 1724
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendButton(pin, pin_value);
1725
 
1044 tk 1726
  // ignore as long as hardware config hasn't been read
496 tk 1727
  if( !SEQ_FILE_HW_ConfigLocked() )
1728
    return -1;
1729
 
740 tk 1730
  // ignore during a backup or format is created
1731
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1732
    return -1;
1733
 
328 tk 1734
  // ensure that selections are matching with track constraints
1735
  SEQ_UI_CheckSelections();
1736
 
492 tk 1737
  // request display update
1738
  seq_ui_display_update_req = 1;
134 tk 1739
 
596 tk 1740
  // stop current message if (new) button has been pressed
1741
  if( pin_value == 0 )
1742
    SEQ_UI_MsgStop();
134 tk 1743
 
596 tk 1744
 
492 tk 1745
  // MEMO: we could also use a jump table with references to the functions
1746
  // here, but this "spagetthi code" simplifies the configuration and
1747
  // the resulting ASM doesn't look that bad!
168 tk 1748
 
492 tk 1749
  for(i=0; i<SEQ_HWCFG_NUM_GP; ++i)
1750
    if( pin == seq_hwcfg_button.gp[i] )
1751
      return SEQ_UI_Button_GP(pin_value, i);
134 tk 1752
 
492 tk 1753
  for(i=0; i<SEQ_HWCFG_NUM_TRACK; ++i)
1754
    if( pin == seq_hwcfg_button.track[i] )
1755
      return SEQ_UI_Button_Track(pin_value, i);
1146 tk 1756
 
1757
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_TRACK; ++i)
1758
    if( pin == seq_hwcfg_button.direct_track[i] )
1759
      return SEQ_UI_Button_DirectTrack(pin_value, i);
1760
 
1205 tk 1761
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_BOOKMARK; ++i)
1762
    if( pin == seq_hwcfg_button.direct_bookmark[i] )
1763
      return SEQ_UI_Button_DirectBookmark(pin_value, i);
1764
 
513 tk 1765
  if( pin == seq_hwcfg_button.track_sel )
1766
    return SEQ_UI_Button_TrackSel(pin_value);
134 tk 1767
 
492 tk 1768
  for(i=0; i<SEQ_HWCFG_NUM_GROUP; ++i)
1769
    if( pin == seq_hwcfg_button.group[i] )
1770
      return SEQ_UI_Button_Group(pin_value, i);
134 tk 1771
 
492 tk 1772
  for(i=0; i<SEQ_HWCFG_NUM_PAR_LAYER; ++i)
1773
    if( pin == seq_hwcfg_button.par_layer[i] )
1774
      return SEQ_UI_Button_ParLayer(pin_value, i);
513 tk 1775
  if( pin == seq_hwcfg_button.par_layer_sel )
1776
    return SEQ_UI_Button_ParLayerSel(pin_value);
134 tk 1777
 
492 tk 1778
  for(i=0; i<SEQ_HWCFG_NUM_TRG_LAYER; ++i)
1779
    if( pin == seq_hwcfg_button.trg_layer[i] )
1780
      return SEQ_UI_Button_TrgLayer(pin_value, i);
513 tk 1781
  if( pin == seq_hwcfg_button.trg_layer_sel )
1782
    return SEQ_UI_Button_TrgLayerSel(pin_value);
134 tk 1783
 
492 tk 1784
  if( pin == seq_hwcfg_button.left )
1785
    return SEQ_UI_Button_Left(pin_value);
1786
  if( pin == seq_hwcfg_button.right )
1787
    return SEQ_UI_Button_Right(pin_value);
1788
  if( pin == seq_hwcfg_button.down )
1789
    return SEQ_UI_Button_Down(pin_value);
1790
  if( pin == seq_hwcfg_button.up )
1791
    return SEQ_UI_Button_Up(pin_value);
134 tk 1792
 
492 tk 1793
  if( pin == seq_hwcfg_button.scrub )
1794
    return SEQ_UI_Button_Scrub(pin_value);
1795
  if( pin == seq_hwcfg_button.metronome )
1796
    return SEQ_UI_Button_Metronome(pin_value);
134 tk 1797
 
630 tk 1798
  if( pin == seq_hwcfg_button.record )
1799
    return SEQ_UI_Button_Record(pin_value);
1219 tk 1800
  if( pin == seq_hwcfg_button.live )
1801
    return SEQ_UI_Button_Live(pin_value);
630 tk 1802
 
492 tk 1803
  if( pin == seq_hwcfg_button.stop )
1804
    return SEQ_UI_Button_Stop(pin_value);
1805
  if( pin == seq_hwcfg_button.pause )
1806
    return SEQ_UI_Button_Pause(pin_value);
1807
  if( pin == seq_hwcfg_button.play )
1808
    return SEQ_UI_Button_Play(pin_value);
1809
  if( pin == seq_hwcfg_button.rew )
1810
    return SEQ_UI_Button_Rew(pin_value);
1811
  if( pin == seq_hwcfg_button.fwd )
1812
    return SEQ_UI_Button_Fwd(pin_value);
596 tk 1813
  if( pin == seq_hwcfg_button.loop )
1814
    return SEQ_UI_Button_Loop(pin_value);
973 tk 1815
  if( pin == seq_hwcfg_button.follow )
1816
    return SEQ_UI_Button_Follow(pin_value);
134 tk 1817
 
492 tk 1818
  if( pin == seq_hwcfg_button.utility )
1819
    return SEQ_UI_Button_Utility(pin_value);
1820
  if( pin == seq_hwcfg_button.copy )
1821
    return SEQ_UI_Button_Copy(pin_value);
1822
  if( pin == seq_hwcfg_button.paste )
1823
    return SEQ_UI_Button_Paste(pin_value);
1824
  if( pin == seq_hwcfg_button.clear )
1825
    return SEQ_UI_Button_Clear(pin_value);
1014 tk 1826
  if( pin == seq_hwcfg_button.undo )
1827
    return SEQ_UI_Button_Undo(pin_value);
134 tk 1828
 
492 tk 1829
  if( pin == seq_hwcfg_button.menu )
1830
    return SEQ_UI_Button_Menu(pin_value);
1203 tk 1831
  if( pin == seq_hwcfg_button.bookmark )
1832
    return SEQ_UI_Button_Bookmark(pin_value);
492 tk 1833
  if( pin == seq_hwcfg_button.select )
1834
    return SEQ_UI_Button_Select(pin_value);
1835
  if( pin == seq_hwcfg_button.exit )
1836
    return SEQ_UI_Button_Exit(pin_value);
134 tk 1837
 
513 tk 1838
  if( pin == seq_hwcfg_button.tap_tempo )
1839
    return SEQ_UI_Button_TapTempo(pin_value);
1840
  if( pin == seq_hwcfg_button.tempo_preset )
1841
    return SEQ_UI_Button_TempoPreset(pin_value);
524 tk 1842
  if( pin == seq_hwcfg_button.ext_restart )
1843
    return SEQ_UI_Button_ExtRestart(pin_value);
134 tk 1844
 
492 tk 1845
  if( pin == seq_hwcfg_button.edit )
1846
    return SEQ_UI_Button_Edit(pin_value);
1847
  if( pin == seq_hwcfg_button.mute )
1848
    return SEQ_UI_Button_Mute(pin_value);
1849
  if( pin == seq_hwcfg_button.pattern )
1850
    return SEQ_UI_Button_Pattern(pin_value);
1851
  if( pin == seq_hwcfg_button.song )
1852
    return SEQ_UI_Button_Song(pin_value);
134 tk 1853
 
492 tk 1854
  if( pin == seq_hwcfg_button.solo )
1855
    return SEQ_UI_Button_Solo(pin_value);
1856
  if( pin == seq_hwcfg_button.fast )
1857
    return SEQ_UI_Button_Fast(pin_value);
1121 tk 1858
  if( pin == seq_hwcfg_button.fast2 )
1859
    return SEQ_UI_Button_Fast2(pin_value);
492 tk 1860
  if( pin == seq_hwcfg_button.all )
1861
    return SEQ_UI_Button_All(pin_value);
134 tk 1862
 
492 tk 1863
  if( pin == seq_hwcfg_button.step_view )
1864
    return SEQ_UI_Button_StepView(pin_value);
134 tk 1865
 
544 tk 1866
  if( pin == seq_hwcfg_button.mixer )
1867
    return SEQ_UI_Button_Mixer(pin_value);
1868
 
1119 tk 1869
  if( pin == seq_hwcfg_button.track_mode )
1870
    return SEQ_UI_Button_TrackMode(pin_value);
1871
  if( pin == seq_hwcfg_button.track_groove )
1872
    return SEQ_UI_Button_TrackGroove(pin_value);
1873
  if( pin == seq_hwcfg_button.track_length )
1874
    return SEQ_UI_Button_TrackLength(pin_value);
1875
  if( pin == seq_hwcfg_button.track_direction )
1876
    return SEQ_UI_Button_TrackDirection(pin_value);
1877
  if( pin == seq_hwcfg_button.track_morph )
1878
    return SEQ_UI_Button_TrackMorph(pin_value);
1879
  if( pin == seq_hwcfg_button.track_transpose )
1880
    return SEQ_UI_Button_TrackTranspose(pin_value);
1349 tk 1881
  if( pin == seq_hwcfg_button.footswitch )
1882
    return SEQ_UI_Button_FootSwitch(pin_value);
1454 midilab 1883
  if( pin == seq_hwcfg_button.pattern_remix )
1884
    return SEQ_UI_Button_Pattern_Remix(pin_value);
625 tk 1885
  // always print debugging message
1886
#if 1
1081 tk 1887
  MUTEX_MIDIOUT_TAKE;
1888
  DEBUG_MSG("[SEQ_UI_Button_Handler] Button SR:%d, Pin:%d not mapped, it has been %s.\n",
1889
        (pin >> 3) + 1,
1890
        pin & 7,
1891
        pin_value ? "depressed" : "pressed");
1892
  MUTEX_MIDIOUT_GIVE;
625 tk 1893
#endif
1894
 
492 tk 1895
  return -1; // button not mapped
134 tk 1896
}
1897
 
1898
 
1899
/////////////////////////////////////////////////////////////////////////////
524 tk 1900
// BLM Button handler
1901
/////////////////////////////////////////////////////////////////////////////
1902
s32 SEQ_UI_BLM_Button_Handler(u32 row, u32 pin, u32 pin_value)
1903
{
625 tk 1904
  // send MIDI event in remote mode and exit
1316 tk 1905
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 1906
    return SEQ_MIDI_SYSEX_REMOTE_Client_Send_BLM_Button(row, pin, pin_value);
1907
 
1044 tk 1908
  // ignore as long as hardware config hasn't been read
524 tk 1909
  if( !SEQ_FILE_HW_ConfigLocked() )
1910
    return -1;
1911
 
740 tk 1912
  // ignore during a backup or format is created
1913
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1914
    return -1;
1915
 
524 tk 1916
  if( row >= SEQ_CORE_NUM_TRACKS_PER_GROUP )
1917
    return -1; // more than 4 tracks not supported (yet) - could be done in this function w/o much effort
1918
 
1919
  if( pin >= 16 )
1920
    return -1; // more than 16 step buttons not supported (yet) - could be done by selecting the step view
1921
 
1922
  // select track depending on row
1923
  ui_selected_tracks = 1 << (row + 4*ui_selected_group);
1924
 
1925
  // ensure that selections are matching with track constraints
1926
  SEQ_UI_CheckSelections();
1927
 
1928
  // request display update
1929
  seq_ui_display_update_req = 1;
1930
 
1931
  // emulate general purpose button
758 tk 1932
  if( seq_hwcfg_blm.buttons_no_ui ) {
763 tk 1933
    s32 status = SEQ_UI_EDIT_Button_Handler(pin, pin_value);
758 tk 1934
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1935
    return status;
763 tk 1936
  }
1937
 
1938
  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 1939
}
1940
 
1941
 
1942
/////////////////////////////////////////////////////////////////////////////
134 tk 1943
// Encoder handler
1944
/////////////////////////////////////////////////////////////////////////////
1945
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
1946
{
625 tk 1947
  // send MIDI event in remote mode and exit
1316 tk 1948
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 1949
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendEncoder(encoder, incrementer);
1950
 
1044 tk 1951
  // ignore as long as hardware config hasn't been read
496 tk 1952
  if( !SEQ_FILE_HW_ConfigLocked() )
1953
    return -1;
1954
 
740 tk 1955
  // ignore during a backup or format is created
1956
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 1957
    return -1;
1958
 
1341 tk 1959
  if( encoder >= SEQ_HWCFG_NUM_ENCODERS )
134 tk 1960
    return -1; // encoder doesn't exist
1961
 
328 tk 1962
  // ensure that selections are matching with track constraints
1963
  SEQ_UI_CheckSelections();
1964
 
596 tk 1965
  // stop current message
1966
  SEQ_UI_MsgStop();
1967
 
134 tk 1968
  // limit incrementer
1969
  if( incrementer > 3 )
1970
    incrementer = 3;
1971
  else if( incrementer < -3 )
1972
    incrementer = -3;
1973
 
1341 tk 1974
  // encoder 17 increments BPM
1975
  if( encoder == 17 ) {
1976
    u16 value = (u16)(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num]*10);
1977
    if( SEQ_UI_Var16_Inc(&value, 25, 3000, incrementer) ) { // at 384ppqn, the minimum BPM rate is ca. 2.5
1978
      // set new BPM
1979
      seq_core_bpm_preset_tempo[seq_core_bpm_preset_num] = (float)value/10.0;
1980
      SEQ_CORE_BPM_Update(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num], seq_core_bpm_preset_ramp[seq_core_bpm_preset_num]);
1981
      //store_file_required = 1;
1982
      seq_ui_display_update_req = 1;      
1983
    }
1984
    return 0;
1985
  }
1986
 
607 tk 1987
  if( seq_ui_button_state.SCRUB && encoder == 0 ) {
1988
    // if sequencer isn't already running, continue it (don't restart)
1989
    if( !SEQ_BPM_IsRunning() )
1990
      SEQ_BPM_Cont();
1991
    ui_seq_pause = 0; // clear pause mode
1278 tk 1992
 
607 tk 1993
    // Scrub sequence back or forth
1994
    portENTER_CRITICAL(); // should be atomic
1995
    SEQ_CORE_Scrub(incrementer);
1996
    portEXIT_CRITICAL();
1997
  } else if( !seq_ui_button_state.MENU_PRESSED && ui_encoder_callback != NULL ) {
173 tk 1998
    ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
740 tk 1999
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0; // ensure that value is visible when it has been changed
134 tk 2000
  }
2001
 
2002
  // request display update
159 tk 2003
  seq_ui_display_update_req = 1;
134 tk 2004
 
2005
  return 0; // no error
2006
}
2007
 
2008
 
353 tk 2009
 
134 tk 2010
/////////////////////////////////////////////////////////////////////////////
626 tk 2011
// Receives a MIDI package from APP_NotifyReceivedEvent (-> app.c)
2012
/////////////////////////////////////////////////////////////////////////////
2013
s32 SEQ_UI_REMOTE_MIDI_Receive(mios32_midi_port_t port, mios32_midi_package_t midi_package)
2014
{
2015
#if 1
2016
  // check for active remote mode
1316 tk 2017
  if( seq_midi_sysex_remote_active_mode != SEQ_MIDI_SYSEX_REMOTE_MODE_SERVER )
626 tk 2018
    return 0; // no error
2019
#endif
2020
 
1316 tk 2021
  if( (seq_midi_sysex_remote_port == DEFAULT && seq_midi_sysex_remote_active_port != port) ||
2022
      (seq_midi_sysex_remote_port != DEFAULT && port != seq_midi_sysex_remote_port) )
626 tk 2023
    return 0; // wrong port
2024
 
2025
  // for easier parsing: convert Note Off -> Note On with velocity 0
2026
  if( midi_package.event == NoteOff ) {
2027
    midi_package.event = NoteOn;
2028
    midi_package.velocity = 0;
2029
  }
2030
 
2031
  switch( midi_package.event ) {
2032
    case NoteOn: {
2033
      switch( midi_package.chn ) {
2034
        case Chn1:
2035
      SEQ_UI_Button_Handler(midi_package.note + 0x00, midi_package.velocity ? 0 : 1);
2036
      break;
2037
        case Chn2:
2038
      SEQ_UI_Button_Handler(midi_package.note + 0x80, midi_package.velocity ? 0 : 1);
2039
      break;
2040
        case Chn3:
2041
      SEQ_UI_BLM_Button_Handler(midi_package.note >> 5, midi_package.note & 0x1f, midi_package.velocity ? 0 : 1);
2042
      break;
2043
      }
2044
    } break;
2045
 
2046
    case CC: {
2047
      if( midi_package.cc_number >= 15 && midi_package.cc_number <= 31 )
2048
    SEQ_UI_Encoder_Handler(midi_package.cc_number-15, (int)midi_package.value - 0x40);
2049
    } break;
2050
  }
2051
 
632 tk 2052
  return 1; // MIDI event has been taken for remote function -> don't forward to router/MIDI event parser
626 tk 2053
}
2054
 
2055
 
2056
/////////////////////////////////////////////////////////////////////////////
741 tk 2057
// MIDI Remote Keyboard Function (called from SEQ_MIDI_IN)
2058
/////////////////////////////////////////////////////////////////////////////
742 tk 2059
s32 SEQ_UI_REMOTE_MIDI_Keyboard(u8 key, u8 depressed)
741 tk 2060
{
742 tk 2061
#if 0
1316 tk 2062
  MIOS32_MIDI_SendDebugMessage("SEQ_MIDI_SYSEX_REMOTE_MIDI_Keyboard(%d, %d)\n", key, depressed);
741 tk 2063
#endif
742 tk 2064
 
2065
  switch( key ) {
2066
    case 0x24: // C-2
2067
      return SEQ_UI_Button_GP(depressed, 0);
2068
    case 0x25: // C#2
2069
      return SEQ_UI_Button_Track(depressed, 0);
2070
    case 0x26: // D-2
2071
      return SEQ_UI_Button_GP(depressed, 1);
2072
    case 0x27: // D#2
2073
      return SEQ_UI_Button_Track(depressed, 1);
2074
    case 0x28: // E-2
2075
      return SEQ_UI_Button_GP(depressed, 2);
2076
    case 0x29: // F-2
2077
      return SEQ_UI_Button_GP(depressed, 3);
2078
    case 0x2a: // F#2
2079
      return SEQ_UI_Button_Track(depressed, 2);
2080
    case 0x2b: // G-2
2081
      return SEQ_UI_Button_GP(depressed, 4);
2082
    case 0x2c: // G#2
2083
      return SEQ_UI_Button_Track(depressed, 3);
2084
    case 0x2d: // A-2
2085
      return SEQ_UI_Button_GP(depressed, 5);
2086
    case 0x2e: // A#2
2087
      return SEQ_UI_Button_ParLayer(depressed, 0);
2088
    case 0x2f: // B-2
2089
      return SEQ_UI_Button_GP(depressed, 6);
2090
 
2091
    case 0x30: // C-3
2092
      return SEQ_UI_Button_GP(depressed, 7);
2093
    case 0x31: // C#3
2094
      return SEQ_UI_Button_ParLayer(depressed, 1);
2095
    case 0x32: // D-3
2096
      return SEQ_UI_Button_GP(depressed, 8);
2097
    case 0x33: // D#3
2098
      return SEQ_UI_Button_ParLayer(depressed, 2);
2099
    case 0x34: // E-3
2100
      return SEQ_UI_Button_GP(depressed, 9);
2101
    case 0x35: // F-3
2102
      return SEQ_UI_Button_GP(depressed, 10);
2103
    case 0x36: // F#3
2104
      return SEQ_UI_Button_TrgLayer(depressed, 0);
2105
    case 0x37: // G-3
2106
      return SEQ_UI_Button_GP(depressed, 11);
2107
    case 0x38: // G#3
2108
      return SEQ_UI_Button_TrgLayer(depressed, 1);
2109
    case 0x39: // A-3
2110
      return SEQ_UI_Button_GP(depressed, 12);
2111
    case 0x3a: // A#3
2112
      return SEQ_UI_Button_TrgLayer(depressed, 2);
2113
    case 0x3b: // B-3
2114
      return SEQ_UI_Button_GP(depressed, 13);
2115
 
2116
    case 0x3c: // C-4
2117
      return SEQ_UI_Button_GP(depressed, 14);
2118
    case 0x3d: // C#4
2119
      return SEQ_UI_Button_Group(depressed, 0);
2120
    case 0x3e: // D-4
2121
      return SEQ_UI_Button_GP(depressed, 15);
2122
    case 0x3f: // D#4
2123
      return SEQ_UI_Button_Group(depressed, 1);
2124
    case 0x40: // E-4
2125
      return 0; // ignore
2126
    case 0x41: // F-4
2127
      return SEQ_UI_Button_StepView(depressed);
2128
    case 0x42: // F#4
2129
      return SEQ_UI_Button_Group(depressed, 1);
2130
    case 0x43: // G-4
2131
      return 0; // ignore
2132
    case 0x44: // G#4
2133
      return SEQ_UI_Button_Group(depressed, 2);
2134
    case 0x45: // A-4
2135
      return SEQ_UI_Button_Left(depressed);
2136
    case 0x46: // A#4
2137
      return SEQ_UI_Button_ToggleGate(depressed);
2138
    case 0x47: // B-4
2139
      return SEQ_UI_Button_Right(depressed);
2140
 
2141
    case 0x48: // C-5
2142
      return SEQ_UI_Button_Edit(depressed);
2143
    case 0x49: // C#5
2144
      return SEQ_UI_Button_Solo(depressed);
2145
    case 0x4a: // D-5
2146
      return SEQ_UI_Button_Mute(depressed);
2147
    case 0x4b: // D#5
2148
      return SEQ_UI_Button_All(depressed);
2149
    case 0x4c: // E-5
2150
      return SEQ_UI_Button_Pattern(depressed);
2151
    case 0x4d: // F-5
2152
      return SEQ_UI_Button_Song(depressed);
2153
    case 0x4e: // F#5
2154
      return SEQ_UI_Button_Fast(depressed);
2155
    case 0x4f: // G-5
2156
      return SEQ_UI_Button_Metronome(depressed);
2157
    case 0x50: // G#5
2158
      return SEQ_UI_Button_ExtRestart(depressed);
2159
    case 0x51: // A-5
2160
      return SEQ_UI_Button_ParLayerSel(depressed);
2161
    case 0x52: // A#5
2162
      return SEQ_UI_Button_TrackSel(depressed);
2163
    case 0x53: // B-5
2164
      return SEQ_UI_Button_Stop(depressed);
2165
 
2166
    case 0x54: // C-6
2167
      return SEQ_UI_Button_Play(depressed);
2168
    case 0x55: // C#6
2169
      return SEQ_UI_Button_Pause(depressed);
2170
    case 0x56: // D-6
2171
      return SEQ_UI_Button_Rew(depressed);
2172
    case 0x57: // D#6
2173
      return SEQ_UI_Button_Fwd(depressed);
2174
    case 0x58: // E-6
2175
      return SEQ_UI_Button_Utility(depressed);
2176
    case 0x59: // F-6
2177
      return SEQ_UI_Button_TempoPreset(depressed);
2178
    case 0x5a: // F#6
2179
      return 0; // ignore
2180
    case 0x5b: // G-6
2181
      return SEQ_UI_Button_Menu(depressed);
2182
    case 0x5c: // G#6
2183
      return SEQ_UI_Button_Select(depressed);
2184
    case 0x5d: // A-6
2185
      return SEQ_UI_Button_Exit(depressed);
2186
    case 0x5e: // A#6
2187
      return SEQ_UI_Button_Down(depressed);
2188
    case 0x5f: // B-6
2189
      return SEQ_UI_Button_Up(depressed);
2190
  }
2191
 
741 tk 2192
  return 0; // no error
2193
}
2194
 
2195
 
2196
/////////////////////////////////////////////////////////////////////////////
134 tk 2197
// Update LCD messages
2198
// Usually called from background task
2199
/////////////////////////////////////////////////////////////////////////////
2200
s32 SEQ_UI_LCD_Handler(void)
2201
{
728 tk 2202
  static u8 boot_animation_wait_ctr = 0;
2203
  static u8 boot_animation_lcd_pos = 0;
2204
 
625 tk 2205
  // special handling in remote client mode
1316 tk 2206
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2207
    return SEQ_UI_LCD_Update();
2208
 
159 tk 2209
  if( seq_ui_display_init_req ) {
2210
    seq_ui_display_init_req = 0; // clear request
134 tk 2211
 
278 tk 2212
    // clear force update of LCD
2213
    SEQ_LCD_Clear();
2214
    SEQ_LCD_Update(1);
134 tk 2215
 
168 tk 2216
    // select first menu item
2217
    ui_selected_item = 0;
2218
 
167 tk 2219
    // call init function of current page
272 tk 2220
    if( ui_menu_pages[ui_page].init_callback != NULL )
2221
      ui_menu_pages[ui_page].init_callback(0); // mode
134 tk 2222
 
2223
    // request display update
159 tk 2224
    seq_ui_display_update_req = 1;
134 tk 2225
  }
2226
 
1044 tk 2227
  // print boot screen as long as hardware config hasn't been read
496 tk 2228
  if( !SEQ_FILE_HW_ConfigLocked() ) {
728 tk 2229
    if( boot_animation_lcd_pos < (40-3) ) {
2230
      if( ++boot_animation_wait_ctr >= 75 ) {
2231
    boot_animation_wait_ctr = 0;
637 tk 2232
 
728 tk 2233
    if( boot_animation_lcd_pos == 0 ) {
2234
      SEQ_LCD_Clear();
2235
      SEQ_LCD_CursorSet(0, 0);
2236
      SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE1 " " MIOS32_LCD_BOOT_MSG_LINE2);
2237
      SEQ_LCD_CursorSet(0, 1);
2238
      SEQ_LCD_PrintString("Searching for SD Card...");
2239
    }
2240
 
2241
    // logo is print on second LCD
2242
    SEQ_LCD_LOGO_Print(boot_animation_lcd_pos++);
2243
      }
2244
    }
740 tk 2245
  } else if( seq_ui_backup_req || seq_ui_format_req ) {
634 tk 2246
    SEQ_LCD_Clear();
2247
    SEQ_LCD_CursorSet(0, 0);
740 tk 2248
    //                     <-------------------------------------->
2249
    //                     0123456789012345678901234567890123456789
2250
    if( seq_ui_backup_req )
959 tk 2251
      SEQ_LCD_PrintString("Copy Files - be patient!!!");
740 tk 2252
    else if( seq_ui_format_req )
959 tk 2253
      SEQ_LCD_PrintString("Creating Files - be patient!!!");
740 tk 2254
    else
2255
      SEQ_LCD_PrintString("Don't know what I'm doing! :-/");
637 tk 2256
 
2257
    if( seq_file_backup_notification != NULL ) {
2258
      int i;
2259
 
2260
      SEQ_LCD_CursorSet(0, 1);
959 tk 2261
      SEQ_LCD_PrintFormattedString("Creating %s", seq_file_backup_notification);
637 tk 2262
 
2263
      SEQ_LCD_CursorSet(40+3, 0);
2264
      SEQ_LCD_PrintString("Total: [");
2265
      for(i=0; i<20; ++i)
2266
    SEQ_LCD_PrintChar((i>(seq_file_backup_percentage/5)) ? ' ' : '#');
2267
      SEQ_LCD_PrintFormattedString("] %3d%%", seq_file_backup_percentage);
2268
 
2269
      SEQ_LCD_CursorSet(40+3, 1);
2270
      SEQ_LCD_PrintString("File:  [");
2271
      for(i=0; i<20; ++i)
1261 tk 2272
    SEQ_LCD_PrintChar((i>(file_copy_percentage/5)) ? ' ' : '#');
2273
      SEQ_LCD_PrintFormattedString("] %3d%%", file_copy_percentage);
637 tk 2274
    }
2275
 
496 tk 2276
  } else if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
2277
    SEQ_LCD_CursorSet(0, 0);
2278
    //                   <-------------------------------------->
2279
    //                   0123456789012345678901234567890123456789
306 tk 2280
    SEQ_LCD_PrintString("Menu Shortcuts:");
2281
    SEQ_LCD_PrintSpaces(25 + 40);
2282
    SEQ_LCD_CursorSet(0, 1);
2283
    SEQ_LCD_PrintString(UI_SHORTCUT_STR); // defined in seq_ui_pages.inc
2284
  } else {
2285
    // perform high priority LCD update request
2286
    if( ui_lcd_callback != NULL )
2287
      ui_lcd_callback(1); // high_prio
167 tk 2288
 
306 tk 2289
    // perform low priority LCD update request if requested
2290
    if( seq_ui_display_update_req ) {
2291
      seq_ui_display_update_req = 0; // clear request
328 tk 2292
 
2293
      // ensure that selections are matching with track constraints
2294
      SEQ_UI_CheckSelections();
2295
 
306 tk 2296
      if( ui_lcd_callback != NULL )
2297
    ui_lcd_callback(0); // no high_prio
2298
    }
134 tk 2299
  }
2300
 
353 tk 2301
  // transfer all changed characters to LCD
2302
  SEQ_UI_LCD_Update();
2303
 
2304
  return 0; // no error
2305
}
2306
 
2307
 
2308
/////////////////////////////////////////////////////////////////////////////
2309
// Called from SEQ_UI_LCD_Handler(), but optionally also from other tasks
2310
// to update the LCD screen immediately
2311
/////////////////////////////////////////////////////////////////////////////
1117 tk 2312
// for newer GCC versions it's important to declare constant arrays outside a function
2313
//                                             00112233
2314
static const char animation_l_arrows[2*4+1] = "   >>>> ";
2315
//                                             00112233
2316
static const char animation_r_arrows[2*4+1] = "  < << <";
2317
//                                               00112233
2318
static const char animation_l_brackets[2*4+1] = "   )))) ";
2319
//                                               00112233
2320
static const char animation_r_brackets[2*4+1] = "  ( (( (";
2321
//                                            00112233
2322
static const char animation_l_stars[2*4+1] = "   **** ";
2323
//                                            00112233
2324
static const char animation_r_stars[2*4+1] = "  * ** *";
353 tk 2325
s32 SEQ_UI_LCD_Update(void)
2326
{
625 tk 2327
  // special handling in remote client mode
1316 tk 2328
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT ) {
626 tk 2329
    MIOS32_IRQ_Disable();
1316 tk 2330
    u8 force = seq_midi_sysex_remote_force_lcd_update;
2331
    seq_midi_sysex_remote_force_lcd_update = 0;
626 tk 2332
    MIOS32_IRQ_Enable();
2333
    return SEQ_LCD_Update(force);
625 tk 2334
  }
2335
 
596 tk 2336
  // if UI message active: copy over the text
2337
  if( ui_msg_ctr ) {
774 tk 2338
    char *animation_l_ptr;
2339
    char *animation_r_ptr;
596 tk 2340
    u8 msg_x = 0;
2341
    u8 right_aligned = 0;
740 tk 2342
    u8 disable_message = 0;
299 tk 2343
 
596 tk 2344
    switch( ui_msg_type ) {
2345
      case SEQ_UI_MSG_SDCARD: {
1117 tk 2346
    animation_l_ptr = (char *)animation_l_arrows;
2347
    animation_r_ptr = (char *)animation_r_arrows;
596 tk 2348
    msg_x = 0; // MEMO: print such important information at first LCD for the case the user hasn't connected the second LCD yet
2349
    right_aligned = 0;
2350
      } break;
2351
 
756 tk 2352
      case SEQ_UI_MSG_DELAYED_ACTION:
2353
      case SEQ_UI_MSG_DELAYED_ACTION_R: {
1117 tk 2354
    animation_l_ptr = (char *)animation_l_brackets;
2355
    animation_r_ptr = (char *)animation_r_brackets;
756 tk 2356
    if( ui_msg_type == SEQ_UI_MSG_DELAYED_ACTION_R ) {
2357
      msg_x = 40; // right LCD
2358
      right_aligned = 0;
2359
    } else {
2360
      msg_x = 39; // left LCD
2361
      right_aligned = 1;
2362
    }
740 tk 2363
 
2364
    if( ui_delayed_action_callback == NULL ) {
2365
      disable_message = 1; // button has been depressed before delay
2366
    } else {
2367
      int seconds = (ui_delayed_action_ctr / 1000) + 1;
2368
      if( seconds == 1 )
2369
        sprintf(ui_msg[0], "Hold for 1 second ");
2370
      else
2371
        sprintf(ui_msg[0], "Hold for %d seconds", seconds);
2372
    }
2373
      } break;
2374
 
741 tk 2375
      case SEQ_UI_MSG_USER_R: {
1117 tk 2376
    animation_l_ptr = (char *)animation_l_stars;
2377
    animation_r_ptr = (char *)animation_r_stars;
741 tk 2378
    msg_x = 40; // right display
2379
    right_aligned = 0;
2380
      } break;
2381
 
596 tk 2382
      default: {
1117 tk 2383
    animation_l_ptr = (char *)animation_l_stars;
2384
    animation_r_ptr = (char *)animation_r_stars;
596 tk 2385
    msg_x = 39;
2386
    right_aligned = 1;
2387
      } break;
2388
 
2389
    }
2390
 
740 tk 2391
    if( !disable_message ) {
2392
      int anum = (ui_msg_ctr % 1000) / 250;
596 tk 2393
 
740 tk 2394
      int len[2];
2395
      len[0] = strlen((char *)ui_msg[0]);
2396
      len[1] = strlen((char *)ui_msg[1]);
2397
      int len_max = len[0];
2398
      if( len[1] > len_max )
2399
    len_max = len[1];
596 tk 2400
 
740 tk 2401
      if( right_aligned )
2402
    msg_x -= (9 + len_max);
596 tk 2403
 
740 tk 2404
      int line;
2405
      for(line=0; line<2; ++line) {
2406
    SEQ_LCD_CursorSet(msg_x, line);
596 tk 2407
 
740 tk 2408
    // ensure that both lines are padded with same number of spaces
2409
    int end_pos = len[line];
2410
    while( end_pos < len_max )
2411
      ui_msg[line][end_pos++] = ' ';
2412
    ui_msg[line][end_pos] = 0;
2413
 
2414
    SEQ_LCD_PrintFormattedString(" %c%c| %s |%c%c ",
2415
                     *(animation_l_ptr + 2*anum + 0), *(animation_l_ptr + 2*anum + 1),
2416
                     (char *)ui_msg[line],
2417
                     *(animation_r_ptr + 2*anum + 0), *(animation_r_ptr + 2*anum + 1));
2418
      }
299 tk 2419
    }
2420
  }
2421
 
637 tk 2422
  // MSD USB notification at right corner if not in Disk page
2423
  // to warn user that USB MIDI is disabled and seq performance is bad now!
638 tk 2424
  if( (TASK_MSD_EnableGet() > 0) && ui_page != SEQ_UI_PAGE_DISK ) {
637 tk 2425
    SEQ_LCD_CursorSet(80-11, 0);
2426
    if( ui_cursor_flash ) SEQ_LCD_PrintSpaces(13); else SEQ_LCD_PrintString(" [MSD USB] ");
2427
    SEQ_LCD_CursorSet(80-11, 1);
2428
    char str[5];
2429
    TASK_MSD_FlagStrGet(str);
2430
    if( ui_cursor_flash ) SEQ_LCD_PrintSpaces(13); else SEQ_LCD_PrintFormattedString(" [ %s  ] ", str);
2431
  }
596 tk 2432
 
278 tk 2433
  // transfer all changed characters to LCD
353 tk 2434
  // SEQ_LCD_Update provides a MUTEX handling to allow updates from different tasks
2435
  return SEQ_LCD_Update(0);
134 tk 2436
}
2437
 
2438
 
2439
/////////////////////////////////////////////////////////////////////////////
2440
// Update all LEDs
2441
// Usually called from background task
2442
/////////////////////////////////////////////////////////////////////////////
2443
s32 SEQ_UI_LED_Handler(void)
2444
{
626 tk 2445
  static u8 remote_led_sr[SEQ_LED_NUM_SR];
2446
 
625 tk 2447
  // ignore in remote client mode
1316 tk 2448
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2449
    return 0; // no error
2450
 
1044 tk 2451
  // ignore as long as hardware config hasn't been read
496 tk 2452
  if( !SEQ_FILE_HW_ConfigLocked() )
2453
    return -1;
2454
 
134 tk 2455
  // track LEDs
987 tk 2456
  // in pattern page: track buttons are used as group buttons
2457
  if( ui_page == SEQ_UI_PAGE_PATTERN ) {
2458
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (ui_selected_group == 0));
2459
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (ui_selected_group == 1));
2460
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (ui_selected_group == 2));
2461
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (ui_selected_group == 3));
2462
  } else if( ui_page == SEQ_UI_PAGE_SONG ) {
2463
    // in song page: track and group buttons are used to select the cursor position
2464
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (ui_selected_item == 3));
2465
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (ui_selected_item == 4));
2466
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (ui_selected_item == 5));
2467
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (ui_selected_item == 6));
2468
  } else {
2469
    u8 selected_tracks = ui_selected_tracks >> (4*ui_selected_group);
2470
    SEQ_LED_PinSet(seq_hwcfg_led.track[0], (selected_tracks & (1 << 0)));
2471
    SEQ_LED_PinSet(seq_hwcfg_led.track[1], (selected_tracks & (1 << 1)));
2472
    SEQ_LED_PinSet(seq_hwcfg_led.track[2], (selected_tracks & (1 << 2)));
2473
    SEQ_LED_PinSet(seq_hwcfg_led.track[3], (selected_tracks & (1 << 3)));
2474
  }
2475
 
678 tk 2476
  SEQ_LED_PinSet(seq_hwcfg_led.track_sel, ui_page == SEQ_UI_PAGE_TRACKSEL);
134 tk 2477
 
2478
  // parameter layer LEDs
987 tk 2479
  // in song page: layer buttons are used to select the cursor position
2480
  if( ui_page == SEQ_UI_PAGE_SONG ) {
2481
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], ui_selected_item == 0);
2482
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], ui_selected_item == 1);
2483
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], ui_selected_item == 2);
2484
  } else {
2485
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[0], (ui_selected_par_layer == 0));
2486
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[1], (ui_selected_par_layer == 1));
2487
    SEQ_LED_PinSet(seq_hwcfg_led.par_layer[2], (ui_selected_par_layer >= 2) || seq_ui_button_state.PAR_LAYER_SEL);
2488
  }
678 tk 2489
  SEQ_LED_PinSet(seq_hwcfg_led.par_layer_sel, ui_page == SEQ_UI_PAGE_PARSEL);
134 tk 2490
 
2491
  // group LEDs
987 tk 2492
  // in song page: track and group buttons are used to select the cursor position
2493
  if( ui_page == SEQ_UI_PAGE_SONG ) {
2494
    SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_item == 3));
2495
    SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_item == 4));
2496
    SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_item == 5));
2497
    SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_item == 6));
2498
  } else {
2499
    SEQ_LED_PinSet(seq_hwcfg_led.group[0], (ui_selected_group == 0));
2500
    SEQ_LED_PinSet(seq_hwcfg_led.group[1], (ui_selected_group == 1));
2501
    SEQ_LED_PinSet(seq_hwcfg_led.group[2], (ui_selected_group == 2));
2502
    SEQ_LED_PinSet(seq_hwcfg_led.group[3], (ui_selected_group == 3));
2503
  }
134 tk 2504
 
2505
  // trigger layer LEDs
492 tk 2506
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[0], (ui_selected_trg_layer == 0));
2507
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[1], (ui_selected_trg_layer == 1));
2508
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer[2], (ui_selected_trg_layer >= 2) || seq_ui_button_state.TRG_LAYER_SEL);
678 tk 2509
  SEQ_LED_PinSet(seq_hwcfg_led.trg_layer_sel, ui_page == SEQ_UI_PAGE_TRGSEL);
134 tk 2510
 
2511
  // remaining LEDs
492 tk 2512
  SEQ_LED_PinSet(seq_hwcfg_led.edit, ui_page == SEQ_UI_PAGE_EDIT);
2513
  SEQ_LED_PinSet(seq_hwcfg_led.mute, ui_page == SEQ_UI_PAGE_MUTE);
2514
  SEQ_LED_PinSet(seq_hwcfg_led.pattern, ui_page == SEQ_UI_PAGE_PATTERN);
399 tk 2515
  if( SEQ_SONG_ActiveGet() )
492 tk 2516
    SEQ_LED_PinSet(seq_hwcfg_led.song, 1);
399 tk 2517
  else
492 tk 2518
    SEQ_LED_PinSet(seq_hwcfg_led.song, ui_cursor_flash ? 0 : (ui_page == SEQ_UI_PAGE_SONG));
743 tk 2519
  SEQ_LED_PinSet(seq_hwcfg_led.mixer, ui_page == SEQ_UI_PAGE_MIXER);
1119 tk 2520
 
2521
  SEQ_LED_PinSet(seq_hwcfg_led.track_mode, ui_page == SEQ_UI_PAGE_TRKMODE);
2522
  SEQ_LED_PinSet(seq_hwcfg_led.track_groove, ui_page == SEQ_UI_PAGE_TRKGRV);
2523
  SEQ_LED_PinSet(seq_hwcfg_led.track_length, ui_page == SEQ_UI_PAGE_TRKLEN);
2524
  SEQ_LED_PinSet(seq_hwcfg_led.track_direction, ui_page == SEQ_UI_PAGE_TRKDIR);
2525
  SEQ_LED_PinSet(seq_hwcfg_led.track_morph, ui_page == SEQ_UI_PAGE_TRKMORPH);
2526
  SEQ_LED_PinSet(seq_hwcfg_led.track_transpose, ui_page == SEQ_UI_PAGE_TRKTRAN);
134 tk 2527
 
492 tk 2528
  SEQ_LED_PinSet(seq_hwcfg_led.solo, seq_ui_button_state.SOLO);
2529
  SEQ_LED_PinSet(seq_hwcfg_led.fast, seq_ui_button_state.FAST_ENCODERS);
1121 tk 2530
  SEQ_LED_PinSet(seq_hwcfg_led.fast2, seq_ui_button_state.FAST2_ENCODERS);
492 tk 2531
  SEQ_LED_PinSet(seq_hwcfg_led.all, seq_ui_button_state.CHANGE_ALL_STEPS);
134 tk 2532
 
1206 tk 2533
  u8 seq_running = SEQ_BPM_IsRunning() && (!seq_core_slaveclk_mute || ((seq_core_state.ref_step & 3) == 0));
2534
  // 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
2535
  SEQ_LED_PinSet(seq_hwcfg_led.play, seq_running);
2536
  SEQ_LED_PinSet(seq_hwcfg_led.stop, !seq_running && !ui_seq_pause);
2537
  SEQ_LED_PinSet(seq_hwcfg_led.pause, ui_seq_pause && (!seq_core_slaveclk_mute || ui_cursor_flash));
240 tk 2538
 
492 tk 2539
  SEQ_LED_PinSet(seq_hwcfg_led.rew, seq_ui_button_state.REW);
2540
  SEQ_LED_PinSet(seq_hwcfg_led.fwd, seq_ui_button_state.FWD);
596 tk 2541
 
2542
  SEQ_LED_PinSet(seq_hwcfg_led.loop, seq_core_state.LOOP);
951 tk 2543
  SEQ_LED_PinSet(seq_hwcfg_led.follow, seq_core_state.FOLLOW);
134 tk 2544
 
678 tk 2545
  SEQ_LED_PinSet(seq_hwcfg_led.step_view, ui_page == SEQ_UI_PAGE_STEPSEL);
134 tk 2546
 
591 tk 2547
  SEQ_LED_PinSet(seq_hwcfg_led.select, seq_ui_button_state.SELECT_PRESSED);
492 tk 2548
  SEQ_LED_PinSet(seq_hwcfg_led.menu, seq_ui_button_state.MENU_PRESSED);
1203 tk 2549
  SEQ_LED_PinSet(seq_hwcfg_led.bookmark, ui_page == SEQ_UI_PAGE_BOOKMARKS);
134 tk 2550
 
596 tk 2551
  // handle double functions
2552
  if( seq_ui_button_state.MENU_PRESSED ) {
2553
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_core_state.LOOP);
951 tk 2554
    SEQ_LED_PinSet(seq_hwcfg_led.exit, seq_core_state.FOLLOW);
596 tk 2555
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.EXT_RESTART_REQ);
2556
  } else {
2557
    SEQ_LED_PinSet(seq_hwcfg_led.scrub, seq_ui_button_state.SCRUB);
951 tk 2558
    SEQ_LED_PinSet(seq_hwcfg_led.exit, ui_page == SEQ_UI_PAGE_MENU);
596 tk 2559
    SEQ_LED_PinSet(seq_hwcfg_led.metronome, seq_core_state.METRONOME);
2560
  }
2561
 
1313 tk 2562
  SEQ_LED_PinSet(seq_hwcfg_led.record, seq_record_state.ENABLED);
1219 tk 2563
  SEQ_LED_PinSet(seq_hwcfg_led.live, ui_page == SEQ_UI_PAGE_TRKLIVE);
630 tk 2564
 
492 tk 2565
  SEQ_LED_PinSet(seq_hwcfg_led.utility, ui_page == SEQ_UI_PAGE_UTIL);
2566
  SEQ_LED_PinSet(seq_hwcfg_led.copy, seq_ui_button_state.COPY);
2567
  SEQ_LED_PinSet(seq_hwcfg_led.paste, seq_ui_button_state.PASTE);
1014 tk 2568
  SEQ_LED_PinSet(seq_hwcfg_led.undo, seq_ui_button_state.UNDO);
492 tk 2569
  SEQ_LED_PinSet(seq_hwcfg_led.clear, seq_ui_button_state.CLEAR);
240 tk 2570
 
513 tk 2571
  SEQ_LED_PinSet(seq_hwcfg_led.tap_tempo, seq_ui_button_state.TAP_TEMPO);
678 tk 2572
  SEQ_LED_PinSet(seq_hwcfg_led.tempo_preset, ui_page == SEQ_UI_PAGE_BPM_PRESETS);
524 tk 2573
  SEQ_LED_PinSet(seq_hwcfg_led.ext_restart, seq_core_state.EXT_RESTART_REQ);
240 tk 2574
 
492 tk 2575
  SEQ_LED_PinSet(seq_hwcfg_led.down, seq_ui_button_state.DOWN);
2576
  SEQ_LED_PinSet(seq_hwcfg_led.up, seq_ui_button_state.UP);
240 tk 2577
 
167 tk 2578
 
1044 tk 2579
  // in MENU page: overrule GP LEDs as long as MENU button is pressed/active
306 tk 2580
  if( seq_ui_button_state.MENU_PRESSED ) {
2581
    if( ui_cursor_flash ) // if flashing flag active: no LED flag set
2582
      ui_gp_leds = 0x0000;
2583
    else {
2584
      int i;
2585
      u16 new_ui_gp_leds = 0x0000;
2586
      for(i=0; i<16; ++i)
2587
    if( ui_page == ui_shortcut_menu_pages[i] )
2588
      new_ui_gp_leds |= (1 << i);
2589
      ui_gp_leds = new_ui_gp_leds;
2590
    }
2591
  } else {
2592
    // note: the background function is permanently interrupted - therefore we write the GP pattern
2593
    // into a temporary variable, and take it over once completed
2594
    u16 new_ui_gp_leds = 0x0000;
2595
    // request GP LED values from current menu page
2596
    // will be transfered to DOUT registers in SEQ_UI_LED_Handler_Periodic
2597
    new_ui_gp_leds = 0x0000;
206 tk 2598
 
306 tk 2599
    if( ui_led_callback != NULL )
2600
      ui_led_callback(&new_ui_gp_leds);
167 tk 2601
 
306 tk 2602
    ui_gp_leds = new_ui_gp_leds;
2603
  }
2604
 
1020 tk 2605
  // update BLM LEDs
2606
  SEQ_BLM_LED_Update();
524 tk 2607
 
626 tk 2608
  // send LED changes in remote server mode
1316 tk 2609
  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 2610
    int first_sr = -1;
2611
    int last_sr = -1;
2612
    int sr;
2613
    for(sr=0; sr<SEQ_LED_NUM_SR; ++sr) {
2614
      u8 value = SEQ_LED_SRGet(sr);
2615
      if( value != remote_led_sr[sr] ) {
2616
    if( first_sr == -1 )
2617
      first_sr = sr;
2618
    last_sr = sr;
2619
    remote_led_sr[sr] = value;
2620
      }
2621
    }
2622
 
2623
    MIOS32_IRQ_Disable();
1316 tk 2624
    if( seq_midi_sysex_remote_force_led_update ) {
626 tk 2625
      first_sr = 0;
2626
      last_sr = SEQ_LED_NUM_SR-1;
2627
    }
1316 tk 2628
    seq_midi_sysex_remote_force_led_update = 0;
626 tk 2629
    MIOS32_IRQ_Enable();
2630
 
2631
    if( first_sr >= 0 )
2632
      SEQ_MIDI_SYSEX_REMOTE_Server_SendLED(first_sr, (u8 *)&remote_led_sr[first_sr], last_sr-first_sr+1);
2633
  }
2634
 
2635
 
134 tk 2636
  return 0; // no error
2637
}
2638
 
2639
 
2640
/////////////////////////////////////////////////////////////////////////////
2641
// updates high-prio LED functions (GP LEDs and Beat LED)
168 tk 2642
// called each mS
134 tk 2643
/////////////////////////////////////////////////////////////////////////////
2644
s32 SEQ_UI_LED_Handler_Periodic()
2645
{
625 tk 2646
  // ignore in remote client mode
1316 tk 2647
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2648
    return 0; // no error
2649
 
1044 tk 2650
  // ignore as long as hardware config hasn't been read
496 tk 2651
  if( !SEQ_FILE_HW_ConfigLocked() )