Subversion Repositories svn.mios32

Rev

Rev 2301 | Rev 2322 | 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 2308 2016-02-14 19:30:07Z 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
 
2308 tk 1161
static s32 SEQ_UI_Button_Move(s32 depressed)
1162
{
1163
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1014 tk 1164
 
2308 tk 1165
  seq_ui_button_state.MOVE = depressed ? 0 : 1;
1166
 
1167
  if( !depressed ) {
1168
    prev_page = ui_page;
1169
    SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
1170
  }
1171
 
1172
  s32 status = SEQ_UI_UTIL_MoveButton(depressed);
1173
  if( depressed ) {
1174
    if( prev_page != SEQ_UI_PAGE_UTIL )
1175
      SEQ_UI_PageSet(prev_page);
1176
  }
1177
 
1178
  return status;
1179
}
1180
 
1181
static s32 SEQ_UI_Button_Scroll(s32 depressed)
1182
{
1183
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1184
 
1185
  seq_ui_button_state.SCROLL = depressed ? 0 : 1;
1186
 
1187
  if( !depressed ) {
1188
    prev_page = ui_page;
1189
    SEQ_UI_PageSet(SEQ_UI_PAGE_UTIL);
1190
  }
1191
 
1192
  s32 status = SEQ_UI_UTIL_ScrollButton(depressed);
1193
  if( depressed ) {
1194
    if( prev_page != SEQ_UI_PAGE_UTIL )
1195
      SEQ_UI_PageSet(prev_page);
1196
  }
1197
 
1198
  return status;
1199
}
1200
 
1201
 
134 tk 1202
static s32 SEQ_UI_Button_Menu(s32 depressed)
1203
{
513 tk 1204
  if( seq_hwcfg_button_beh.menu ) {
1205
    // toggle mode
1206
    if( depressed ) return -1; // ignore when button depressed
1207
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
678 tk 1208
    if( !seq_ui_button_state.MENU_PRESSED ) // due to page change: button going to be set, clear other toggle buttons
1209
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1210
    seq_ui_button_state.MENU_PRESSED ^= 1; // toggle MENU pressed (will also be released once GP button has been pressed)
1211
  } else {
1212
    // set mode
1213
    seq_ui_button_state.MENU_FIRST_PAGE_SELECTED = 0;
1214
    seq_ui_button_state.MENU_PRESSED = depressed ? 0 : 1;
1215
  }
134 tk 1216
 
1217
  return 0; // no error
1218
}
1219
 
1203 tk 1220
 
1221
static s32 SEQ_UI_Button_Bookmark(s32 depressed)
1222
{
1223
  if( seq_hwcfg_button_beh.bookmark ) {
1224
    if( depressed ) return -1; // ignore when button depressed
1225
    if( !seq_ui_button_state.BOOKMARK ) // due to page change: button going to be set, clear other toggle buttons
1226
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
1227
#if 0
1228
    seq_ui_button_state.BOOKMARK ^= 1; // toggle BOOKMARK pressed (will also be released once GP button has been pressed)
1229
#else
1230
    seq_ui_button_state.BOOKMARK = 1; // seems that it's better *not* to toggle!
1231
#endif
1232
  } else {
1233
    // set mode
1234
    seq_ui_button_state.BOOKMARK = depressed ? 0 : 1;
1235
  }
1236
 
1237
  if( seq_ui_button_state.BOOKMARK ) {
1238
    if( ui_page != SEQ_UI_PAGE_BOOKMARKS )
1239
      ui_page_before_bookmark = ui_page;
1240
    SEQ_UI_PageSet(SEQ_UI_PAGE_BOOKMARKS);
1241
  } else {
1242
    if( ui_page == SEQ_UI_PAGE_BOOKMARKS )
1243
      SEQ_UI_PageSet(ui_page_before_bookmark);
1244
  }
1245
 
1246
  return 0; // no error
1247
}
1248
 
1249
 
1205 tk 1250
static s32 SEQ_UI_Button_DirectBookmark(s32 depressed, u32 bookmark_button)
1251
{
1252
  if( !depressed )
1253
    ui_page_before_bookmark = ui_page;
1254
 
1255
  return SEQ_UI_BOOKMARKS_Button_Handler(bookmark_button, depressed);
1256
}
1257
 
1258
 
134 tk 1259
static s32 SEQ_UI_Button_Select(s32 depressed)
1260
{
1203 tk 1261
  // double function: -> Bookmark if menu button pressed
1262
  if( seq_ui_button_state.MENU_PRESSED )
1263
    return SEQ_UI_Button_Bookmark(depressed);
1264
 
168 tk 1265
  // forward to menu page
1877 tk 1266
  seq_ui_button_state.SELECT_PRESSED = depressed ? 0 : 1;
1267
  if( ui_button_callback != NULL ) {
1268
    ui_button_callback(SEQ_UI_BUTTON_Select, depressed);
1269
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
591 tk 1270
  }
134 tk 1271
 
1272
  return 0; // no error
1273
}
1274
 
1275
static s32 SEQ_UI_Button_Exit(s32 depressed)
1276
{
951 tk 1277
  // double function: -> Follow if menu button pressed
1278
  if( seq_ui_button_state.MENU_PRESSED )
1279
    return SEQ_UI_Button_Follow(depressed);
1280
 
272 tk 1281
  if( depressed ) return -1; // ignore when button depressed
1282
 
1283
  u8 prev_ui_page = ui_page;
1284
 
168 tk 1285
  // forward to menu page
1123 tk 1286
  if( ui_button_callback != NULL ) {
1287
    if( ui_button_callback(SEQ_UI_BUTTON_Exit, depressed) >= 1 )
1288
      return 1; // page has already handled exit button
740 tk 1289
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1290
  }
134 tk 1291
 
167 tk 1292
  // release all button states
984 tk 1293
  // seq_ui_button_state.ALL = 0;
1294
  // clashes with SOLO/ALL/etc.
167 tk 1295
 
272 tk 1296
  // enter menu page if we were not there before
1297
  if( prev_ui_page != SEQ_UI_PAGE_MENU )
1298
    SEQ_UI_PageSet(SEQ_UI_PAGE_MENU);
1299
 
134 tk 1300
  return 0; // no error
1301
}
1302
 
1303
static s32 SEQ_UI_Button_Edit(s32 depressed)
1304
{
741 tk 1305
  seq_ui_button_state.EDIT_PRESSED = depressed ? 0 : 1;
591 tk 1306
 
167 tk 1307
  // change to edit page
1350 tk 1308
  if( !depressed ) {
1309
    SEQ_UI_PageSet(SEQ_UI_PAGE_EDIT);
167 tk 1310
 
1350 tk 1311
    // set/clear encoder fast function if required
1312
    SEQ_UI_InitEncSpeed(1); // auto config
1313
  }
178 tk 1314
 
1350 tk 1315
  // EDIT button notification to button callback
1316
  // currently only used in EDIT page itself!
1317
  if( depressed && ui_page != SEQ_UI_PAGE_EDIT )
1318
    return -1;
1319
 
1320
  if( ui_button_callback != NULL ) {
1321
    ui_button_callback(SEQ_UI_BUTTON_Edit, depressed);
1322
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
1323
  }
1324
 
134 tk 1325
  return 0; // no error
1326
}
1327
 
1328
static s32 SEQ_UI_Button_Mute(s32 depressed)
1329
{
591 tk 1330
  seq_ui_button_state.MUTE_PRESSED = depressed ? 0 : 1;
1331
 
134 tk 1332
  if( depressed ) return -1; // ignore when button depressed
1333
 
184 tk 1334
  SEQ_UI_PageSet(SEQ_UI_PAGE_MUTE);
1335
 
134 tk 1336
  return 0; // no error
1337
}
1338
 
1339
static s32 SEQ_UI_Button_Pattern(s32 depressed)
1340
{
591 tk 1341
  seq_ui_button_state.PATTERN_PRESSED = depressed ? 0 : 1;
1342
 
134 tk 1343
  if( depressed ) return -1; // ignore when button depressed
1344
 
184 tk 1345
  SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN);
1346
 
134 tk 1347
  return 0; // no error
1348
}
1349
 
1454 midilab 1350
static s32 SEQ_UI_Button_Pattern_Remix(s32 depressed)
1351
{
1352
 
1353
    if ( ui_page == SEQ_UI_PAGE_PATTERN_RMX ) {
2161 tk 1354
#ifndef MIOS32_FAMILY_EMULATION
1454 midilab 1355
        // to avoid race conditions using the same button(any other way of solving that?)
1356
        vTaskDelay(60);
2161 tk 1357
#endif
1454 midilab 1358
        // a trick to use the same button with 2 functionalitys
1359
        ui_button_callback(SEQ_UI_BUTTON_Edit, depressed);
1360
    } else {
1361
        SEQ_UI_PageSet(SEQ_UI_PAGE_PATTERN_RMX);
1362
    }
1363
 
1364
    return 0; // no error
1365
 
1366
}
1367
 
134 tk 1368
static s32 SEQ_UI_Button_Song(s32 depressed)
1369
{
591 tk 1370
  seq_ui_button_state.SONG_PRESSED = depressed ? 0 : 1;
1371
 
134 tk 1372
  if( depressed ) return -1; // ignore when button depressed
1373
 
399 tk 1374
  SEQ_UI_PageSet(SEQ_UI_PAGE_SONG);
1375
 
134 tk 1376
  return 0; // no error
1377
}
1378
 
