Subversion Repositories svn.mios32

Rev

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