Subversion Repositories svn.mios32

Rev

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