1379
static s32 SEQ_UI_Button_Solo(s32 depressed)
1380
{
513 tk 1381
  if( seq_hwcfg_button_beh.solo ) {
1382
    // toggle mode
1383
    if( depressed ) return -1; // ignore when button depressed
2110 tk 1384
    seq_ui_button_state.SOLO ^= 1;    
513 tk 1385
  } else {
1386
    // set mode
1387
    seq_ui_button_state.SOLO = depressed ? 0 : 1;
1388
  }
134 tk 1389
 
2110 tk 1390
  // seq_core_trk_soloed currently only used for the BLM16x16+X
1391
  // which overrules the legacy SOLO function
1392
  if( !seq_ui_button_state.SOLO )
1393
    seq_core_trk_soloed = 0;
1394
 
134 tk 1395
  return 0; // no error
1396
}
1397
 
1398
static s32 SEQ_UI_Button_Fast(s32 depressed)
1399
{
513 tk 1400
  if( seq_hwcfg_button_beh.fast ) {
1401
    // toggle mode
1402
    if( depressed ) return -1; // ignore when button depressed
1403
    seq_ui_button_state.FAST_ENCODERS ^= 1;
1404
  } else {
1405
    // set mode
1406
    seq_ui_button_state.FAST_ENCODERS = depressed ? 0 : 1;
1407
  }
134 tk 1408
 
178 tk 1409
  SEQ_UI_InitEncSpeed(0); // no auto config
1410
 
134 tk 1411
  return 0; // no error
1412
}
1413
 
1121 tk 1414
static s32 SEQ_UI_Button_Fast2(s32 depressed)
1415
{
1416
  if( seq_hwcfg_button_beh.fast2 ) {
1417
    // toggle mode
1418
    if( depressed ) return -1; // ignore when button depressed
1419
    seq_ui_button_state.FAST2_ENCODERS ^= 1;
1420
  } else {
1421
    // set mode
1422
    seq_ui_button_state.FAST2_ENCODERS = depressed ? 0 : 1;
1423
  }
1424
 
1425
  SEQ_UI_InitEncSpeed(0); // no auto config
1426
 
1427
  return 0; // no error
1428
}
1429
 
134 tk 1430
static s32 SEQ_UI_Button_All(s32 depressed)
1431
{
178 tk 1432
  seq_ui_button_state.CHANGE_ALL_STEPS_SAME_VALUE = depressed ? 0 : 1;
134 tk 1433
 
513 tk 1434
  if( seq_hwcfg_button_beh.all ) {
1435
    // toggle mode
1436
    if( depressed ) return -1;
1437
    seq_ui_button_state.CHANGE_ALL_STEPS ^= 1;
1438
  } else {
1439
    // set mode
1440
    seq_ui_button_state.CHANGE_ALL_STEPS = depressed ? 0 : 1;
1441
  }
178 tk 1442
 
134 tk 1443
  return 0; // no error
1444
}
1445
 
1446
static s32 SEQ_UI_Button_StepView(s32 depressed)
1447
{
600 tk 1448
  //  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1449
  // also used by seq_ui_stepsel
1450
 
513 tk 1451
  if( seq_hwcfg_button_beh.step_view ) {
1452
    if( depressed ) return -1; // ignore when button depressed
678 tk 1453
    if( !seq_ui_button_state.STEP_VIEW ) // due to page change: button going to be set, clear other toggle buttons
1454
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1455
    seq_ui_button_state.STEP_VIEW ^= 1; // toggle STEP_VIEW pressed (will also be released once GP button has been pressed)
1456
  } else {
1457
    // set mode
1458
    seq_ui_button_state.STEP_VIEW = depressed ? 0 : 1;
1459
  }
134 tk 1460
 
513 tk 1461
  if( seq_ui_button_state.STEP_VIEW ) {
600 tk 1462
    ui_stepview_prev_page = ui_page;
303 tk 1463
    SEQ_UI_PageSet(SEQ_UI_PAGE_STEPSEL);
1464
  } else {
524 tk 1465
    if( ui_page == SEQ_UI_PAGE_STEPSEL )
600 tk 1466
      SEQ_UI_PageSet(ui_stepview_prev_page);
303 tk 1467
  }
134 tk 1468
 
1469
  return 0; // no error
1470
}
1471
 
1713 tk 1472
static s32 SEQ_UI_Button_StepViewInc(s32 depressed)
1473
{
1474
  if( depressed ) return -1; // ignore when button depressed
1475
 
1476
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1477
  int num_steps = SEQ_TRG_NumStepsGet(visible_track);
1478
 
1479
  int new_step_view = ui_selected_step_view + 1;
1480
  if( (16*new_step_view) < num_steps ) {
1481
    // select new step view
1482
    ui_selected_step_view = new_step_view;
1483
 
1484
    // select step within view
1751 tk 1485
    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
1486
      ui_selected_step = (ui_selected_step_view << 4) | (ui_selected_step & 0xf);
1487
    }
1713 tk 1488
  }
1489
 
1490
  char buffer[20];
1491
  sprintf(buffer, "%d-%d", ui_selected_step_view*16 + 1, ui_selected_step_view*16 + 16);
1492
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Step View", buffer);
1493
 
1494
  return 0; // no error
1495
}
1496
 
1497
static s32 SEQ_UI_Button_StepViewDec(s32 depressed)
1498
{
1499
  if( depressed ) return -1; // ignore when button depressed
1500
 
1501
  int new_step_view = ui_selected_step_view - 1;
1502
  if( new_step_view >= 0 ) {
1503
    // select new step view
1504
    ui_selected_step_view = new_step_view;
1505
 
1506
    // select step within view
1751 tk 1507
    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
1508
      ui_selected_step = (ui_selected_step_view << 4) | (ui_selected_step & 0xf);
1509
    }
1713 tk 1510
  }
1511
 
1512
  char buffer[20];
1513
  sprintf(buffer, "%d-%d", ui_selected_step_view*16 + 1, ui_selected_step_view*16 + 16);
1514
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Step View", buffer);
1515
 
1516
  return 0; // no error
1517
}
1518
 
513 tk 1519
static s32 SEQ_UI_Button_TrackSel(s32 depressed)
134 tk 1520
{
513 tk 1521
  static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
134 tk 1522
 
513 tk 1523
  if( seq_hwcfg_button_beh.track_sel ) {
1524
    if( depressed ) return -1; // ignore when button depressed
678 tk 1525
    if( !seq_ui_button_state.TRACK_SEL ) // due to page change: button going to be set, clear other toggle buttons
1526
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1527
    seq_ui_button_state.TRACK_SEL ^= 1; // toggle TRACKSEL status (will also be released once GP button has been pressed)
1528
  } else {
1529
    seq_ui_button_state.TRACK_SEL = depressed ? 0 : 1;
1530
  }
1531
 
1532
  if( seq_ui_button_state.TRACK_SEL ) {
1533
    prev_page = ui_page;
1534
    SEQ_UI_PageSet(SEQ_UI_PAGE_TRACKSEL);
1535
  } else {
524 tk 1536
    if( ui_page == SEQ_UI_PAGE_TRACKSEL )
1537
      SEQ_UI_PageSet(prev_page);
513 tk 1538
  }
1539
 
134 tk 1540
  return 0; // no error
1541
}
1542
 
987 tk 1543
static s32 SEQ_UI_Button_Group(s32 depressed, u32 group)
1544
{
1545
  if( depressed ) return -1; // ignore when button depressed
1546
 
1547
  if( group >= 4 ) return -2; // max. 4 group buttons
1548
 
1549
  // in song page: track and group buttons are used to select the cursor position
1550
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1551
    ui_selected_item = 3 + group;
1552
    return 0;
1553
  }
1554
 
1555
  // if group has changed:
1556
  if( group != ui_selected_group ) {
1557
    // get current track selection
1558
    u16 old_tracks = ui_selected_tracks >> (4*ui_selected_group);
1559
 
1560
    // select new group
1561
    ui_selected_group = group;
1562
 
1563
    // take over old track selection
1564
    ui_selected_tracks = old_tracks << (4*ui_selected_group);
1565
  }
1566
 
1567
  // set/clear encoder fast function if required
1568
  SEQ_UI_InitEncSpeed(1); // auto config
1569
 
1570
  return 0; // no error
1571
}
1572
 
