Subversion Repositories svn.mios32

Rev

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