Subversion Repositories svn.mios32

Rev

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