484 tk 1573
static s32 SEQ_UI_Button_Track(s32 depressed, u32 track_button)
134 tk 1574
{
484 tk 1575
  static u8 button_state = 0x0f; // all 4 buttons depressed
134 tk 1576
 
484 tk 1577
  if( track_button >= 4 ) return -2; // max. 4 track buttons
134 tk 1578
 
484 tk 1579
  if( depressed ) {
1580
    button_state |= (1 << track_button);
1581
    return 0; // no error
1582
  }
134 tk 1583
 
484 tk 1584
  button_state &= ~(1 << track_button);
1585
 
987 tk 1586
  // in pattern and song page: use track buttons as group buttons
1587
  if( ui_page == SEQ_UI_PAGE_PATTERN || ui_page == SEQ_UI_PAGE_SONG ) {
1588
    return SEQ_UI_Button_Group(depressed, track_button);
1589
  }
1590
 
484 tk 1591
  if( button_state == (~(1 << track_button) & 0xf) ) {
1592
    // if only one select button pressed: radio-button function (1 of 4)
1593
    ui_selected_tracks = 1 << (track_button + 4*ui_selected_group);
1594
  } else {
1595
    // if more than one select button pressed: toggle function (4 of 4)
1596
    ui_selected_tracks ^= 1 << (track_button + 4*ui_selected_group);
1597
  }
1598
 
178 tk 1599
  // set/clear encoder fast function if required
1600
  SEQ_UI_InitEncSpeed(1); // auto config
1601
 
134 tk 1602
  return 0; // no error
1603
}
1604
 
1146 tk 1605
static s32 SEQ_UI_Button_DirectTrack(s32 depressed, u32 track_button)
1606
{
1607
  static u16 button_state = 0xffff; // all 16 buttons depressed
1608
 
1609
  if( track_button >= 16 ) return -2; // max. 16 direct track buttons
1610
 
1611
  if( depressed ) {
1612
    button_state |= (1 << track_button);
1613
    return 0; // no error
1614
  }
1615
 
1616
  button_state &= ~(1 << track_button);
1617
 
1618
  if( button_state == (~(1 << track_button) & 0xffff) ) {
1619
    // if only one select button pressed: radio-button function (1 of 16)
1620
    ui_selected_tracks = 1 << track_button;
1488 tk 1621
    ui_selected_group = track_button / 4;
1146 tk 1622
  } else {
1623
    // if more than one select button pressed: toggle function (16 of 16)
1624
    ui_selected_tracks ^= 1 << track_button;
1625
  }
1626
 
1627
  // set/clear encoder fast function if required
1628
  SEQ_UI_InitEncSpeed(1); // auto config
1629
 
1630
  return 0; // no error
1631
}
1632
 
513 tk 1633
static s32 SEQ_UI_Button_ParLayerSel(s32 depressed)
1634
{
600 tk 1635
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1636
  // also used by seq_ui_parsel.c
513 tk 1637
 
1638
  if( seq_hwcfg_button_beh.par_layer ) {
1639
    if( depressed ) return -1; // ignore when button depressed
678 tk 1640
    if( !seq_ui_button_state.PAR_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1641
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1642
    seq_ui_button_state.PAR_LAYER_SEL ^= 1; // toggle PARSEL status (will also be released once GP button has been pressed)
1643
  } else {
1644
    seq_ui_button_state.PAR_LAYER_SEL = depressed ? 0 : 1;
1645
  }
1646
 
1647
  if( seq_ui_button_state.PAR_LAYER_SEL ) {
2168 tk 1648
    if( ui_page != SEQ_UI_PAGE_PARSEL ) {
1649
      ui_parlayer_prev_page = ui_page;
1650
      SEQ_UI_PageSet(SEQ_UI_PAGE_PARSEL);
1651
    }
513 tk 1652
  } else {
524 tk 1653
    if( ui_page == SEQ_UI_PAGE_PARSEL )
600 tk 1654
      SEQ_UI_PageSet(ui_parlayer_prev_page);
513 tk 1655
  }
1656
 
1657
  // set/clear encoder fast function if required
1658
  SEQ_UI_InitEncSpeed(1); // auto config
1659
 
1660
  return 0; // no error
1661
}
1662
 
134 tk 1663
static s32 SEQ_UI_Button_ParLayer(s32 depressed, u32 par_layer)
1664
{
1117 tk 1665
  static u8 layer_c_pressed = 0;
784 tk 1666
 
134 tk 1667
  if( par_layer >= 3 ) return -2; // max. 3 parlayer buttons
1668
 
1205 tk 1669
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1670
  u8 num_p_layers = SEQ_PAR_NumLayersGet(visible_track);
1671
 
987 tk 1672
  // in song page: parameter layer buttons are used to select the cursor position
1673
  if( ui_page == SEQ_UI_PAGE_SONG ) {
1674
    ui_selected_item = par_layer;
1675
    return 0;
1676
  }
1677
 
1205 tk 1678
  // drum mode in edit page: print parameter layer as long as button is pressed
1679
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1680
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1681
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1682
      ui_hold_msg_ctr = depressed ? 0 : ~0; // show value for at least 65 seconds... enough?
1683
    }
1684
  }
134 tk 1685
 
784 tk 1686
  // holding Layer C button allows to increment/decrement layer with A/B button
1687
  if( par_layer == 2 )
1688
    layer_c_pressed = !depressed;
1689
 
1690
  if( layer_c_pressed && par_layer == 0 ) {
333 tk 1691
    if( depressed ) return -1; // ignore when button depressed
784 tk 1692
    // increment layer
1693
    if( ++ui_selected_par_layer >= num_p_layers )
1694
      ui_selected_par_layer = 0;
1695
  } else if( layer_c_pressed && par_layer == 1 ) {
333 tk 1696
    if( depressed ) return -1; // ignore when button depressed
784 tk 1697
    // decrement layer
1698
    if( ui_selected_par_layer == 0 )
1699
      ui_selected_par_layer = num_p_layers - 1;
333 tk 1700
    else
784 tk 1701
      --ui_selected_par_layer;
333 tk 1702
  } else {
784 tk 1703
    if( num_p_layers <= 3 ) {
1704
      // 3 layers: direct selection with LayerA/B/C button
333 tk 1705
      if( depressed ) return -1; // ignore when button depressed
784 tk 1706
      if( par_layer >= num_p_layers ) {
1707
    char str1[21];
1708
    sprintf(str1, "Parameter Layer %c", 'A'+par_layer);
1709
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1710
      } else {
1711
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1712
    ui_selected_par_layer = par_layer;
1713
      }
1714
    } else if( num_p_layers <= 4 ) {
1715
      // 4 layers: LayerC Button toggles between C and D
1716
      if( depressed ) return -1; // ignore when button depressed
333 tk 1717
      seq_ui_button_state.PAR_LAYER_SEL = 0;
784 tk 1718
      if( par_layer == 2 )
1719
    ui_selected_par_layer = (ui_selected_par_layer == 2) ? 3 : 2;
1720
      else
1721
    ui_selected_par_layer = par_layer;
333 tk 1722
    } else {
784 tk 1723
      // >4 layers: LayerA/B button selects directly, Layer C button enters layer selection page
1724
      if( par_layer <= 1 ) {
1725
    if( depressed ) return -1; // ignore when button depressed
1726
    seq_ui_button_state.PAR_LAYER_SEL = 0;
1727
    ui_selected_par_layer = par_layer;
2168 tk 1728
 
1729
    if( ui_page == SEQ_UI_PAGE_PARSEL )
1730
      SEQ_UI_PageSet(ui_parlayer_prev_page);
784 tk 1731
      } else {
1732
    return SEQ_UI_Button_ParLayerSel(depressed);
1733
      }
333 tk 1734
    }
1735
  }
1736
 
178 tk 1737
  // set/clear encoder fast function if required
1738
  SEQ_UI_InitEncSpeed(1); // auto config
1739
 
134 tk 1740
  return 0; // no error
1741
}
1742
 
513 tk 1743
static s32 SEQ_UI_Button_TrgLayerSel(s32 depressed)
1744
{
600 tk 1745
  // static seq_ui_page_t prev_page = SEQ_UI_PAGE_NONE;
1746
  // also used by seq_ui_trgsel.c
513 tk 1747
 
1748
  if( seq_hwcfg_button_beh.trg_layer ) {
1749
    if( depressed ) return -1; // ignore when button depressed
678 tk 1750
    if( !seq_ui_button_state.TRG_LAYER_SEL ) // due to page change: button going to be set, clear other toggle buttons
1751
      seq_ui_button_state.PAGE_CHANGE_BUTTON_FLAGS = 0;
513 tk 1752
    seq_ui_button_state.TRG_LAYER_SEL ^= 1; // toggle TRGSEL status (will also be released once GP button has been pressed)
1753
  } else {
1754
    seq_ui_button_state.TRG_LAYER_SEL = depressed ? 0 : 1;
1755
  }
1756
 
1757
  if( seq_ui_button_state.TRG_LAYER_SEL ) {
2168 tk 1758
    if( ui_page != SEQ_UI_PAGE_TRGSEL ) {
1759
      ui_trglayer_prev_page = ui_page;
1760
      SEQ_UI_PageSet(SEQ_UI_PAGE_TRGSEL);
1761
    }
513 tk 1762
  } else {
524 tk 1763
    if( ui_page == SEQ_UI_PAGE_TRGSEL )
600 tk 1764
      SEQ_UI_PageSet(ui_trglayer_prev_page);
513 tk 1765
  }
1766
 
1767
  return 0; // no error
1768
}
1769
 
134 tk 1770
static s32 SEQ_UI_Button_TrgLayer(s32 depressed, u32 trg_layer)
1771
{
1117 tk 1772
  static u8 layer_c_pressed = 0;
784 tk 1773
 
134 tk 1774
  if( trg_layer >= 3 ) return -2; // max. 3 trglayer buttons
1775
 
326 tk 1776
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1777
  u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1778
  u8 num_t_layers = SEQ_TRG_NumLayersGet(visible_track);
134 tk 1779
 
1205 tk 1780
  // drum mode in edit page: ensure that trigger layer is print again
1781
  if( ui_page == SEQ_UI_PAGE_EDIT ) {
1782
    u8 event_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVENT_MODE);
1783
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1784
      if( !depressed )
1785
    ui_hold_msg_ctr = 0;
1786
    }
