Subversion Repositories svn.mios32

Rev

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