Subversion Repositories svn.mios32

Rev

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