1787
  }
1788
 
784 tk 1789
  // holding Layer C button allows to increment/decrement layer with A/B button
1790
  if( trg_layer == 2 )
1791
    layer_c_pressed = !depressed;
1792
 
1793
  if( layer_c_pressed && trg_layer == 0 ) {
326 tk 1794
    if( depressed ) return -1; // ignore when button depressed
784 tk 1795
    // increment layer
1796
    if( ++ui_selected_trg_layer >= num_t_layers )
1797
      ui_selected_trg_layer = 0;
1798
  } else if( layer_c_pressed && trg_layer == 1 ) {
326 tk 1799
    if( depressed ) return -1; // ignore when button depressed
784 tk 1800
    // decrement layer
1801
    if( ui_selected_trg_layer == 0 )
1802
      ui_selected_trg_layer = num_t_layers - 1;
326 tk 1803
    else
784 tk 1804
      --ui_selected_trg_layer;
326 tk 1805
  } else {
784 tk 1806
    if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 3 ) {
1807
      // 3 layers: direct selection with LayerA/B/C button
326 tk 1808
      if( depressed ) return -1; // ignore when button depressed
784 tk 1809
      if( trg_layer >= num_t_layers ) {
1810
    char str1[21];
1811
    sprintf(str1, "Trigger Layer %c", 'A'+trg_layer);
1812
    SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, str1, "not available!");
1813
      } else {
1814
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1815
    ui_selected_trg_layer = trg_layer;
1816
      }
1817
    } else if( event_mode != SEQ_EVENT_MODE_Drum && num_t_layers <= 4 ) {
1818
      // 4 layers: LayerC Button toggles between C and D
1819
      if( depressed ) return -1; // ignore when button depressed
328 tk 1820
      seq_ui_button_state.TRG_LAYER_SEL = 0;
784 tk 1821
      if( trg_layer == 2 )
1822
    ui_selected_trg_layer = (ui_selected_trg_layer == 2) ? 3 : 2;
1823
      else
1824
    ui_selected_trg_layer = trg_layer;
326 tk 1825
    } else {
784 tk 1826
      // >4 layers or drum mode: LayerA/B button selects directly, Layer C button enters trigger selection page
1827
      // also used for drum tracks
1828
      if( trg_layer <= 1 ) {
1829
    if( depressed ) return -1; // ignore when button depressed
1830
    seq_ui_button_state.TRG_LAYER_SEL = 0;
1831
    ui_selected_trg_layer = trg_layer;
2168 tk 1832
 
1833
    if( ui_page == SEQ_UI_PAGE_TRGSEL )
1834
      SEQ_UI_PageSet(ui_trglayer_prev_page);
784 tk 1835
      } else {
1836
    return SEQ_UI_Button_TrgLayerSel(depressed);
1837
      }
326 tk 1838
    }
1839
  }
1840
 
134 tk 1841
  return 0; // no error
1842
}
1843
 
1844
 
1119 tk 1845
static s32 SEQ_UI_Button_Mixer(s32 depressed)
544 tk 1846
{
1847
  if( depressed ) return -1; // ignore when button depressed
134 tk 1848
 
1119 tk 1849
  SEQ_UI_PageSet(SEQ_UI_PAGE_MIXER);
544 tk 1850
 
1851
  return 0; // no error
1852
}
1853
 
1787 tk 1854
static s32 SEQ_UI_Button_Save(s32 depressed)
1855
{
1856
  if( depressed ) return -1; // ignore when button depressed
1857
 
1858
  u8 group = ui_selected_group;
1859
  seq_pattern_t pattern = seq_pattern[group];
1860
  s32 status;
1861
  if( (status=SEQ_PATTERN_Save(group, pattern)) < 0 ) {
1862
    SEQ_UI_SDCardErrMsg(2000, status);
1863
  } else {
1864
    char str1[21];
1865
    char str2[21];
1866
    sprintf(str1, "Track Group G%d", group + 1);
1867
    sprintf(str2, "stored into %d:%c%d", pattern.bank+1, (pattern.lower ? 'a' : 'A') + pattern.group, pattern.num + 1);
1868
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, str1, str2);
1869
  }
1870
 
1871
  return 0; // no error
1872
}
1873
 
1874
static s32 SEQ_UI_Button_SaveAll(s32 depressed)
1875
{
1876
  if( depressed ) return -1; // ignore when button depressed
1877
 
1878
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Complete Session", "stored!");
1879
  seq_ui_saveall_req = 1;
1880
 
1881
  return 0; // no error
1882
}
1883
 
1119 tk 1884
static s32 SEQ_UI_Button_TrackMode(s32 depressed)
544 tk 1885
{
1886
  if( depressed ) return -1; // ignore when button depressed
1887
 
1119 tk 1888
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMODE);
544 tk 1889
 
1890
  return 0; // no error
1891
}
1892
 
1119 tk 1893
static s32 SEQ_UI_Button_TrackGroove(s32 depressed)
544 tk 1894
{
1895
  if( depressed ) return -1; // ignore when button depressed
1896
 
1119 tk 1897
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKGRV);
1898
 
1899
  return 0; // no error
1900
}
1901
 
1902
static s32 SEQ_UI_Button_TrackLength(s32 depressed)
1903
{
1904
  if( depressed ) return -1; // ignore when button depressed
1905
 
1906
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKLEN);
1907
 
1908
  return 0; // no error
1909
}
1910
 
1911
static s32 SEQ_UI_Button_TrackDirection(s32 depressed)
1912
{
1913
  if( depressed ) return -1; // ignore when button depressed
1914
 
1915
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKDIR);
1916
 
1917
  return 0; // no error
1918
}
1919
 
1920
static s32 SEQ_UI_Button_TrackMorph(s32 depressed)
1921
{
1922
  if( depressed ) return -1; // ignore when button depressed
1923
 
1924
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKMORPH);
1925
 
1926
  return 0; // no error
1927
}
1928
 
1929
static s32 SEQ_UI_Button_TrackTranspose(s32 depressed)
1930
{
1931
  if( depressed ) return -1; // ignore when button depressed
1932
 
544 tk 1933
  SEQ_UI_PageSet(SEQ_UI_PAGE_TRKTRAN);
1934
 
1935
  return 0; // no error
1936
}
1937
 
2294 tk 1938
static s32 SEQ_UI_Button_Fx(s32 depressed)
1939
{
1940
  if( depressed ) return -1; // ignore when button depressed
1941
 
1942
  SEQ_UI_PageSet(SEQ_UI_PAGE_FX);
1943
 
1944
  return 0; // no error
1945
}
1946
 
1811 tk 1947
static s32 SEQ_UI_Button_MuteAllTracks(s32 depressed)
1948
{
1949
  if( depressed ) return -1; // ignore when button depressed
1950
  seq_core_trk_muted = 0xffff;
1814 tk 1951
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Tracks", "muted");
1811 tk 1952
  return 0; // no error
1953
}
544 tk 1954
 
1811 tk 1955
static s32 SEQ_UI_Button_MuteTrackLayers(s32 depressed)
1956
{
1957
  if( depressed ) return -1; // ignore when button depressed
1958
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1959
  seq_core_trk[visible_track].layer_muted = 0xffff;
1814 tk 1960
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "of current Track muted");
1811 tk 1961
  return 0; // no error
1962
}
1963
 
1964
static s32 SEQ_UI_Button_MuteAllTracksAndLayers(s32 depressed)
1965
{
1966
  if( depressed ) return -1; // ignore when button depressed
1967
  int track;
1968
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1969
    seq_core_trk[track].layer_muted = 0xffff;
1970
  seq_core_trk_muted = 0xffff;
1814 tk 1971
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "and Tracks muted");
1811 tk 1972
  return 0; // no error
1973
}
1974
 
1975
static s32 SEQ_UI_Button_UnMuteAllTracks(s32 depressed)
1976
{
1977
  if( depressed ) return -1; // ignore when button depressed
1814 tk 1978
  seq_core_trk_muted = 0x0000;
1979
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Tracks", "unmuted");
1811 tk 1980
  return 0; // no error
1981
}
1982
 
1983
static s32 SEQ_UI_Button_UnMuteTrackLayers(s32 depressed)
1984
{
1985
  if( depressed ) return -1; // ignore when button depressed
1986
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1814 tk 1987
  seq_core_trk[visible_track].layer_muted = 0x0000;
1988
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "of current Track unmuted");
1811 tk 1989
  return 0; // no error
1990
}
1991
 
1992
static s32 SEQ_UI_Button_UnMuteAllTracksAndLayers(s32 depressed)
1993
{
1994
  if( depressed ) return -1; // ignore when button depressed
1995
  int track;
1996
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
1814 tk 1997
    seq_core_trk[track].layer_muted = 0x0000;
1998
  seq_core_trk_muted = 0x0000;
1999
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "All Layers", "and Tracks unmuted");
1811 tk 2000
  return 0; // no error
