Subversion Repositories svn.mios32

Rev

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