Subversion Repositories svn.mios32

Rev

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