2001
}
2002
 
742 tk 2003
// only used by keyboard remote function
2004
static s32 SEQ_UI_Button_ToggleGate(s32 depressed)
2005
{
2006
  if( depressed ) return -1; // ignore when button depressed
544 tk 2007
 
742 tk 2008
  u8 visible_track = SEQ_UI_VisibleTrackGet();
2009
  u8 gate = SEQ_TRG_GateGet(visible_track, ui_selected_step, ui_selected_instrument) ? 0 : 1;
2010
  SEQ_TRG_GateSet(visible_track, ui_selected_step, ui_selected_instrument, gate);
544 tk 2011
 
742 tk 2012
  return 0; // no error
2013
}
2014
 
1349 tk 2015
static s32 SEQ_UI_Button_FootSwitch(s32 depressed)
2016
{
2017
  // static variables (only used here, therefore local)
2018
  static u32 fs_time_control = 0; // timestamp of last operation
742 tk 2019
 
1349 tk 2020
  // this is used as a constant value
2079 midilab 2021
  u32 fs_time_delay = 500; // mS - should this be configurable?
742 tk 2022
 
2079 midilab 2023
  // Clear track check
2024
  if( depressed ) {
2025
        // if footswitch time passed between pressed and depressed is less than fs_time_delay miliseconds, clear track.
2026
    if( ( MIOS32_TIMESTAMP_GetDelay(fs_time_control) < fs_time_delay ) && ( fs_time_control != 0 ) )
1349 tk 2027
    {
2079 midilab 2028
            SEQ_UI_Button_Clear_Track(0);
1349 tk 2029
    }
2030
  } else {
2079 midilab 2031
        // store pressed timestamp
2032
        fs_time_control = MIOS32_TIMESTAMP_Get();
1349 tk 2033
  }
2034
 
2079 midilab 2035
    // PUNCH_IN, PUNCH_OUT
1349 tk 2036
  if( depressed ) {
2037
    // disable recording
2168 tk 2038
    SEQ_RECORD_Enable(0, 1);
1349 tk 2039
  } else {
2040
    // enable recording
2168 tk 2041
    SEQ_RECORD_Enable(1, 1);
1349 tk 2042
    seq_record_state.ARMED_TRACKS = ui_selected_tracks; // not used yet, just preparation for future changes
2043
  }
2044
 
2045
  return 0; // no error
2046
}
2047
 
2048
 
134 tk 2049
/////////////////////////////////////////////////////////////////////////////
2050
// Button handler
2051
/////////////////////////////////////////////////////////////////////////////
2052
s32 SEQ_UI_Button_Handler(u32 pin, u32 pin_value)
2053
{
492 tk 2054
  int i;
2055
 
625 tk 2056
  // send MIDI event in remote mode and exit
1316 tk 2057
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2058
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendButton(pin, pin_value);
2059
 
1044 tk 2060
  // ignore as long as hardware config hasn't been read
496 tk 2061
  if( !SEQ_FILE_HW_ConfigLocked() )
2062
    return -1;
2063
 
740 tk 2064
  // ignore during a backup or format is created
2065
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 2066
    return -1;
2067
 
328 tk 2068
  // ensure that selections are matching with track constraints
2069
  SEQ_UI_CheckSelections();
2070
 
492 tk 2071
  // request display update
2072
  seq_ui_display_update_req = 1;
134 tk 2073
 
596 tk 2074
  // stop current message if (new) button has been pressed
2075
  if( pin_value == 0 )
2076
    SEQ_UI_MsgStop();
134 tk 2077
 
596 tk 2078
 
492 tk 2079
  // MEMO: we could also use a jump table with references to the functions
2080
  // here, but this "spagetthi code" simplifies the configuration and
2081
  // the resulting ASM doesn't look that bad!
168 tk 2082
 
492 tk 2083
  for(i=0; i<SEQ_HWCFG_NUM_GP; ++i)
2084
    if( pin == seq_hwcfg_button.gp[i] )
2085
      return SEQ_UI_Button_GP(pin_value, i);
134 tk 2086
 
492 tk 2087
  for(i=0; i<SEQ_HWCFG_NUM_TRACK; ++i)
2088
    if( pin == seq_hwcfg_button.track[i] )
2089
      return SEQ_UI_Button_Track(pin_value, i);
1146 tk 2090
 
2091
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_TRACK; ++i)
2092
    if( pin == seq_hwcfg_button.direct_track[i] )
2093
      return SEQ_UI_Button_DirectTrack(pin_value, i);
2094
 
1205 tk 2095
  for(i=0; i<SEQ_HWCFG_NUM_DIRECT_BOOKMARK; ++i)
2096
    if( pin == seq_hwcfg_button.direct_bookmark[i] )
2097
      return SEQ_UI_Button_DirectBookmark(pin_value, i);
2098
 
513 tk 2099
  if( pin == seq_hwcfg_button.track_sel )
2100
    return SEQ_UI_Button_TrackSel(pin_value);
134 tk 2101
 
492 tk 2102
  for(i=0; i<SEQ_HWCFG_NUM_GROUP; ++i)
2103
    if( pin == seq_hwcfg_button.group[i] )
2104
      return SEQ_UI_Button_Group(pin_value, i);
134 tk 2105
 
492 tk 2106
  for(i=0; i<SEQ_HWCFG_NUM_PAR_LAYER; ++i)
2107
    if( pin == seq_hwcfg_button.par_layer[i] )
2108
      return SEQ_UI_Button_ParLayer(pin_value, i);
513 tk 2109
  if( pin == seq_hwcfg_button.par_layer_sel )
2110
    return SEQ_UI_Button_ParLayerSel(pin_value);
134 tk 2111
 
492 tk 2112
  for(i=0; i<SEQ_HWCFG_NUM_TRG_LAYER; ++i)
2113
    if( pin == seq_hwcfg_button.trg_layer[i] )
2114
      return SEQ_UI_Button_TrgLayer(pin_value, i);
513 tk 2115
  if( pin == seq_hwcfg_button.trg_layer_sel )
2116
    return SEQ_UI_Button_TrgLayerSel(pin_value);
134 tk 2117
 
492 tk 2118
  if( pin == seq_hwcfg_button.left )
2119
    return SEQ_UI_Button_Left(pin_value);
2120
  if( pin == seq_hwcfg_button.right )
2121
    return SEQ_UI_Button_Right(pin_value);
2122
  if( pin == seq_hwcfg_button.down )
2123
    return SEQ_UI_Button_Down(pin_value);
2124
  if( pin == seq_hwcfg_button.up )
2125
    return SEQ_UI_Button_Up(pin_value);
134 tk 2126
 
492 tk 2127
  if( pin == seq_hwcfg_button.scrub )
2128
    return SEQ_UI_Button_Scrub(pin_value);
2129
  if( pin == seq_hwcfg_button.metronome )
2130
    return SEQ_UI_Button_Metronome(pin_value);
134 tk 2131
 
630 tk 2132
  if( pin == seq_hwcfg_button.record )
2133
    return SEQ_UI_Button_Record(pin_value);
1219 tk 2134
  if( pin == seq_hwcfg_button.live )
2135
    return SEQ_UI_Button_Live(pin_value);
630 tk 2136
 
492 tk 2137
  if( pin == seq_hwcfg_button.stop )
2138
    return SEQ_UI_Button_Stop(pin_value);
2139
  if( pin == seq_hwcfg_button.pause )
2140
    return SEQ_UI_Button_Pause(pin_value);
2141
  if( pin == seq_hwcfg_button.play )
2142
    return SEQ_UI_Button_Play(pin_value);
2143
  if( pin == seq_hwcfg_button.rew )
2144
    return SEQ_UI_Button_Rew(pin_value);
2145
  if( pin == seq_hwcfg_button.fwd )
2146
    return SEQ_UI_Button_Fwd(pin_value);
596 tk 2147
  if( pin == seq_hwcfg_button.loop )
2148
    return SEQ_UI_Button_Loop(pin_value);
973 tk 2149
  if( pin == seq_hwcfg_button.follow )
2150
    return SEQ_UI_Button_Follow(pin_value);
134 tk 2151
 
492 tk 2152
  if( pin == seq_hwcfg_button.utility )
2153
    return SEQ_UI_Button_Utility(pin_value);
2154
  if( pin == seq_hwcfg_button.copy )
2155
    return SEQ_UI_Button_Copy(pin_value);
2156
  if( pin == seq_hwcfg_button.paste )
2157
    return SEQ_UI_Button_Paste(pin_value);
2158
  if( pin == seq_hwcfg_button.clear )
2159
    return SEQ_UI_Button_Clear(pin_value);
1014 tk 2160
  if( pin == seq_hwcfg_button.undo )
2161
    return SEQ_UI_Button_Undo(pin_value);
2308 tk 2162
  if( pin == seq_hwcfg_button.move )
2163
    return SEQ_UI_Button_Move(pin_value);
2164
  if( pin == seq_hwcfg_button.scroll )
2165
    return SEQ_UI_Button_Scroll(pin_value);
134 tk 2166
 
492 tk 2167
  if( pin == seq_hwcfg_button.menu )
2168
    return SEQ_UI_Button_Menu(pin_value);
