Subversion Repositories svn.mios32

Rev

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