1203 tk 2169
  if( pin == seq_hwcfg_button.bookmark )
2170
    return SEQ_UI_Button_Bookmark(pin_value);
492 tk 2171
  if( pin == seq_hwcfg_button.select )
2172
    return SEQ_UI_Button_Select(pin_value);
2173
  if( pin == seq_hwcfg_button.exit )
2174
    return SEQ_UI_Button_Exit(pin_value);
134 tk 2175
 
513 tk 2176
  if( pin == seq_hwcfg_button.tap_tempo )
2177
    return SEQ_UI_Button_TapTempo(pin_value);
2178
  if( pin == seq_hwcfg_button.tempo_preset )
2179
    return SEQ_UI_Button_TempoPreset(pin_value);
524 tk 2180
  if( pin == seq_hwcfg_button.ext_restart )
2181
    return SEQ_UI_Button_ExtRestart(pin_value);
134 tk 2182
 
492 tk 2183
  if( pin == seq_hwcfg_button.edit )
2184
    return SEQ_UI_Button_Edit(pin_value);
2185
  if( pin == seq_hwcfg_button.mute )
2186
    return SEQ_UI_Button_Mute(pin_value);
2187
  if( pin == seq_hwcfg_button.pattern )
2188
    return SEQ_UI_Button_Pattern(pin_value);
2189
  if( pin == seq_hwcfg_button.song )
2190
    return SEQ_UI_Button_Song(pin_value);
134 tk 2191
 
492 tk 2192
  if( pin == seq_hwcfg_button.solo )
2193
    return SEQ_UI_Button_Solo(pin_value);
2194
  if( pin == seq_hwcfg_button.fast )
2195
    return SEQ_UI_Button_Fast(pin_value);
1121 tk 2196
  if( pin == seq_hwcfg_button.fast2 )
2197
    return SEQ_UI_Button_Fast2(pin_value);
492 tk 2198
  if( pin == seq_hwcfg_button.all )
2199
    return SEQ_UI_Button_All(pin_value);
134 tk 2200
 
492 tk 2201
  if( pin == seq_hwcfg_button.step_view )
2202
    return SEQ_UI_Button_StepView(pin_value);
134 tk 2203
 
544 tk 2204
  if( pin == seq_hwcfg_button.mixer )
2205
    return SEQ_UI_Button_Mixer(pin_value);
2206
 
1787 tk 2207
  if( pin == seq_hwcfg_button.save )
2208
    return SEQ_UI_Button_Save(pin_value);
2209
  if( pin == seq_hwcfg_button.save_all )
2210
    return SEQ_UI_Button_SaveAll(pin_value);
2211
 
1119 tk 2212
  if( pin == seq_hwcfg_button.track_mode )
2213
    return SEQ_UI_Button_TrackMode(pin_value);
2214
  if( pin == seq_hwcfg_button.track_groove )
2215
    return SEQ_UI_Button_TrackGroove(pin_value);
2216
  if( pin == seq_hwcfg_button.track_length )
2217
    return SEQ_UI_Button_TrackLength(pin_value);
2218
  if( pin == seq_hwcfg_button.track_direction )
2219
    return SEQ_UI_Button_TrackDirection(pin_value);
2220
  if( pin == seq_hwcfg_button.track_morph )
2221
    return SEQ_UI_Button_TrackMorph(pin_value);
2222
  if( pin == seq_hwcfg_button.track_transpose )
2223
    return SEQ_UI_Button_TrackTranspose(pin_value);
2294 tk 2224
  if( pin == seq_hwcfg_button.fx )
2225
    return SEQ_UI_Button_Fx(pin_value);
1349 tk 2226
  if( pin == seq_hwcfg_button.footswitch )
2227
    return SEQ_UI_Button_FootSwitch(pin_value);
1454 midilab 2228
  if( pin == seq_hwcfg_button.pattern_remix )
2229
    return SEQ_UI_Button_Pattern_Remix(pin_value);
1811 tk 2230
 
2231
  if( pin == seq_hwcfg_button.mute_all_tracks )
2232
    return SEQ_UI_Button_MuteAllTracks(pin_value);
2233
  if( pin == seq_hwcfg_button.mute_track_layers )
2234
    return SEQ_UI_Button_MuteTrackLayers(pin_value);
2235
  if( pin == seq_hwcfg_button.mute_all_tracks_and_layers )
2236
    return SEQ_UI_Button_MuteAllTracksAndLayers(pin_value);
2237
  if( pin == seq_hwcfg_button.unmute_all_tracks )
2238
    return SEQ_UI_Button_UnMuteAllTracks(pin_value);
2239
  if( pin == seq_hwcfg_button.unmute_track_layers )
2240
    return SEQ_UI_Button_UnMuteTrackLayers(pin_value);
2241
  if( pin == seq_hwcfg_button.unmute_all_tracks_and_layers )
2242
    return SEQ_UI_Button_UnMuteAllTracksAndLayers(pin_value);
2243
 
625 tk 2244
  // always print debugging message
2245
#if 1
1081 tk 2246
  MUTEX_MIDIOUT_TAKE;
2247
  DEBUG_MSG("[SEQ_UI_Button_Handler] Button SR:%d, Pin:%d not mapped, it has been %s.\n",
2248
        (pin >> 3) + 1,
2249
        pin & 7,
2250
        pin_value ? "depressed" : "pressed");
2251
  MUTEX_MIDIOUT_GIVE;
625 tk 2252
#endif
2253
 
492 tk 2254
  return -1; // button not mapped
134 tk 2255
}
2256
 
2257
 
2258
/////////////////////////////////////////////////////////////////////////////
524 tk 2259
// BLM Button handler
2260
/////////////////////////////////////////////////////////////////////////////
2261
s32 SEQ_UI_BLM_Button_Handler(u32 row, u32 pin, u32 pin_value)
2262
{
625 tk 2263
  // send MIDI event in remote mode and exit
1316 tk 2264
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2265
    return SEQ_MIDI_SYSEX_REMOTE_Client_Send_BLM_Button(row, pin, pin_value);
2266
 
1044 tk 2267
  // ignore as long as hardware config hasn't been read
524 tk 2268
  if( !SEQ_FILE_HW_ConfigLocked() )
2269
    return -1;
2270
 
740 tk 2271
  // ignore during a backup or format is created
2272
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 2273
    return -1;
2274
 
524 tk 2275
  if( row >= SEQ_CORE_NUM_TRACKS_PER_GROUP )
2276
    return -1; // more than 4 tracks not supported (yet) - could be done in this function w/o much effort
2277
 
2278
  if( pin >= 16 )
2279
    return -1; // more than 16 step buttons not supported (yet) - could be done by selecting the step view
2280
 
2281
  // select track depending on row
2282
  ui_selected_tracks = 1 << (row + 4*ui_selected_group);
2283
 
2284
  // ensure that selections are matching with track constraints
2285
  SEQ_UI_CheckSelections();
2286
 
2287
  // request display update
2288
  seq_ui_display_update_req = 1;
2289
 
2290
  // emulate general purpose button
758 tk 2291
  if( seq_hwcfg_blm.buttons_no_ui ) {
763 tk 2292
    s32 status = SEQ_UI_EDIT_Button_Handler(pin, pin_value);
758 tk 2293
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0;
2294
    return status;
763 tk 2295
  }
2296
 
2297
  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 2298
}
2299
 
2300
 
2301
/////////////////////////////////////////////////////////////////////////////
134 tk 2302
// Encoder handler
2303
/////////////////////////////////////////////////////////////////////////////
2304
s32 SEQ_UI_Encoder_Handler(u32 encoder, s32 incrementer)
2305
{
625 tk 2306
  // send MIDI event in remote mode and exit
1316 tk 2307
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2308
    return SEQ_MIDI_SYSEX_REMOTE_Client_SendEncoder(encoder, incrementer);
2309
 
1044 tk 2310
  // ignore as long as hardware config hasn't been read
496 tk 2311
  if( !SEQ_FILE_HW_ConfigLocked() )
2312
    return -1;
2313
 
740 tk 2314
  // ignore during a backup or format is created
2315
  if( seq_ui_backup_req || seq_ui_format_req )
634 tk 2316
    return -1;
2317
 
1341 tk 2318
  if( encoder >= SEQ_HWCFG_NUM_ENCODERS )
134 tk 2319
    return -1; // encoder doesn't exist
2320
 
328 tk 2321
  // ensure that selections are matching with track constraints
2322
  SEQ_UI_CheckSelections();
2323
 
596 tk 2324
  // stop current message
2325
  SEQ_UI_MsgStop();
2326
 
134 tk 2327
  // limit incrementer
2328
  if( incrementer > 3 )
2329
    incrementer = 3;
2330
  else if( incrementer < -3 )
2331
    incrementer = -3;
2332
 
1341 tk 2333
  // encoder 17 increments BPM
2334
  if( encoder == 17 ) {
2335
    u16 value = (u16)(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num]*10);
2336
    if( SEQ_UI_Var16_Inc(&value, 25, 3000, incrementer) ) { // at 384ppqn, the minimum BPM rate is ca. 2.5
2337
      // set new BPM
2338
      seq_core_bpm_preset_tempo[seq_core_bpm_preset_num] = (float)value/10.0;
2339
      SEQ_CORE_BPM_Update(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num], seq_core_bpm_preset_ramp[seq_core_bpm_preset_num]);
2340
      //store_file_required = 1;
2341
      seq_ui_display_update_req = 1;      
2342
    }
2343
    return 0;
2344
  }
2345
 
607 tk 2346
  if( seq_ui_button_state.SCRUB && encoder == 0 ) {
2347
    // if sequencer isn't already running, continue it (don't restart)
2348
    if( !SEQ_BPM_IsRunning() )
2349
      SEQ_BPM_Cont();
2350
    ui_seq_pause = 0; // clear pause mode
1278 tk 2351
 
607 tk 2352
    // Scrub sequence back or forth
2353
    portENTER_CRITICAL(); // should be atomic
2354
    SEQ_CORE_Scrub(incrementer);
2355
    portEXIT_CRITICAL();
2356
  } else if( !seq_ui_button_state.MENU_PRESSED && ui_encoder_callback != NULL ) {
173 tk 2357
    ui_encoder_callback((encoder == 0) ? SEQ_UI_ENCODER_Datawheel : (encoder-1), incrementer);
740 tk 2358
    ui_cursor_flash_ctr = ui_cursor_flash_overrun_ctr = 0; // ensure that value is visible when it has been changed
134 tk 2359
  }
2360
 
2361
  // request display update
159 tk 2362
  seq_ui_display_update_req = 1;
134 tk 2363
 
2364
  return 0; // no error
2365
}
2366
 
2367
 
353 tk 2368
 
134 tk 2369
/////////////////////////////////////////////////////////////////////////////
626 tk 2370
// Receives a MIDI package from APP_NotifyReceivedEvent (-> app.c)
2371
/////////////////////////////////////////////////////////////////////////////
2372
s32 SEQ_UI_REMOTE_MIDI_Receive(mios32_midi_port_t port, mios32_midi_package_t midi_package)
2373
{
2374
#if 1
2375
  // check for active remote mode
1316 tk 2376
  if( seq_midi_sysex_remote_active_mode != SEQ_MIDI_SYSEX_REMOTE_MODE_SERVER )
626 tk 2377
    return 0; // no error
2378
#endif
2379
 
1316 tk 2380
  if( (seq_midi_sysex_remote_port == DEFAULT && seq_midi_sysex_remote_active_port != port) ||
2381
      (seq_midi_sysex_remote_port != DEFAULT && port != seq_midi_sysex_remote_port) )
626 tk 2382
    return 0; // wrong port
2383
 
2384
  // for easier parsing: convert Note Off -> Note On with velocity 0
2385
  if( midi_package.event == NoteOff ) {
2386
    midi_package.event = NoteOn;
2387
    midi_package.velocity = 0;
2388
  }
2389
 
2390
  switch( midi_package.event ) {
2391
    case NoteOn: {
2392
      switch( midi_package.chn ) {
2393
        case Chn1:
2394
      SEQ_UI_Button_Handler(midi_package.note + 0x00, midi_package.velocity ? 0 : 1);
2395
      break;
2396
        case Chn2:
2397
      SEQ_UI_Button_Handler(midi_package.note + 0x80, midi_package.velocity ? 0 : 1);
2398
      break;
2399
        case Chn3:
2400
      SEQ_UI_BLM_Button_Handler(midi_package.note >> 5, midi_package.note & 0x1f, midi_package.velocity ? 0 : 1);
2401
      break;
2402
      }
2403
    } break;
2404
 
2405
    case CC: {
2406
      if( midi_package.cc_number >= 15 && midi_package.cc_number <= 31 )
2407
    SEQ_UI_Encoder_Handler(midi_package.cc_number-15, (int)midi_package.value - 0x40);
2408
    } break;
2409
  }
2410
 
632 tk 2411
  return 1; // MIDI event has been taken for remote function -> don't forward to router/MIDI event parser
626 tk 2412
}
2413
 
2414
 
2415
/////////////////////////////////////////////////////////////////////////////
741 tk 2416
// MIDI Remote Keyboard Function (called from SEQ_MIDI_IN)
2417
/////////////////////////////////////////////////////////////////////////////
742 tk 2418
s32 SEQ_UI_REMOTE_MIDI_Keyboard(u8 key, u8 depressed)
741 tk 2419
{
742 tk 2420
#if 0
1316 tk 2421
  MIOS32_MIDI_SendDebugMessage("SEQ_MIDI_SYSEX_REMOTE_MIDI_Keyboard(%d, %d)\n", key, depressed);
741 tk 2422
#endif
742 tk 2423
 
2424
  switch( key ) {
2425
    case 0x24: // C-2
2426
      return SEQ_UI_Button_GP(depressed, 0);
2427
    case 0x25: // C#2
2428
      return SEQ_UI_Button_Track(depressed, 0);
2429
    case 0x26: // D-2
2430
      return SEQ_UI_Button_GP(depressed, 1);
2431
    case 0x27: // D#2
2432
      return SEQ_UI_Button_Track(depressed, 1);
2433
    case 0x28: // E-2
2434
      return SEQ_UI_Button_GP(depressed, 2);
2435
    case 0x29: // F-2
2436
      return SEQ_UI_Button_GP(depressed, 3);
2437
    case 0x2a: // F#2
2438
      return SEQ_UI_Button_Track(depressed, 2);
2439
    case 0x2b: // G-2
2440
      return SEQ_UI_Button_GP(depressed, 4);
2441
    case 0x2c: // G#2
2442
      return SEQ_UI_Button_Track(depressed, 3);
2443
    case 0x2d: // A-2
2444
      return SEQ_UI_Button_GP(depressed, 5);
2445
    case 0x2e: // A#2
2446
      return SEQ_UI_Button_ParLayer(depressed, 0);
2447
    case 0x2f: // B-2
2448
      return SEQ_UI_Button_GP(depressed, 6);
2449
 
2450
    case 0x30: // C-3
2451
      return SEQ_UI_Button_GP(depressed, 7);
2452
    case 0x31: // C#3
2453
      return SEQ_UI_Button_ParLayer(depressed, 1);
2454
    case 0x32: // D-3
2455
      return SEQ_UI_Button_GP(depressed, 8);
2456
    case 0x33: // D#3
2457
      return SEQ_UI_Button_ParLayer(depressed, 2);
2458
    case 0x34: // E-3
2459
      return SEQ_UI_Button_GP(depressed, 9);
2460
    case 0x35: // F-3
2461
      return SEQ_UI_Button_GP(depressed, 10);
2462
    case 0x36: // F#3
2463
      return SEQ_UI_Button_TrgLayer(depressed, 0);
2464
    case 0x37: // G-3
2465
      return SEQ_UI_Button_GP(depressed, 11);
2466
    case 0x38: // G#3
2467
      return SEQ_UI_Button_TrgLayer(depressed, 1);
2468
    case 0x39: // A-3
2469
      return SEQ_UI_Button_GP(depressed, 12);
2470
    case 0x3a: // A#3
2471
      return SEQ_UI_Button_TrgLayer(depressed, 2);
2472
    case 0x3b: // B-3
2473
      return SEQ_UI_Button_GP(depressed, 13);
2474
 
2475
    case 0x3c: // C-4
2476
      return SEQ_UI_Button_GP(depressed, 14);
2477
    case 0x3d: // C#4
2478
      return SEQ_UI_Button_Group(depressed, 0);
2479
    case 0x3e: // D-4
2480
      return SEQ_UI_Button_GP(depressed, 15);
2481
    case 0x3f: // D#4
2482
      return SEQ_UI_Button_Group(depressed, 1);
2483
    case 0x40: // E-4
2484
      return 0; // ignore
2485
    case 0x41: // F-4
2486
      return SEQ_UI_Button_StepView(depressed);
2487
    case 0x42: // F#4
2162 tk 2488
      return SEQ_UI_Button_Group(depressed, 2);
742 tk 2489
    case 0x43: // G-4
2490
      return 0; // ignore
2491
    case 0x44: // G#4
2162 tk 2492
      return SEQ_UI_Button_Group(depressed, 3);
742 tk 2493
    case 0x45: // A-4
2494
      return SEQ_UI_Button_Left(depressed);
2495
    case 0x46: // A#4
2496
      return SEQ_UI_Button_ToggleGate(depressed);
2497
    case 0x47: // B-4
2498
      return SEQ_UI_Button_Right(depressed);
2499
 
2500
    case 0x48: // C-5
2501
      return SEQ_UI_Button_Edit(depressed);
2502
    case 0x49: // C#5
2503
      return SEQ_UI_Button_Solo(depressed);
2504
    case 0x4a: // D-5
2505
      return SEQ_UI_Button_Mute(depressed);
2506
    case 0x4b: // D#5
2507
      return SEQ_UI_Button_All(depressed);
2508
    case 0x4c: // E-5
2509
      return SEQ_UI_Button_Pattern(depressed);
2510
    case 0x4d: // F-5
2511
      return SEQ_UI_Button_Song(depressed);
2512
    case 0x4e: // F#5
2513
      return SEQ_UI_Button_Fast(depressed);
2514
    case 0x4f: // G-5
2515
      return SEQ_UI_Button_Metronome(depressed);
2516
    case 0x50: // G#5
2517
      return SEQ_UI_Button_ExtRestart(depressed);
2518
    case 0x51: // A-5
2519
      return SEQ_UI_Button_ParLayerSel(depressed);
2520
    case 0x52: // A#5
2521
      return SEQ_UI_Button_TrackSel(depressed);
2522
    case 0x53: // B-5
2523
      return SEQ_UI_Button_Stop(depressed);
2524
 
2525
    case 0x54: // C-6
2526
      return SEQ_UI_Button_Play(depressed);
2527
    case 0x55: // C#6
2528
      return SEQ_UI_Button_Pause(depressed);
2529
    case 0x56: // D-6
2530
      return SEQ_UI_Button_Rew(depressed);
2531
    case 0x57: // D#6
2532
      return SEQ_UI_Button_Fwd(depressed);
2533
    case 0x58: // E-6
2534
      return SEQ_UI_Button_Utility(depressed);
2535
    case 0x59: // F-6
2536
      return SEQ_UI_Button_TempoPreset(depressed);
2537
    case 0x5a: // F#6
2538
      return 0; // ignore
2539
    case 0x5b: // G-6
2540
      return SEQ_UI_Button_Menu(depressed);
2541
    case 0x5c: // G#6
2542
      return SEQ_UI_Button_Select(depressed);
2543
    case 0x5d: // A-6
2544
      return SEQ_UI_Button_Exit(depressed);
2545
    case 0x5e: // A#6
2546
      return SEQ_UI_Button_Down(depressed);
2547
    case 0x5f: // B-6
2548
      return SEQ_UI_Button_Up(depressed);
2549
  }
2550
 
741 tk 2551
  return 0; // no error
2552
}
2553
 
2554
 
2555
/////////////////////////////////////////////////////////////////////////////
134 tk 2556
// Update LCD messages
2557
// Usually called from background task
2558
/////////////////////////////////////////////////////////////////////////////
2559
s32 SEQ_UI_LCD_Handler(void)
2560
{
728 tk 2561
  static u8 boot_animation_wait_ctr = 0;
2562
  static u8 boot_animation_lcd_pos = 0;
2130 tk 2563
  static u8 screen_saver_was_active = 0;
728 tk 2564
 
625 tk 2565
  // special handling in remote client mode
1316 tk 2566
  if( seq_midi_sysex_remote_active_mode == SEQ_MIDI_SYSEX_REMOTE_MODE_CLIENT )
625 tk 2567
    return SEQ_UI_LCD_Update();
2568
 
159 tk 2569
  if( seq_ui_display_init_req ) {
2570
    seq_ui_display_init_req = 0; // clear request
134 tk 2571
 
278 tk 2572
    // clear force update of LCD
2573
    SEQ_LCD_Clear();
2574
    SEQ_LCD_Update(1);
134 tk 2575
 
168 tk 2576
    // select first menu item
2577
    ui_selected_item = 0;
2578
 
167 tk 2579
    // call init function of current page
2039 tk 2580
    SEQ_UI_PAGES_CallInit(ui_page);
134 tk 2581
 
2582
    // request display update
159 tk 2583
    seq_ui_display_update_req = 1;
134 tk 2584
  }
2585
 
2130 tk 2586
  // print boot screen as long as hardware config hasn't been read or screensaver is active
496 tk 2587
  if( !SEQ_FILE_HW_ConfigLocked() ) {
728 tk 2588
    if( boot_animation_lcd_pos < (40-3) ) {
2589
      if( ++boot_animation_wait_ctr >= 75 ) {
2590
    boot_animation_wait_ctr = 0;
637 tk 2591
 
728 tk 2592
    if( boot_animation_lcd_pos == 0 ) {
2593
      SEQ_LCD_Clear();
2594
      SEQ_LCD_CursorSet(0, 0);
2595
      SEQ_LCD_PrintString(MIOS32_LCD_BOOT_MSG_LINE1 " " MIOS32_LCD_BOOT_MSG_LINE2);
2596
      SEQ_LCD_CursorSet(0, 1);
2597
      SEQ_LCD_PrintString("Searching for SD Card...");
2598
    }
2599
 
2600
    // logo is print on second LCD
2130 tk 2601
    SEQ_LCD_LOGO_Print(40, boot_animation_lcd_pos++);
728 tk 2602
      }
2603
    }
740 tk 2604
  } else if( seq_ui_backup_req || seq_ui_format_req ) {
634 tk 2605
    SEQ_LCD_Clear();
2606
    SEQ_LCD_CursorSet(0, 0);
740 tk 2607
    //                     <-------------------------------------->
2608
    //                     0123456789012345678901234567890123456789
2609
    if( seq_ui_backup_req )
959 tk 2610
      SEQ_LCD_PrintString("Copy Files - be patient!!!");
740 tk 2611
    else if( seq_ui_format_req )
959 tk 2612
      SEQ_LCD_PrintString("Creating Files - be patient!!!");
740 tk 2613
    else
2614
      SEQ_LCD_PrintString("Don't know what I'm doing! :-/");
637 tk 2615
 
2616
    if( seq_file_backup_notification != NULL ) {
2617
      int i;
2618
 
2619
      SEQ_LCD_CursorSet(0, 1);
959 tk 2620
      SEQ_LCD_PrintFormattedString("Creating %s", seq_file_backup_notification);
637 tk 2621
 
2622
      SEQ_LCD_CursorSet(40+3, 0);
2623
      SEQ_LCD_PrintString("Total: [");
2624
      for(i=0; i<20; ++i)
2625
    SEQ_LCD_PrintChar((i>(seq_file_backup_percentage/5)) ? ' ' : '#');
2626
      SEQ_LCD_PrintFormattedString("] %3d%%", seq_file_backup_percentage);
2627
 
2628
      SEQ_LCD_CursorSet(40+3, 1);
2629
      SEQ_LCD_PrintString("File:  [");
2630
      for(i=0; i<20; ++i)
1261 tk 2631
    SEQ_LCD_PrintChar((i>(file_copy_percentage/5)) ? ' ' : '#');
2632
      SEQ_LCD_PrintFormattedString("] %3d%%", file_copy_percentage);
637 tk 2633
    }
2634
 
2130 tk 2635
  } else if( SEQ_LCD_LOGO_ScreenSaver_IsActive() ) {
2636
    screen_saver_was_active = 1;
2637
    SEQ_LCD_LOGO_ScreenSaver_Print();
496 tk 2638
  } else if( seq_ui_button_state.MENU_PRESSED && !seq_ui_button_state.MENU_FIRST_PAGE_SELECTED ) {
2639
    SEQ_LCD_CursorSet(0, 0);
2640
    //                   <-------------------------------------->
2641
    //                   0123456789012345678901234567890123456789
306 tk 2642
    SEQ_LCD_PrintString("Menu Shortcuts:");
2643
    SEQ_LCD_PrintSpaces(25 + 40);
2644
    SEQ_LCD_CursorSet(0, 1);
2039 tk 2645
 
2646
    int i;
2647
    for(i=0; i<16; ++i) {
2648
      SEQ_LCD_PrintString(SEQ_UI_PAGES_MenuShortcutNameGet(i));
2649
    }
306 tk 2650
  } else {
2130 tk 2651
    // re-init special chars
2652
    if( screen_saver_was_active ) {
2653
      screen_saver_was_active = 0;
2654
      SEQ_LCD_ReInitSpecialChars();
2655
    }
2656
 
306 tk 2657
    // perform high priority LCD update request
2658
    if( ui_lcd_callback != NULL )
2659
      ui_lcd_callback(1); // high_prio
167 tk 2660
 
306 tk 2661
    // perform low priority LCD update request if requested
2662
    if( seq_ui_display_update_req ) {
2663
      seq_ui_display_update_req = 0; // clear request
328 tk 2664
 
2665
      // ensure that selections are matching with track constraints
2666
      SEQ_UI_CheckSelections();
2667
 
306 tk 2668
      if( ui_lcd_callback != NULL )
2669
    ui_lcd_callback(0); // no high_prio
2670
    }
134 tk 2671
  }
2672
 
353 tk 2673
  // transfer all changed characters to LCD
2674
  SEQ_UI_LCD_Update();
2675
 
2676
  return 0; // no error
2677
}
2678
 
2679
 
2680
/////////////////////////////////////////////////////////////////////////////
2681
// Called from SEQ_UI_LCD_Handler(), but optionally also from other tasks
2682
// to update the LCD screen immediately
2683
/////////////////////////////////////////////////////////////////////////////
1117 tk 2684
// for newer GCC versions it's important to declare constant arrays outside a function
2685
//                                             00112233
2686
static const char animation_l_arrows[2*4+1] = "   >>>> ";
2687
//                                             00112233
2688
static const char animation_r_arrows[2*4+1] = "  < << <";
2689
//                                               00112233
2690
static const char animation_l_brackets[2*4+1] = "   )))) ";
2691
//                                               00112233
2692
static const char animation_r_brackets[2*4+1] = "  ( (( (";
2693
//                                            00112233
2694
static const char animation_l_stars[2*4+1] = "   **** ";
2695
//                                            00112233
2696
static const char animation_r_stars[2*4+1] = "  * ** *";
353 tk 2697
s32 SEQ_UI_LCD_Update(void)
2698
{
625 tk 2699
  // special handling in remote client mode