Subversion Repositories svn.mios32

Rev

Rev 2389 | Rev 2449 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
174 tk 1
// $Id: seq_ui_trkevnt.c 2444 2016-11-05 17:37:51Z tk $
2
/*
319 tk 3
 * Track event page
174 tk 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>
326 tk 19
#include <string.h>
766 tk 20
 
21
#include "tasks.h"
22
 
174 tk 23
#include "seq_lcd.h"
24
#include "seq_ui.h"
25
#include "seq_cc.h"
333 tk 26
#include "seq_par.h"
984 tk 27
#include "seq_trg.h"
174 tk 28
#include "seq_layer.h"
690 tk 29
#include "seq_midi_port.h"
30
#include "seq_label.h"
718 tk 31
#include "seq_cc_labels.h"
2041 tk 32
#include "seq_midi_in.h"
1261 tk 33
 
34
#include "file.h"
766 tk 35
#include "seq_file.h"
36
#include "seq_file_t.h"
174 tk 37
 
38
 
39
/////////////////////////////////////////////////////////////////////////////
40
// Local definitions
41
/////////////////////////////////////////////////////////////////////////////
42
 
319 tk 43
// Note/Chord/CC
472 tk 44
#define NUM_OF_ITEMS_NORMAL 8
319 tk 45
#define ITEM_GXTY           0
46
#define ITEM_EVENT_MODE     1
47
#define ITEM_MIDI_PORT      2
48
#define ITEM_MIDI_CHANNEL   3
2092 tk 49
#define ITEM_TRKINST        4
472 tk 50
#define ITEM_LAYER_SELECT   5
51
#define ITEM_LAYER_CONTROL  6
52
#define ITEM_LAYER_PAR      7
174 tk 53
 
319 tk 54
// Drum
55
#define NUM_OF_ITEMS_DRUM   11
472 tk 56
//#define ITEM_GXTY           0
57
//#define ITEM_EVENT_MODE     1
58
//#define ITEM_MIDI_PORT      2
59
//#define ITEM_MIDI_CHANNEL   3
2092 tk 60
//#define ITEM_TRKINST        4
319 tk 61
#define ITEM_LAYER_A_SELECT 5
62
#define ITEM_LAYER_B_SELECT 6
63
#define ITEM_DRUM_SELECT    7
64
#define ITEM_DRUM_NOTE      8
65
#define ITEM_DRUM_VEL_N     9
66
#define ITEM_DRUM_VEL_A     10
174 tk 67
 
766 tk 68
#define IMPORT_NUM_OF_ITEMS    5
69
#define IMPORT_ITEM_NAME       0
70
#define IMPORT_ITEM_CHN        1
71
#define IMPORT_ITEM_MAPS       2
72
#define IMPORT_ITEM_CFG        3
73
#define IMPORT_ITEM_STEPS      4
319 tk 74
 
75
 
766 tk 76
// Preset dialog screens
77
#define PR_DIALOG_NONE          0
2092 tk 78
#define PR_DIALOG_PRESETS       1
79
#define PR_DIALOG_EXPORT_FNAME  2
80
#define PR_DIALOG_EXPORT_FEXISTS 3
81
#define PR_DIALOG_IMPORT        4
766 tk 82
 
83
#define NUM_LIST_DISPLAYED_ITEMS 4
84
#define LIST_ENTRY_WIDTH 9
85
 
86
 
174 tk 87
/////////////////////////////////////////////////////////////////////////////
323 tk 88
// Local types
89
/////////////////////////////////////////////////////////////////////////////
90
 
91
typedef struct {
92
  seq_event_mode_t event_mode;  // event mode as forwarded to SEQ_CC_MIDI_EVENT_MODE
93
  u8               par_layers;  // number of parameter layers
94
  u16              par_steps;   // number of steps per parameter layer
95
  u8               trg_layers;  // number of trigger layers
96
  u16              trg_steps;   // number of steps per trigger layer
328 tk 97
  u8               instruments; // number of instruments per track
323 tk 98
} layer_config_t;
99
 
100
 
101
/////////////////////////////////////////////////////////////////////////////
176 tk 102
// Local prototypes
103
/////////////////////////////////////////////////////////////////////////////
104
 
323 tk 105
static s32 GetLayerConfig(u8 track);
106
static s32 CopyPreset(u8 track, u8 config);
756 tk 107
static void InitReq(u32 dummy);
176 tk 108
 
766 tk 109
static s32 SEQ_UI_TRKEVNT_UpdateDirList(void);
176 tk 110
 
766 tk 111
static s32 DoExport(u8 force_overwrite);
112
static s32 DoImport(void);
113
 
114
 
176 tk 115
/////////////////////////////////////////////////////////////////////////////
178 tk 116
// Local variables
117
/////////////////////////////////////////////////////////////////////////////
118
 
323 tk 119
static u8 selected_layer_config;
472 tk 120
static u8 selected_layer_config_track;
319 tk 121
 
2444 tk 122
static u8 selected_drum_par_layer = 0;
123
 
752 tk 124
static u8 edit_cc_number;
1635 tk 125
static u8 edit_layer_type;
752 tk 126
 
472 tk 127
static const layer_config_t layer_config[] = {
328 tk 128
  //      mode           par_layers  par_steps  trg_layers  trg_steps  instruments
129
  { SEQ_EVENT_MODE_Note,    16,          64,        8,          64,      1 },
130
  { SEQ_EVENT_MODE_Note,     8,         128,        8,         128,      1 },
131
  { SEQ_EVENT_MODE_Note,     4,         256,        8,         256,      1 },
132
  { SEQ_EVENT_MODE_Chord,   16,          64,        8,          64,      1 },
133
  { SEQ_EVENT_MODE_Chord,    8,         128,        8,         128,      1 },
134
  { SEQ_EVENT_MODE_Chord,    4,         256,        8,         256,      1 },
135
  { SEQ_EVENT_MODE_CC,      16,          64,        8,          64,      1 },
136
  { SEQ_EVENT_MODE_CC,       8,         128,        8,         128,      1 },
137
  { SEQ_EVENT_MODE_CC,       4,         256,        8,         256,      1 },
2444 tk 138
  { SEQ_EVENT_MODE_Drum,     4,          16,        2,          64,     16 },
328 tk 139
  { SEQ_EVENT_MODE_Drum,     1,          64,        2,          64,     16 },
140
  { SEQ_EVENT_MODE_Drum,     2,          32,        1,         128,     16 },
141
  { SEQ_EVENT_MODE_Drum,     1,         128,        2,         128,      8 },
2389 tk 142
  { SEQ_EVENT_MODE_Drum,     2,          64,        2,         128,      8 },
984 tk 143
  { SEQ_EVENT_MODE_Drum,     2,          64,        1,         256,      8 },
144
  { SEQ_EVENT_MODE_Drum,     1,          64,        1,          64,     16 },
145
  { SEQ_EVENT_MODE_Drum,     1,         128,        1,         128,      8 },
1316 tk 146
  { SEQ_EVENT_MODE_Drum,     1,         256,        1,         256,      4 }
323 tk 147
};
148
 
319 tk 149
 
766 tk 150
static u8 pr_dialog;
151
 
1261 tk 152
static s32 dir_num_items; // contains FILE error status if < 0
766 tk 153
static u8 dir_view_offset = 0; // only changed once after startup
154
static char dir_name[12]; // directory name of device (first char is 0 if no device selected)
155
 
156
static seq_file_t_import_flags_t import_flags;
157
 
158
 
178 tk 159
/////////////////////////////////////////////////////////////////////////////
2041 tk 160
 
161
typedef enum {
162
  MIDI_LEARN_MODE_OFF = 0,
163
  MIDI_LEARN_MODE_DRUM_NOTE,
164
} midi_learn_mode_t;
165
 
166
static midi_learn_mode_t midi_learn_mode = MIDI_LEARN_MODE_OFF;
167
 
168
/////////////////////////////////////////////////////////////////////////////
174 tk 169
// Local LED handler function
170
/////////////////////////////////////////////////////////////////////////////
171
static s32 LED_Handler(u16 *gp_leds)
172
{
766 tk 173
  switch( pr_dialog ) {
174
    case PR_DIALOG_PRESETS:
175
      *gp_leds = (3 << (2*ui_selected_item));
176
      break;
174 tk 177
 
766 tk 178
    case PR_DIALOG_EXPORT_FNAME:
179
    case PR_DIALOG_EXPORT_FEXISTS:
180
      // no LED functions yet
181
      break;
182
 
183
    case PR_DIALOG_IMPORT:
184
      switch( ui_selected_item ) {
185
        case IMPORT_ITEM_NAME:
186
      *gp_leds |= 0x0100;
187
      break;
188
        case IMPORT_ITEM_CHN:
189
      *gp_leds |= 0x0200;
190
      break;
191
        case IMPORT_ITEM_MAPS:
192
      *gp_leds |= 0x0400;
193
      break;
194
        case IMPORT_ITEM_CFG:
195
      *gp_leds |= 0x0800;
196
      break;
197
        case IMPORT_ITEM_STEPS:
198
      *gp_leds |= 0x1000;
199
      break;
200
      }
201
      break;
202
 
203
    default:
204
      if( ui_cursor_flash ) { // if flashing flag active: no LED flag set
205
    // flash INIT LED if current preset doesn't match with old preset
206
    // this notifies the user, that he should press the "INIT" button
207
    u8 visible_track = SEQ_UI_VisibleTrackGet();
208
    if( selected_layer_config != GetLayerConfig(visible_track) )
209
      *gp_leds = 0x8000;
210
 
211
    return 0;
212
      }
213
 
214
      if( layer_config[selected_layer_config].event_mode == SEQ_EVENT_MODE_Drum ) {
215
    switch( ui_selected_item ) {
216
      case ITEM_GXTY: *gp_leds = 0x0001; break;
217
      case ITEM_EVENT_MODE: *gp_leds = 0x001e; break;
218
      case ITEM_MIDI_PORT: *gp_leds = 0x0020; break;
219
      case ITEM_MIDI_CHANNEL: *gp_leds = 0x0040; break;
2092 tk 220
      case ITEM_TRKINST: *gp_leds = 0x0080; break;
766 tk 221
      case ITEM_LAYER_A_SELECT: *gp_leds = 0x0100; break;
222
      case ITEM_LAYER_B_SELECT: *gp_leds = 0x0200; break;
223
      case ITEM_DRUM_SELECT: *gp_leds = 0x0400; break;
224
      case ITEM_DRUM_NOTE: *gp_leds = 0x0800; break;
225
      case ITEM_DRUM_VEL_N: *gp_leds = 0x1000; break;
226
      case ITEM_DRUM_VEL_A: *gp_leds = 0x2000; break;
227
    }
228
      } else {
229
    switch( ui_selected_item ) {
230
      case ITEM_GXTY: *gp_leds = 0x0001; break;
231
      case ITEM_EVENT_MODE: *gp_leds = 0x001e; break;
232
      case ITEM_MIDI_PORT: *gp_leds = 0x0020; break;
233
      case ITEM_MIDI_CHANNEL: *gp_leds = 0x0040; break;
2092 tk 234
      case ITEM_TRKINST: *gp_leds = 0x0080; break;
766 tk 235
      case ITEM_LAYER_SELECT: *gp_leds = 0x0100; break;
236
      case ITEM_LAYER_CONTROL: *gp_leds = 0x0200; break;
237
      case ITEM_LAYER_PAR: *gp_leds = 0x1c00; break;
238
    }
239
      }
174 tk 240
  }
241
 
242
  return 0; // no error
243
}
244
 
245
 
246
/////////////////////////////////////////////////////////////////////////////
247
// Local encoder callback function
248
// Should return:
249
//   1 if value has been changed
250
//   0 if value hasn't been changed
251
//  -1 if invalid or unsupported encoder
252
/////////////////////////////////////////////////////////////////////////////
253
static s32 Encoder_Handler(seq_ui_encoder_t encoder, s32 incrementer)
254
{
323 tk 255
  u8 event_mode = layer_config[selected_layer_config].event_mode;
335 tk 256
  u8 visible_track = SEQ_UI_VisibleTrackGet();
178 tk 257
 
766 tk 258
  switch( pr_dialog ) {
259
    ///////////////////////////////////////////////////////////////////////////
260
    case PR_DIALOG_PRESETS:
472 tk 261
      switch( encoder ) {
262
        case SEQ_UI_ENCODER_GP9:
766 tk 263
      return SEQ_UI_GxTyInc(incrementer);
174 tk 264
 
472 tk 265
        case SEQ_UI_ENCODER_GP10:
766 tk 266
      return -1; // not mapped
174 tk 267
 
472 tk 268
        case SEQ_UI_ENCODER_GP11:
766 tk 269
        case SEQ_UI_ENCODER_GP12: {
270
      int i;
174 tk 271
 
766 tk 272
      // only via button
273
      if( incrementer != 0 )
274
        return 0;
174 tk 275
 
766 tk 276
      // initialize keypad editor
277
      SEQ_UI_KeyPad_Init();
278
      for(i=0; i<8; ++i)
279
        dir_name[i] = ' ';
280
 
281
      ui_selected_item = 0;
282
      pr_dialog = PR_DIALOG_EXPORT_FNAME;
283
 
284
      return 1;
285
    }
286
 
472 tk 287
        case SEQ_UI_ENCODER_GP13:
481 tk 288
        case SEQ_UI_ENCODER_GP14:
766 tk 289
        case SEQ_UI_ENCODER_GP15:
290
      return -1; // not mapped
472 tk 291
 
481 tk 292
        case SEQ_UI_ENCODER_GP16:
766 tk 293
      // EXIT only via button
294
      if( incrementer == 0 ) {
295
        ui_selected_item = 0;
296
        pr_dialog = PR_DIALOG_NONE;
297
      }
298
      return 1;
299
 
300
        default:
301
      if( SEQ_UI_SelectListItem(incrementer, dir_num_items, NUM_LIST_DISPLAYED_ITEMS, &ui_selected_item, &dir_view_offset) )
302
        SEQ_UI_TRKEVNT_UpdateDirList();
472 tk 303
      }
766 tk 304
      break;
305
 
306
 
307
    ///////////////////////////////////////////////////////////////////////////
308
    case PR_DIALOG_IMPORT: {
309
      if( encoder <= SEQ_UI_ENCODER_GP8 )
310
    return -1; // not mapped
311
 
472 tk 312
      switch( encoder ) {
313
        case SEQ_UI_ENCODER_GP9:
766 tk 314
          ui_selected_item = IMPORT_ITEM_NAME;
315
          break;
174 tk 316
 
472 tk 317
        case SEQ_UI_ENCODER_GP10:
766 tk 318
          ui_selected_item = IMPORT_ITEM_CHN;
319
          break;
320
 
472 tk 321
        case SEQ_UI_ENCODER_GP11:
766 tk 322
          ui_selected_item = IMPORT_ITEM_MAPS;
323
          break;
324
 
472 tk 325
        case SEQ_UI_ENCODER_GP12:
766 tk 326
          ui_selected_item = IMPORT_ITEM_CFG;
327
          break;
328
 
472 tk 329
        case SEQ_UI_ENCODER_GP13:
766 tk 330
          ui_selected_item = IMPORT_ITEM_STEPS;
331
          break;
332
 
472 tk 333
        case SEQ_UI_ENCODER_GP14:
766 tk 334
      // not mapped
335
      return -1;
336
 
337
        case SEQ_UI_ENCODER_GP15:
338
      // IMPORT only via button
339
      if( incrementer == 0 ) {
340
        if( DoImport() == 0 ) {
341
          // exit page
342
          ui_selected_item = 0;
343
          pr_dialog = PR_DIALOG_NONE;
752 tk 344
        }
345
      }
766 tk 346
      return 1;
347
 
348
        case SEQ_UI_ENCODER_GP16: {
349
      // EXIT only via button
350
      if( incrementer == 0 ) {
351
        ui_selected_item = 0;
352
        pr_dialog = PR_DIALOG_NONE;
353
      }
354
      return 1;
355
    } break;
356
      }
357
 
358
      // for GP encoders and Datawheel
359
      switch( ui_selected_item ) {
360
        case IMPORT_ITEM_NAME:
361
      if( !incrementer ) incrementer = import_flags.NAME ? -1 : 1;
362
      import_flags.NAME = incrementer > 0 ? 1 : 0;
472 tk 363
      break;
174 tk 364
 
766 tk 365
        case IMPORT_ITEM_CHN:
366
      if( !incrementer ) incrementer = import_flags.CHN ? -1 : 1;
367
      import_flags.CHN = incrementer > 0 ? 1 : 0;
368
      break;
319 tk 369
 
766 tk 370
        case IMPORT_ITEM_MAPS:
371
      if( !incrementer ) incrementer = import_flags.MAPS ? -1 : 1;
372
      import_flags.MAPS = incrementer > 0 ? 1 : 0;
373
      break;
374
 
375
        case IMPORT_ITEM_CFG:
376
      if( !incrementer ) incrementer = import_flags.CFG ? -1 : 1;
377
      import_flags.CFG = incrementer > 0 ? 1 : 0;
378
      break;
379
 
380
        case IMPORT_ITEM_STEPS:
381
      if( !incrementer ) incrementer = import_flags.STEPS ? -1 : 1;
382
      import_flags.STEPS = incrementer > 0 ? 1 : 0;
383
      break;
472 tk 384
      }
766 tk 385
 
386
      return -1; // invalid or unsupported encoder
472 tk 387
    }
388
 
389
 
766 tk 390
    ///////////////////////////////////////////////////////////////////////////
391
    case PR_DIALOG_EXPORT_FNAME: {
392
      switch( encoder ) {
393
        case SEQ_UI_ENCODER_GP15: {
394
      // SAVE only via button
395
      if( incrementer != 0 )
396
        return 0;
472 tk 397
 
766 tk 398
      if( DoExport(0) == 0 ) { // don't force overwrite
399
        // exit keypad editor
400
        ui_selected_item = 0;
401
        pr_dialog = PR_DIALOG_NONE;
402
      }
174 tk 403
 
766 tk 404
      return 1;
405
    } break;
472 tk 406
 
766 tk 407
        case SEQ_UI_ENCODER_GP16: {
408
      // EXIT only via button
409
      if( incrementer == 0 ) {
410
        ui_selected_item = 0;
411
        pr_dialog = PR_DIALOG_NONE;
412
      }
413
      return 1;
414
    } break;
285 tk 415
      }
472 tk 416
 
766 tk 417
      return SEQ_UI_KeyPad_Handler(encoder, incrementer, (char *)&dir_name[0], 8);
418
    }
472 tk 419
 
174 tk 420
 
766 tk 421
    ///////////////////////////////////////////////////////////////////////////
422
    case PR_DIALOG_EXPORT_FEXISTS: {
423
      switch( encoder ) {
424
        case SEQ_UI_ENCODER_GP11: {
425
      // YES only via button
426
      if( incrementer != 0 )
427
        return 0;
428
 
429
      // YES: overwrite file
430
      if( DoExport(1) == 0 ) { // force overwrite
431
        // exit keypad editor
432
        ui_selected_item = 0;
433
        pr_dialog = PR_DIALOG_NONE;
434
      }
335 tk 435
      return 1;
766 tk 436
    } break;
437
 
438
        case SEQ_UI_ENCODER_GP12: {
439
      // NO only via button
440
      if( incrementer != 0 )
441
        return 0;
442
 
443
      // NO: don't overwrite file - back to filename entry
444
 
445
      ui_selected_item = 0;
446
      pr_dialog = PR_DIALOG_EXPORT_FNAME;
335 tk 447
      return 1;
766 tk 448
    } break;
449
 
450
        case SEQ_UI_ENCODER_GP16: {
451
      // EXIT only via button
452
      if( incrementer == 0 ) {
453
        ui_selected_item = 0;
454
        pr_dialog = PR_DIALOG_NONE;
455
      }
456
      return 1;
457
    } break;
458
      }
459
 
460
      return -1; // not mapped
461
    }
462
 
463
 
464
    ///////////////////////////////////////////////////////////////////////////
465
    default:
466
 
467
      if( encoder >= SEQ_UI_ENCODER_GP9 && encoder <= SEQ_UI_ENCODER_GP16 ) {
468
    if( selected_layer_config != GetLayerConfig(visible_track) ) {
1044 tk 469
      // ENC function disabled as long as pattern hasn't been initialized
766 tk 470
      return -1;
335 tk 471
    }
766 tk 472
 
752 tk 473
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
766 tk 474
      switch( encoder ) {
475
        case SEQ_UI_ENCODER_GP9:
476
          ui_selected_item = ITEM_LAYER_A_SELECT;
477
          break;
478
 
479
        case SEQ_UI_ENCODER_GP10:
480
          ui_selected_item = ITEM_LAYER_B_SELECT;
481
          break;
482
 
483
        case SEQ_UI_ENCODER_GP11:
484
          ui_selected_item = ITEM_DRUM_SELECT;
485
          break;
486
 
487
        case SEQ_UI_ENCODER_GP12:
488
          ui_selected_item = ITEM_DRUM_NOTE;
2041 tk 489
 
490
          // GP12 button activates MIDI learn mode
491
          if( incrementer == 0 ) {
492
        midi_learn_mode = MIDI_LEARN_MODE_DRUM_NOTE;
493
        SEQ_UI_MIDILearnMessage(SEQ_UI_MSG_USER, 1);
494
          }
495
 
766 tk 496
          break;
497
 
498
        case SEQ_UI_ENCODER_GP13:
499
          ui_selected_item = ITEM_DRUM_VEL_N;
500
          break;
501
 
502
        case SEQ_UI_ENCODER_GP14:
503
          ui_selected_item = ITEM_DRUM_VEL_A;
504
          break;
505
 
506
        case SEQ_UI_ENCODER_GP15:
507
          // change to preset page (only via button)
508
          if( incrementer == 0 ) {
509
        ui_selected_item = 0;
510
        pr_dialog = PR_DIALOG_PRESETS;
511
        SEQ_UI_TRKEVNT_UpdateDirList();
512
          }
513
          return 1;
514
 
515
        case SEQ_UI_ENCODER_GP16:
516
          return -1; // EXIT not mapped to encoder
517
      }
752 tk 518
    } else {
766 tk 519
      switch( encoder ) {
520
        case SEQ_UI_ENCODER_GP9:
521
          ui_selected_item = ITEM_LAYER_SELECT;
522
          break;
523
 
524
        case SEQ_UI_ENCODER_GP10:
1635 tk 525
          // Layer selection now has to be confirmed with GP button
526
          if( incrementer ) {
527
        if( ui_selected_item != ITEM_LAYER_CONTROL ) {
528
          edit_layer_type = SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_par_layer);
529
          ui_selected_item = ITEM_LAYER_CONTROL;
530
        }
531
        SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "Please confirm new type", "with GP button!");
532
          } else {
533
        if( edit_layer_type != SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_par_layer) ) {
534
          // TODO: has to be done for all selected tracks
535
          SEQ_CC_Set(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_par_layer, edit_layer_type);
536
          SEQ_LAYER_CopyParLayerPreset(visible_track, ui_selected_par_layer);
537
          SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "Layer Type", "has been changed.");
1771 tk 538
        } else {
539
          // send MIDI event
540
          if( SEQ_LAYER_DirectSendEvent(visible_track, ui_selected_par_layer) >= 0 ) {
541
            SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "MIDI event", "has been sent.");
542
          }
1635 tk 543
        }
544
          }
766 tk 545
          break;
546
 
547
        case SEQ_UI_ENCODER_GP11:
548
        case SEQ_UI_ENCODER_GP12:
2294 tk 549
        case SEQ_UI_ENCODER_GP13: {
550
          u8 assignment = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
551
          if( ui_selected_item == ITEM_LAYER_CONTROL )
552
        assignment = edit_layer_type;
553
 
554
          if( assignment == SEQ_PAR_Type_CC ) {
555
        // CC number selection now has to be confirmed with GP button
556
        if( incrementer ) {
557
          if( ui_selected_item != ITEM_LAYER_PAR ) {
558
            edit_cc_number = SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer);
559
            ui_selected_item = ITEM_LAYER_PAR;
560
          }
561
          SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "Please confirm CC", "with GP button!");
1771 tk 562
        } else {
2294 tk 563
          if( edit_cc_number != SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer) ) {
564
            SEQ_CC_Set(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer, edit_cc_number);
565
            SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "CC number", "has been changed.");
566
          } else {
567
            // send MIDI event
568
            if( SEQ_LAYER_DirectSendEvent(visible_track, ui_selected_par_layer) >= 0 ) {
569
              SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "MIDI event", "has been sent.");
570
            }
1771 tk 571
          }
766 tk 572
        }
2294 tk 573
          } else {
574
        return -1; // ignore
766 tk 575
          }
2294 tk 576
        } break;
766 tk 577
 
578
        case SEQ_UI_ENCODER_GP14:
579
        case SEQ_UI_ENCODER_GP15:
580
          // change to preset page (only via button)
581
          if( incrementer == 0 ) {
582
        ui_selected_item = 0;
583
        pr_dialog = PR_DIALOG_PRESETS;
584
        SEQ_UI_TRKEVNT_UpdateDirList();
585
          }
586
          return 1;
587
 
588
        case SEQ_UI_ENCODER_GP16:
589
          return -1; // not mapped to encoder
590
      }
752 tk 591
    }
766 tk 592
      }
752 tk 593
 
766 tk 594
      switch( encoder ) {
595
        case SEQ_UI_ENCODER_GP1:
596
      ui_selected_item = ITEM_GXTY;
597
      break;
598
 
599
        case SEQ_UI_ENCODER_GP2:
600
        case SEQ_UI_ENCODER_GP3:
601
        case SEQ_UI_ENCODER_GP4:
602
        case SEQ_UI_ENCODER_GP5:
603
      ui_selected_item = ITEM_EVENT_MODE;
604
      break;
605
 
606
        case SEQ_UI_ENCODER_GP6:
607
      ui_selected_item = ITEM_MIDI_PORT;
608
      break;
609
 
610
        case SEQ_UI_ENCODER_GP7:
611
      ui_selected_item = ITEM_MIDI_CHANNEL;
612
      break;
613
 
614
        case SEQ_UI_ENCODER_GP8:
2092 tk 615
      // enter track instrument page if button has been pressed
616
      if( incrementer == 0 )
617
        SEQ_UI_PageSet(SEQ_UI_PAGE_TRKINST);
618
      return 1;
766 tk 619
      }
620
 
621
      // for GP encoders and Datawheel
622
      switch( ui_selected_item ) {
623
        case ITEM_GXTY: return SEQ_UI_GxTyInc(incrementer);
624
        case ITEM_EVENT_MODE: {
625
      u8 max_layer_config = (sizeof(layer_config)/sizeof(layer_config_t)) - 1;
626
      return SEQ_UI_Var8_Inc(&selected_layer_config, 0, max_layer_config, incrementer);
627
    } break;
628
 
629
        case ITEM_MIDI_PORT: {
630
      mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
631
      u8 port_ix = SEQ_MIDI_PORT_OutIxGet(port);
632
      if( SEQ_UI_Var8_Inc(&port_ix, 0, SEQ_MIDI_PORT_OutNumGet()-1, incrementer) ) {
633
        mios32_midi_port_t new_port = SEQ_MIDI_PORT_OutPortGet(port_ix);
634
        SEQ_UI_CC_Set(SEQ_CC_MIDI_PORT, new_port);
635
        return 1; // value changed
636
      }
637
      return 0; // value not changed
638
    } break;
639
 
640
        case ITEM_MIDI_CHANNEL: return SEQ_UI_CC_Inc(SEQ_CC_MIDI_CHANNEL, 0, 15, incrementer);
641
      }
642
 
643
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
644
    switch( ui_selected_item ) {
645
    case ITEM_DRUM_SELECT: {
646
      u8 num_drums = layer_config[selected_layer_config].instruments;
647
      return SEQ_UI_Var8_Inc(&ui_selected_instrument, 0, num_drums-1, incrementer);
648
    } break;
649
    case ITEM_LAYER_A_SELECT: {
2444 tk 650
      if( layer_config[selected_layer_config].par_layers > 2 ) {
651
        return SEQ_UI_Var8_Inc(&selected_drum_par_layer, 0, layer_config[selected_layer_config].par_layers-1, incrementer);
652
      } else {
653
        selected_drum_par_layer = 0;
654
        if( SEQ_UI_CC_Inc(SEQ_CC_PAR_ASG_DRUM_LAYER_A, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
655
          SEQ_LAYER_CopyParLayerPreset(visible_track, 0);
656
          return 1;
657
        }
658
        return 0;
766 tk 659
      }
660
    } break;
661
    case ITEM_LAYER_B_SELECT: {
2444 tk 662
      if( layer_config[selected_layer_config].par_layers > 2 ) {
663
        if( SEQ_UI_CC_Inc(SEQ_CC_PAR_ASG_DRUM_LAYER_A + selected_drum_par_layer, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
664
          SEQ_LAYER_CopyParLayerPreset(visible_track, selected_drum_par_layer);
665
          return 1;
666
        }
667
        return 0;
668
      } else {
669
        selected_drum_par_layer = 1;
670
        if( SEQ_UI_CC_Inc(SEQ_CC_PAR_ASG_DRUM_LAYER_B, 0, SEQ_PAR_NUM_TYPES-1, incrementer) ) {
671
          SEQ_LAYER_CopyParLayerPreset(visible_track, 1);
672
          return 1;
673
        }
674
        return 0;
766 tk 675
      }
676
    } break;
2041 tk 677
 
678
    case ITEM_DRUM_NOTE: {
679
      return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_A1 + ui_selected_instrument, 0, 127, incrementer);
680
    } break;
681
 
682
    case ITEM_DRUM_VEL_N: {
683
      if( !SEQ_CC_TrackHasAccentTrgLayer(visible_track) ) {
684
        SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "VelN can't be changed:", "No accent layer in this config!");
685
      } else if( SEQ_CC_TrackHasVelocityParLayer(visible_track) ) {
686
        SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "VelN can't be changed: Track", "has already a velocity layer!");
687
      } else {
688
        return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_B1 + ui_selected_instrument, 0, 127, incrementer);
689
      }
690
    } break;
691
 
692
    case ITEM_DRUM_VEL_A: {
693
      if( !SEQ_CC_TrackHasAccentTrgLayer(visible_track) ) {
694
        SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "VelA can't be changed:", "No accent layer in this config!");
695
      } else {
696
        return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_C1 + ui_selected_instrument, 0, 127, incrementer);
697
      }
698
    } break;
333 tk 699
    }
766 tk 700
      } else {
701
    switch( ui_selected_item ) {
1024 tk 702
      case ITEM_LAYER_SELECT:  return SEQ_UI_Var8_Inc(&ui_selected_par_layer, 0, SEQ_PAR_NumLayersGet(visible_track)-1, incrementer);
766 tk 703
      case ITEM_LAYER_PAR:
704
        if( event_mode == SEQ_EVENT_MODE_Drum ) {
705
          return SEQ_UI_CC_Inc(SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer, 0, 127, incrementer);
706
        } else {
707
          // CC number selection now has to be confirmed with GP button
1811 tk 708
          return SEQ_UI_Var8_Inc(&edit_cc_number, 0, 128, incrementer);
766 tk 709
        }
710
 
711
      case ITEM_LAYER_CONTROL: {
1635 tk 712
        // Layer Control selection now has to be confirmed with GP button
2274 tk 713
        u8 value = SEQ_PAR_MappedTypeGet(edit_layer_type);
714
        if( SEQ_UI_Var8_Inc(&value, 0, SEQ_PAR_NUM_TYPES-1, incrementer) > 0 ) {
715
          edit_layer_type = SEQ_PAR_UnMappedTypeGet(value);
716
          return 1;
717
        }
718
        return 0;
766 tk 719
      } break;
720
    }
721
      }
319 tk 722
  }
723
 
174 tk 724
  return -1; // invalid or unsupported encoder
725
}
726
 
727
 
728
/////////////////////////////////////////////////////////////////////////////
729
// Local button callback function
730
// Should return:
731
//   1 if value has been changed
732
//   0 if value hasn't been changed
733
//  -1 if invalid or unsupported button
734
/////////////////////////////////////////////////////////////////////////////
735
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
736
{
752 tk 737
  u8 event_mode = layer_config[selected_layer_config].event_mode;
323 tk 738
 
766 tk 739
  switch( pr_dialog ) {
740
    ///////////////////////////////////////////////////////////////////////////
741
    case PR_DIALOG_PRESETS:
742
      if( depressed ) return 0; // ignore when button depressed
743
 
744
      if( button >= SEQ_UI_BUTTON_GP9 && button <= SEQ_UI_BUTTON_GP16 )
745
    return Encoder_Handler(button, 0); // re-use encoder handler
746
 
747
      if( button <= SEQ_UI_BUTTON_GP8 || button == SEQ_UI_BUTTON_Select ) {
748
    if( button != SEQ_UI_BUTTON_Select )
749
      ui_selected_item = button / 2;
750
 
751
    if( dir_num_items >= 1 && (ui_selected_item+dir_view_offset) < dir_num_items ) {
752
      // get filename
956 tk 753
      int i;
754
      char *p = (char *)&dir_name[0];
755
      for(i=0; i<8; ++i) {
756
        char c = ui_global_dir_list[LIST_ENTRY_WIDTH*ui_selected_item + i];
757
        if( c != ' ' )
758
          *p++ = c;
759
      }
760
      *p++ = 0;
766 tk 761
      // switch to import page
319 tk 762
      ui_selected_item = 0;
766 tk 763
      pr_dialog = PR_DIALOG_IMPORT;
764
    }
1123 tk 765
 
766
    return 1;
319 tk 767
      }
1123 tk 768
      break;
319 tk 769
 
174 tk 770
 
766 tk 771
    ///////////////////////////////////////////////////////////////////////////
772
    case PR_DIALOG_IMPORT:
773
      if( depressed ) return 0; // ignore when button depressed
774
 
775
      if( button <= SEQ_UI_BUTTON_GP16 )
776
    return Encoder_Handler(button, 0); // re-use encoder handler
777
 
778
      switch( button ) {
779
        case SEQ_UI_BUTTON_Select:
780
        case SEQ_UI_BUTTON_Right:
781
          if( ++ui_selected_item >= IMPORT_NUM_OF_ITEMS )
782
        ui_selected_item = 0;
783
 
784
          return 1; // value always changed
785
 
786
        case SEQ_UI_BUTTON_Left:
787
          if( ui_selected_item == 0 )
788
        ui_selected_item = IMPORT_NUM_OF_ITEMS-1;
1142 tk 789
      else
790
        --ui_selected_item;    
766 tk 791
          return 1; // value always changed
792
 
793
        case SEQ_UI_BUTTON_Up:
794
          return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
795
 
796
        case SEQ_UI_BUTTON_Down:
797
          return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
319 tk 798
      }
1123 tk 799
      break;
174 tk 800
 
801
 
766 tk 802
    ///////////////////////////////////////////////////////////////////////////
803
    case PR_DIALOG_EXPORT_FNAME:
804
    case PR_DIALOG_EXPORT_FEXISTS: {
805
      if( depressed ) return 0; // ignore when button depressed
806
 
1123 tk 807
      if( button <= SEQ_UI_BUTTON_GP16 )
808
    return Encoder_Handler(button, 0); // re-use encoder handler
809
    } break;
766 tk 810
 
811
 
812
    ///////////////////////////////////////////////////////////////////////////
813
    default:
814
      if( button == SEQ_UI_BUTTON_GP16 ) {
815
    if( depressed )
816
      SEQ_UI_UnInstallDelayedActionCallback(InitReq);
817
    else {
818
      SEQ_UI_InstallDelayedActionCallback(InitReq, 2000, 0);
819
      SEQ_UI_Msg(SEQ_UI_MSG_DELAYED_ACTION_R, 2001, "", "to initialize Track!");
820
    }
821
    return 1; // value has been changed
822
      }
823
 
2041 tk 824
      if( depressed ) {
825
    if( button == SEQ_UI_BUTTON_GP12 ) {
826
      if( midi_learn_mode != MIDI_LEARN_MODE_OFF ) {
827
        midi_learn_mode = MIDI_LEARN_MODE_OFF;
828
        SEQ_UI_MIDILearnMessage(SEQ_UI_MSG_USER, 0);
829
      }
830
    }
766 tk 831
 
2041 tk 832
    return 0; // ignore when button depressed
833
      }
834
 
766 tk 835
      if( button <= SEQ_UI_BUTTON_GP15 )
836
    return Encoder_Handler((seq_ui_encoder_t)button, 0);
837
 
838
      switch( button ) {
839
        case SEQ_UI_BUTTON_Select:
840
        case SEQ_UI_BUTTON_Right:
841
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
842
        if( ++ui_selected_item >= NUM_OF_ITEMS_DRUM )
843
          ui_selected_item = 0;
844
      } else {
845
        if( ++ui_selected_item >= NUM_OF_ITEMS_NORMAL )
846
          ui_selected_item = 0;
847
      }
848
 
849
      return 1; // value always changed
850
 
851
        case SEQ_UI_BUTTON_Left:
852
      if( event_mode == SEQ_EVENT_MODE_Drum ) {
853
        if( ui_selected_item == 0 )
854
          ui_selected_item = NUM_OF_ITEMS_DRUM-1;
1142 tk 855
        else
856
          --ui_selected_item;
766 tk 857
      } else {
858
        if( ui_selected_item == 0 )
859
          ui_selected_item = NUM_OF_ITEMS_NORMAL-1;
1142 tk 860
        else
861
          --ui_selected_item;
766 tk 862
      }
863
      return 1; // value always changed
864
 
865
        case SEQ_UI_BUTTON_Up:
866
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
867
 
868
        case SEQ_UI_BUTTON_Down:
869
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
870
      }
174 tk 871
  }
872
 
1123 tk 873
  if( depressed )
874
    return 0; // ignore when button depressed
875
 
876
  switch( button ) {
877
  case SEQ_UI_BUTTON_Exit:
878
    if( pr_dialog != PR_DIALOG_NONE ) {
879
      // switch to main dialog
880
      pr_dialog = PR_DIALOG_NONE;
881
      ui_selected_item = 0;
882
      return 1;
883
    }
884
    break;
885
  }
886
 
174 tk 887
  return -1; // invalid or unsupported button
888
}
889
 
890
 
891
/////////////////////////////////////////////////////////////////////////////
892
// Local Display Handler function
893
// IN: <high_prio>: if set, a high-priority LCD update is requested
894
/////////////////////////////////////////////////////////////////////////////
895
static s32 LCD_Handler(u8 high_prio)
896
{
897
  if( high_prio )
898
    return 0; // there are no high-priority updates
899
 
900
  // layout:
901
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
902
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
903
  // <--------------------------------------><-------------------------------------->
2092 tk 904
  // Trk. Type Steps/ParL/TrgL Port Chn. Trk.Layer  controls                         
905
  // G1T1 Note  256   4     8  IIC2  12  Inst  D    Prob                PRESETS  INIT
174 tk 906
 
2092 tk 907
  // Trk. Type Steps/ParL/TrgL Port Chn. Trk.Layer  controls                         
908
  // G1T1 Note  256   4     8  IIC2  12  Inst  D    CC #001 (ModWheel)  PRESETS  INIT
319 tk 909
 
910
  // Track Type "Note", Chord" and "CC":
911
  // Note: Parameter Layer A/B/C statically assigned to Note Number/Velocity/Length
912
  //       Parameter Layer D..P can be mapped to
913
  //       - additional Notes (e.g. for poly recording)
914
  //       - Base note (directly forwarded to Transposer, e.g. for Force-to-Scale or Chords)
915
  //       - CC (Number 000..127 assignable, GM controller name will be displayed)
916
  //       - Pitch Bender
917
  //       - Loopback (Number 000..127 assignable, name will be displayed)
338 tk 918
  //       - Delay (0..95 ticks @384 ppqn)
319 tk 919
  //       - Probability (100%..0%)
327 tk 920
  //       - "Roll/Flam Effect" (a selection of up to 128 different effects selectable for each step separately)
319 tk 921
  // Chord: same like Note, but predefined Chords will be played
922
  // CC: Layer A/B/C play CCs (or other parameters) as well - no note number, no velocity, no length
923
 
924
  // Available Layer Constraints (Partitioning for 1024 bytes Par. memory, 2048 bits Trg. memory)
925
  //    - 256 Steps with  4 Parameter Layers A-D and 8 Trigger Layers A-H
926
  //    - 128 Steps with  8 Parameter Layers A-H and 8 Trigger Layers A-H
927
  //    -  64 Steps with 16 Parameter Layers A-P and 8 Trigger Layers A-H
928
 
929
 
930
  // layout:
931
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
932
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
933
  // <--------------------------------------><-------------------------------------->
2092 tk 934
  // Trk. Type StepsP/T  Drums Port Chn. Trk.LayA LayB  Drum Note VelN VelA PRE-    
935
  // G1T1 Drum  (64/2*64) 16   USB1  10  InstPrb. ----   BD   C-1  100  127 SETS INIT
319 tk 936
 
2092 tk 937
  // Trk. Type StepsP/T  Drums Port Chn. Trk.LayA LayB  Drum Note VelN VelA PRE-         
938
  // G1T1 Drum  (2*64/256) 8   USB1  12  InstVel. Len.   SD   D-1  ---  --- SETS INIT
319 tk 939
 
940
 
941
  // Track Type "Drums":
327 tk 942
  //    1 or 2 parameter layers for each trigger layer (drum instrument).
943
  //    If parameters layers consist of more than 1024 steps in total, steps > 1024 will be mirrored
944
  //    assignable to Velocity/Gatelength/Delay/Probability/Roll/Flam only
319 tk 945
  //    (no CC, no Pitch Bender, no Loopback, as they don't work note-wise, but 
946
  //     only channel wise
947
  //     just send them from a different track)
948
 
949
  // Each drum instrument provides 4 constant parameters for:
950
  //   - Note Number
472 tk 951
  //   - MIDI Channel (1-16) for all drum instruments (TODO: optionally allow to use a "local" channel, edit parameter right of VelA)
319 tk 952
  //   - Velocity Normal (if not taken from Parameter Layer)
953
  //   - Velocity Accented (if not taken from Parameter Layer)
954
 
955
 
956
  // Available Layer Constraints (Partitioning for 1024 bytes Par. memory, 2048 bits Trg. memory)
327 tk 957
  //    - 16 Parameter Layers with 64 steps and 2*16 Trigger Layers A-P with 64 steps taken for Gate and Accent
958
  //    - 2*16 Parameter Layer with 32 steps and 16 Trigger Layers A-P with 128 steps taken for Gate
959
  //    - 8 Parameter Layer with 128 steps and 2*8 Trigger Layers A-P with 128 steps taken for Gate and Accent
960
  //    - 2*8 Parameter Layer with 64 steps and 8 Trigger Layers A-P with 256 steps taken for Gate
319 tk 961
 
472 tk 962
 
963
 
766 tk 964
  // Preset dialogs:
965
  // Load Preset File (10 files found)       Trk.      SAVE AS                       
966
  //  xxxxxxxx  xxxxxxxx  xxxxxxxx  xxxxxxxx G1T1     NEW PRESET                 EXIT
967
 
968
  // Import selections:
956 tk 969
  // Importing /PRESETS/xxxxx.V4T to G1T1    Name Chn. Maps Cfg. Steps
766 tk 970
  // Please select track sections:           yes  yes  yes  yes   yes     IMPORT EXIT
971
 
972
  // "Save as new preset"
956 tk 973
  // Please enter Filename:                  /PRESETS/<xxxxxxxx>.V4T                 
766 tk 974
  // .,!1 ABC2 DEF3 GHI4 JKL5 MNO6 PQRS7 TUV8WXYZ9 -_ 0  Char <>  Del Ins   SAVE EXIT
975
 
976
  // File exists
956 tk 977
  //                                         File '/PRESETS/xxx.V4T' already exists     
766 tk 978
  //                                         Overwrite? YES  NO                  EXIT
979
 
980
 
981
 
982
 
174 tk 983
  u8 visible_track = SEQ_UI_VisibleTrackGet();
472 tk 984
 
985
  // if track has changed, switch layer config:
986
  if( visible_track != selected_layer_config_track ) {
987
    selected_layer_config_track = visible_track;
988
    selected_layer_config = GetLayerConfig(selected_layer_config_track);
989
  }
990
 
323 tk 991
  u8 event_mode = layer_config[selected_layer_config].event_mode;
174 tk 992
 
472 tk 993
 
766 tk 994
  switch( pr_dialog ) {
995
    ///////////////////////////////////////////////////////////////////////////
996
    case PR_DIALOG_PRESETS: {
997
      SEQ_LCD_CursorSet(0, 0);
998
      SEQ_LCD_PrintSpaces(40);
999
 
1000
      SEQ_LCD_CursorSet(0, 0);
1001
      if( dir_num_items < 0 ) {
1261 tk 1002
    if( dir_num_items == FILE_ERR_NO_DIR )
956 tk 1003
      SEQ_LCD_PrintString("/PRESETS directory not found on SD Card!");
766 tk 1004
    else
1005
      SEQ_LCD_PrintFormattedString("SD Card Access Error: %d", dir_num_items);
1006
      } else if( dir_num_items == 0 ) {
956 tk 1007
    SEQ_LCD_PrintFormattedString("No files found under /PRESETS!");
752 tk 1008
      } else {
766 tk 1009
    SEQ_LCD_PrintFormattedString("Select Preset File (%d files found)", dir_num_items);
729 tk 1010
      }
1011
 
766 tk 1012
      ///////////////////////////////////////////////////////////////////////////
1013
      SEQ_LCD_CursorSet(40, 0);
1014
      SEQ_LCD_PrintString("Trk.      SAVE AS");
1015
      SEQ_LCD_PrintSpaces(40-23);
752 tk 1016
 
766 tk 1017
      ///////////////////////////////////////////////////////////////////////////
1018
      SEQ_LCD_CursorSet(0, 1);
752 tk 1019
 
766 tk 1020
      SEQ_LCD_PrintList((char *)ui_global_dir_list, LIST_ENTRY_WIDTH, dir_num_items, NUM_LIST_DISPLAYED_ITEMS, ui_selected_item, dir_view_offset);
752 tk 1021
 
766 tk 1022
      SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
1023
      SEQ_LCD_PrintString("     NEW PRESET                 EXIT");
1024
    } break;
752 tk 1025
 
1026
 
766 tk 1027
    case PR_DIALOG_IMPORT: {
1028
      ///////////////////////////////////////////////////////////////////////////
1029
      SEQ_LCD_CursorSet(0, 0);
956 tk 1030
      SEQ_LCD_PrintFormattedString("Importing /PRESETS/%s.V4T to ", dir_name);
766 tk 1031
      SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
1032
      SEQ_LCD_PrintSpaces(10);
752 tk 1033
 
766 tk 1034
      SEQ_LCD_CursorSet(40, 0);
1035
      SEQ_LCD_PrintString("Name Chn. Maps Cfg. Steps");
1036
      SEQ_LCD_PrintSpaces(15);
752 tk 1037
 
766 tk 1038
      SEQ_LCD_CursorSet(0, 1);
1039
      SEQ_LCD_PrintFormattedString("Please select track sections:");
1040
      SEQ_LCD_PrintSpaces(11);
174 tk 1041
 
766 tk 1042
      if( ui_selected_item == IMPORT_ITEM_NAME && ui_cursor_flash ) {
1043
    SEQ_LCD_PrintSpaces(3);
1044
      } else {
1045
    SEQ_LCD_PrintString(import_flags.NAME ? "yes" : " no");
1046
      }
1047
      SEQ_LCD_PrintSpaces(2);
174 tk 1048
 
766 tk 1049
      if( ui_selected_item == IMPORT_ITEM_CHN && ui_cursor_flash ) {
1050
    SEQ_LCD_PrintSpaces(3);
1051
      } else {
1052
    SEQ_LCD_PrintString(import_flags.CHN ? "yes" : " no");
1053
      }
1054
      SEQ_LCD_PrintSpaces(2);
174 tk 1055
 
766 tk 1056
      if( ui_selected_item == IMPORT_ITEM_MAPS && ui_cursor_flash ) {
1057
    SEQ_LCD_PrintSpaces(3);
1058
      } else {
1059
    SEQ_LCD_PrintString(import_flags.MAPS ? "yes" : " no");
1060
      }
1061
      SEQ_LCD_PrintSpaces(2);
174 tk 1062
 
766 tk 1063
      if( ui_selected_item == IMPORT_ITEM_CFG && ui_cursor_flash ) {
1064
    SEQ_LCD_PrintSpaces(3);
1065
      } else {
1066
    SEQ_LCD_PrintString(import_flags.CFG ? "yes" : " no");
1067
      }
1068
      SEQ_LCD_PrintSpaces(2);
174 tk 1069
 
766 tk 1070
      if( ui_selected_item == IMPORT_ITEM_STEPS && ui_cursor_flash ) {
1071
    SEQ_LCD_PrintSpaces(3);
1072
      } else {
1073
    SEQ_LCD_PrintString(import_flags.STEPS ? "yes" : " no");
1074
      }
327 tk 1075
 
766 tk 1076
      SEQ_LCD_PrintSpaces(6);
327 tk 1077
 
766 tk 1078
      SEQ_LCD_PrintString("IMPORT EXIT");
1079
    } break;
327 tk 1080
 
174 tk 1081
 
766 tk 1082
    case PR_DIALOG_EXPORT_FNAME: {
1083
      int i;
174 tk 1084
 
766 tk 1085
      SEQ_LCD_CursorSet(0, 0);
1086
      SEQ_LCD_PrintString("Please enter Filename:");
1087
      SEQ_LCD_PrintSpaces(18);
174 tk 1088
 
956 tk 1089
      SEQ_LCD_PrintString("/PRESETS/<");
766 tk 1090
      for(i=0; i<8; ++i)
1091
    SEQ_LCD_PrintChar(dir_name[i]);
1092
      SEQ_LCD_PrintString(">.V4T");
1093
      SEQ_LCD_PrintSpaces(20);
472 tk 1094
 
766 tk 1095
      // insert flashing cursor
1096
      if( ui_cursor_flash ) {
1097
    SEQ_LCD_CursorSet(50 + ui_edit_name_cursor, 0);
1098
    SEQ_LCD_PrintChar('*');
1099
      }
472 tk 1100
 
766 tk 1101
      SEQ_UI_KeyPad_LCD_Msg();
1102
      SEQ_LCD_PrintString("  SAVE EXIT");
1103
    } break;
174 tk 1104
 
1105
 
766 tk 1106
    case PR_DIALOG_EXPORT_FEXISTS: {
1107
      SEQ_LCD_CursorSet(0, 0);
1108
      SEQ_LCD_PrintSpaces(40);
1109
 
956 tk 1110
      SEQ_LCD_PrintFormattedString("File '/PRESETS/%s.V4T' already exists!", dir_name);
766 tk 1111
      SEQ_LCD_PrintSpaces(10);
1112
 
1113
      SEQ_LCD_CursorSet(0, 1);
1114
      SEQ_LCD_PrintSpaces(40);
1115
 
1116
      SEQ_LCD_PrintString("Overwrite? YES  NO");
1117
      SEQ_LCD_PrintSpaces(18);
1118
      SEQ_LCD_PrintString("EXIT");
1119
    } break;
1120
 
1121
 
1122
 
1123
    ///////////////////////////////////////////////////////////////////////////
1124
    default:
1125
 
1126
      SEQ_LCD_CursorSet(0, 0);
1127
 
1128
      SEQ_LCD_PrintString("Trk. Type ");
1129
      SEQ_LCD_PrintString((event_mode == SEQ_EVENT_MODE_Drum) ? "StepsP/T  Drums " : "Steps/ParL/TrgL ");
1130
      SEQ_LCD_PrintString("Port Chn. ");
1131
 
2092 tk 1132
      if( ui_selected_item == ITEM_TRKINST && ui_cursor_flash ) {
766 tk 1133
    SEQ_LCD_PrintSpaces(4);
472 tk 1134
      } else {
2092 tk 1135
    SEQ_LCD_PrintFormattedString("Trk.");
472 tk 1136
      }
319 tk 1137
 
766 tk 1138
      if( selected_layer_config != GetLayerConfig(visible_track) ) {
1139
    SEQ_LCD_PrintString("    Please initialize the track         ");
1140
      } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
2444 tk 1141
    if( layer_config[selected_layer_config].par_layers > 2 ) {
1142
      SEQ_LCD_PrintString("Layer Asg. ");
1143
    } else {
1144
      SEQ_LCD_PrintString("LayA ");
1145
      SEQ_LCD_PrintString((layer_config[selected_layer_config].par_layers >= 2) ? "LayB " : "     ");
1146
    }
2041 tk 1147
    if( SEQ_CC_TrackHasAccentTrgLayer(visible_track) && !SEQ_CC_TrackHasVelocityParLayer(visible_track) ) {
1148
      SEQ_LCD_PrintString(" Drum Note VelN VelA PRE-    ");
2042 tk 1149
    } else if( SEQ_CC_TrackHasAccentTrgLayer(visible_track) ) {
1150
      SEQ_LCD_PrintString(" Drum Note      VelA PRE-    ");
2041 tk 1151
    } else {
1152
      SEQ_LCD_PrintString(" Drum Note           PRE-    ");
1153
    }
766 tk 1154
      } else {
1155
    SEQ_LCD_PrintString("Layer  controls                         ");
1156
      }
319 tk 1157
 
766 tk 1158
      ///////////////////////////////////////////////////////////////////////////
1159
      SEQ_LCD_CursorSet(0, 1);
319 tk 1160
 
766 tk 1161
      if( ui_selected_item == ITEM_GXTY && ui_cursor_flash ) {
1162
    SEQ_LCD_PrintSpaces(5);
1163
      } else {
1164
    SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
1165
    SEQ_LCD_PrintSpaces(1);
1166
      }
319 tk 1167
 
766 tk 1168
      ///////////////////////////////////////////////////////////////////////////
319 tk 1169
 
766 tk 1170
      if( ui_selected_item == ITEM_EVENT_MODE && ui_cursor_flash ) {
1171
    SEQ_LCD_PrintSpaces(21);
1172
      } else {
1173
    SEQ_LCD_PrintString((char *)SEQ_LAYER_GetEvntModeName(event_mode));
323 tk 1174
 
766 tk 1175
    layer_config_t *lc = (layer_config_t *)&layer_config[selected_layer_config];
1176
    if( event_mode == SEQ_EVENT_MODE_Drum ) {
1177
      SEQ_LCD_PrintChar(' ');
1178
      SEQ_LCD_PrintChar('(');
1179
      SEQ_LCD_PrintSpaces(14); // for easier handling
1180
      SEQ_LCD_CursorSet(12, 1);
1181
 
1182
      if( lc->par_layers > 1 )
1183
        SEQ_LCD_PrintFormattedString("%d*", lc->par_layers);
1184
      SEQ_LCD_PrintFormattedString("%d/", lc->par_steps);
1185
      if( lc->trg_layers > 1 )
1186
        SEQ_LCD_PrintFormattedString("%d*", lc->trg_layers);
1187
      SEQ_LCD_PrintFormattedString("%d", lc->trg_steps);
1188
 
1189
      SEQ_LCD_PrintFormattedString(") %d", lc->instruments);
1190
      SEQ_LCD_CursorSet(26, 1);
1191
    } else {
1192
      SEQ_LCD_PrintFormattedString("  %3d %3d  %3d  ", lc->par_steps, lc->par_layers, lc->trg_layers);
1193
    }
333 tk 1194
      }
174 tk 1195
 
766 tk 1196
      ///////////////////////////////////////////////////////////////////////////
1197
      mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
1198
      if( ui_selected_item == ITEM_MIDI_PORT && ui_cursor_flash ) {
1199
    SEQ_LCD_PrintSpaces(5);
1200
      } else {
1201
    SEQ_LCD_PrintMIDIOutPort(port);
1202
    SEQ_LCD_PrintChar(SEQ_MIDI_PORT_OutCheckAvailable(port) ? ' ' : '*');
1203
      }
178 tk 1204
 
766 tk 1205
      ///////////////////////////////////////////////////////////////////////////
1206
      if( ui_selected_item == ITEM_MIDI_CHANNEL && ui_cursor_flash ) {
1207
    SEQ_LCD_PrintSpaces(5);
1208
      } else {
1209
    SEQ_LCD_PrintFormattedString("%3d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
1210
      }
323 tk 1211
 
766 tk 1212
      ///////////////////////////////////////////////////////////////////////////
2092 tk 1213
      if( ui_selected_item == ITEM_TRKINST && ui_cursor_flash ) {
766 tk 1214
    SEQ_LCD_PrintSpaces(4);
1215
      } else {
2092 tk 1216
    SEQ_LCD_PrintFormattedString("Inst");
766 tk 1217
      }
1218
 
1219
      ///////////////////////////////////////////////////////////////////////////
1220
      if( selected_layer_config != GetLayerConfig(visible_track) ) {
1221
    SEQ_LCD_PrintString(" ---------------------------------> ");
1222
    if( (ui_cursor_flash_overrun_ctr & 1) ) {
1223
      SEQ_LCD_PrintSpaces(4);
1224
    } else {
1225
      SEQ_LCD_PrintString("INIT");
1226
    }
1227
 
1228
        ///////////////////////////////////////////////////////////////////////////
1229
      } else if( event_mode == SEQ_EVENT_MODE_Drum ) {
1230
    /////////////////////////////////////////////////////////////////////////
1231
    if( ui_selected_item == ITEM_LAYER_A_SELECT && ui_cursor_flash ) {
1232
      SEQ_LCD_PrintSpaces(5);
1233
    } else {
2444 tk 1234
      if( layer_config[selected_layer_config].par_layers > 2 ) {
1235
        SEQ_LCD_PrintSpaces(2);
1236
        SEQ_LCD_PrintChar('A' + selected_drum_par_layer);
1237
        SEQ_LCD_PrintSpaces(2);
2389 tk 1238
      } else {
2444 tk 1239
        seq_par_layer_type_t asg = SEQ_PAR_AssignmentGet(visible_track, 0);
1240
        if( asg == SEQ_PAR_Type_CC ) {
1241
          SEQ_LCD_PrintString("TODO "); // CC not supported for drum tracks, print bullshit
1242
        } else {
1243
          SEQ_LCD_PrintString(SEQ_PAR_TypeStr(asg));
1244
        }
2389 tk 1245
      }
766 tk 1246
    }
1247
 
1248
    /////////////////////////////////////////////////////////////////////////
2444 tk 1249
    if( layer_config[selected_layer_config].par_layers > 2 ) {
1250
      if( ui_selected_item == ITEM_LAYER_B_SELECT && ui_cursor_flash ) {
1251
        SEQ_LCD_PrintSpaces(6);
1252
      } else {
1253
        SEQ_LCD_PrintSpaces(1);
1254
 
1255
        seq_par_layer_type_t asg = SEQ_PAR_AssignmentGet(visible_track, selected_drum_par_layer);
2389 tk 1256
        if( asg == SEQ_PAR_Type_CC ) {
2444 tk 1257
          SEQ_LCD_PrintString("TODO "); // CC not supported for drum tracks, print bullshit
2389 tk 1258
        } else {
1259
          SEQ_LCD_PrintString(SEQ_PAR_TypeStr(asg));
1260
        }
2444 tk 1261
      }
1262
    } else {
1263
      if( ui_selected_item == ITEM_LAYER_B_SELECT && ui_cursor_flash ) {
1264
        SEQ_LCD_PrintSpaces(5);
766 tk 1265
      } else {
2444 tk 1266
        if( layer_config[selected_layer_config].par_layers >= 2 ) {
1267
          seq_par_layer_type_t asg = SEQ_PAR_AssignmentGet(visible_track, 1);
1268
          if( asg == SEQ_PAR_Type_CC ) {
1269
        SEQ_LCD_PrintString("TODO "); // CC not supported for drum tracks, print bullshit
1270
          } else {
1271
        SEQ_LCD_PrintString(SEQ_PAR_TypeStr(asg));
1272
          }
1273
        } else {
1274
          if( ui_selected_item == ITEM_LAYER_B_SELECT )
1275
        SEQ_LCD_PrintString(" --- "); // not a bug, but a feature - highlight, that layer not configurable
1276
          else
1277
        SEQ_LCD_PrintSpaces(5);
1278
        }
766 tk 1279
      }
2444 tk 1280
      SEQ_LCD_PrintSpaces(1);
766 tk 1281
    }
1282
 
1283
    /////////////////////////////////////////////////////////////////////////
1284
    if( ui_selected_item == ITEM_DRUM_SELECT && ui_cursor_flash ) {
1285
      SEQ_LCD_PrintSpaces(5);
1286
    } else {
1287
      SEQ_LCD_PrintTrackDrum(visible_track, ui_selected_instrument, (char *)seq_core_trk[visible_track].name);
1288
    }
1289
 
1290
    /////////////////////////////////////////////////////////////////////////
1291
    SEQ_LCD_PrintSpaces(1);
1292
    if( ui_selected_item == ITEM_DRUM_NOTE && ui_cursor_flash ) {
1293
      SEQ_LCD_PrintSpaces(3);
1294
    } else {
1295
      SEQ_LCD_PrintNote(SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_instrument));
1296
    }
1297
    SEQ_LCD_PrintSpaces(1);
1298
 
1299
    /////////////////////////////////////////////////////////////////////////
1300
    if( ui_selected_item == ITEM_DRUM_VEL_N && ui_cursor_flash ) {
1301
      SEQ_LCD_PrintSpaces(5);
1302
    } else {
2041 tk 1303
      if( SEQ_CC_TrackHasAccentTrgLayer(visible_track) && !SEQ_CC_TrackHasVelocityParLayer(visible_track) ) {
1304
        SEQ_LCD_PrintFormattedString(" %3d ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_instrument));
1305
      } else {
1306
        SEQ_LCD_PrintString(" --- ");
1307
      }
766 tk 1308
    }
1309
 
1310
    /////////////////////////////////////////////////////////////////////////
1311
    if( ui_selected_item == ITEM_DRUM_VEL_A && ui_cursor_flash ) {
1312
      SEQ_LCD_PrintSpaces(5);
1313
    } else {
2042 tk 1314
      if( SEQ_CC_TrackHasAccentTrgLayer(visible_track) ) {
2041 tk 1315
        SEQ_LCD_PrintFormattedString(" %3d ", SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_C1 + ui_selected_instrument));
1316
      } else {
1317
        SEQ_LCD_PrintString(" --- ");
1318
      }
766 tk 1319
    }
1320
 
1321
    SEQ_LCD_PrintString("SETS INIT");
1322
      } else {
1323
    /////////////////////////////////////////////////////////////////////////
1324
    SEQ_LCD_PrintSpaces(2);
1325
    if( ui_selected_item == ITEM_LAYER_SELECT && ui_cursor_flash ) {
1326
      SEQ_LCD_PrintChar(' ');
1327
    } else {
1328
      SEQ_LCD_PrintChar('A' + ui_selected_par_layer);
1329
    }
1635 tk 1330
    SEQ_LCD_PrintSpaces(3);
766 tk 1331
 
1332
    /////////////////////////////////////////////////////////////////////////
1333
    if( ui_selected_item == ITEM_LAYER_CONTROL && ui_cursor_flash ) {
1635 tk 1334
      SEQ_LCD_PrintSpaces(6);
766 tk 1335
    } else {
1635 tk 1336
      u8 current_value = SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_A1 + ui_selected_par_layer);
1337
      if( ui_selected_item == ITEM_LAYER_CONTROL && edit_layer_type != current_value ) {
1338
        SEQ_LCD_PrintChar('!');
1339
        SEQ_LCD_PrintString(SEQ_PAR_TypeStr(edit_layer_type));
1340
      } else {
1341
        SEQ_LCD_PrintChar(' ');
2294 tk 1342
        SEQ_LCD_PrintString(SEQ_PAR_TypeStr(SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer)));
1635 tk 1343
      }
766 tk 1344
    }
1345
 
1346
    /////////////////////////////////////////////////////////////////////////
1347
    if( ui_selected_item == ITEM_LAYER_PAR && ui_cursor_flash ) {
1348
      SEQ_LCD_PrintSpaces(15);
1349
    } else {
1635 tk 1350
      u8 assignment = SEQ_PAR_AssignmentGet(visible_track, ui_selected_par_layer);
1351
      if( ui_selected_item == ITEM_LAYER_CONTROL )
1352
        assignment = edit_layer_type;
1353
 
1354
      switch( assignment ) {
766 tk 1355
            case SEQ_PAR_Type_CC: {
1356
          mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT);
1357
          u8 current_value = SEQ_CC_Get(visible_track, SEQ_CC_LAY_CONST_B1 + ui_selected_par_layer);
1358
          u8 edit_value = ui_selected_item == ITEM_LAYER_PAR ? edit_cc_number : current_value;
1811 tk 1359
 
1360
          if( edit_value >= 0x80 ) {
1361
        SEQ_LCD_PrintFormattedString("off%c(no CC   ) ", (current_value != edit_value) ? '!' : ' ');
1362
          } else {
1363
        SEQ_LCD_PrintFormattedString("%03d%c(%s) ", edit_value,
1364
                         (current_value != edit_value) ? '!' : ' ',
1365
                         SEQ_CC_LABELS_Get(port, edit_value));
1366
          }
766 tk 1367
        } break;
1368
 
1369
            default:
1370
          SEQ_LCD_PrintSpaces(15);
1371
      }
1372
    }
1373
 
1374
    SEQ_LCD_PrintString("PRESETS  INIT");
1375
      }
1376
  }
1377
 
174 tk 1378
  return 0; // no error
1379
}
1380
 
1381
 
1382
/////////////////////////////////////////////////////////////////////////////
2041 tk 1383
// MIDI IN
1384
/////////////////////////////////////////////////////////////////////////////
2047 tk 1385
static s32 MIDI_IN_Handler(mios32_midi_port_t port, mios32_midi_package_t p)
2041 tk 1386
{
1387
  if( midi_learn_mode == MIDI_LEARN_MODE_DRUM_NOTE ) {
2043 tk 1388
    if( p.type == NoteOn && p.velocity > 0 ) {
1389
      SEQ_UI_CC_Set(SEQ_CC_LAY_CONST_A1 + ui_selected_instrument, p.note);
1390
      seq_ui_display_update_req = 1;
1391
    }
2041 tk 1392
  }
1393
 
1394
  return 0;
1395
}
1396
 
1397
 
1398
/////////////////////////////////////////////////////////////////////////////
174 tk 1399
// Initialisation
1400
/////////////////////////////////////////////////////////////////////////////
1401
s32 SEQ_UI_TRKEVNT_Init(u32 mode)
1402
{
1403
  // install callback routines
1404
  SEQ_UI_InstallButtonCallback(Button_Handler);
1405
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
1406
  SEQ_UI_InstallLEDCallback(LED_Handler);
1407
  SEQ_UI_InstallLCDCallback(LCD_Handler);
2041 tk 1408
  SEQ_UI_InstallMIDIINCallback(MIDI_IN_Handler);
174 tk 1409
 
2041 tk 1410
  // disable MIDI learn mode by default
1411
  midi_learn_mode = MIDI_LEARN_MODE_OFF;
1412
 
766 tk 1413
  // load charset (if this hasn't been done yet)
1414
  SEQ_LCD_InitSpecialChars(SEQ_LCD_CHARSET_Menu);
178 tk 1415
 
472 tk 1416
  selected_layer_config_track = SEQ_UI_VisibleTrackGet();
1417
  selected_layer_config = GetLayerConfig(selected_layer_config_track);
1418
 
2092 tk 1419
  dir_name[0] = 0;
1420
  pr_dialog = 0;
1421
 
472 tk 1422
  // initialize edit label vars (name is modified directly, not via ui_edit_name!)
1423
  ui_edit_name_cursor = 0;
1424
  ui_edit_preset_num_category = 0;
1425
  ui_edit_preset_num_label = 0;
1426
 
766 tk 1427
  import_flags.ALL = 0xff;
1428
 
174 tk 1429
  return 0; // no error
1430
}
176 tk 1431
 
1432
 
1433
/////////////////////////////////////////////////////////////////////////////
323 tk 1434
// Copies preset
176 tk 1435
/////////////////////////////////////////////////////////////////////////////
323 tk 1436
static s32 CopyPreset(u8 track, u8 config)
176 tk 1437
{
323 tk 1438
  // exit if invalid config
1439
  if( config >= (sizeof(layer_config)/sizeof(layer_config_t)) )
1440
    return -1; // invalid config
176 tk 1441
 
328 tk 1442
  layer_config_t *lc = (layer_config_t *)&layer_config[selected_layer_config];
1443
 
323 tk 1444
  // partitionate layers and clear all steps
328 tk 1445
  SEQ_PAR_TrackInit(track, lc->par_steps, lc->par_layers, lc->instruments);
1446
  SEQ_TRG_TrackInit(track, lc->trg_steps, lc->trg_layers, lc->instruments);
176 tk 1447
 
472 tk 1448
#if 0
1449
  // confusing if assignments are not changed under such a condition
336 tk 1450
  u8 init_assignments = lc->event_mode != SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
472 tk 1451
#else
1452
  u8 init_assignments = 1;
1453
#endif
336 tk 1454
 
328 tk 1455
  SEQ_CC_Set(track, SEQ_CC_MIDI_EVENT_MODE, lc->event_mode);
176 tk 1456
 
326 tk 1457
  // BEGIN TMP
328 tk 1458
  if( lc->event_mode == SEQ_EVENT_MODE_Drum ) {
729 tk 1459
    int i;
1460
 
1461
    for(i=0; i<16; ++i)
1462
      SEQ_LABEL_CopyPresetDrum(i, (char *)&seq_core_trk[track].name[5*i]);
326 tk 1463
  } else {
1464
    memset((char *)seq_core_trk[track].name, ' ', 80);
1465
  }
1466
  // END TMP
1467
 
324 tk 1468
  u8 only_layers = 0;
1469
  u8 all_triggers_cleared = 0;
335 tk 1470
  return SEQ_LAYER_CopyPreset(track, only_layers, all_triggers_cleared, init_assignments);
323 tk 1471
}
176 tk 1472
 
1473
 
323 tk 1474
/////////////////////////////////////////////////////////////////////////////
1475
// Determines current layer config
1476
/////////////////////////////////////////////////////////////////////////////
1477
static s32 GetLayerConfig(u8 track)
1478
{
1479
  int i;
1480
 
1481
  u8 event_mode = SEQ_CC_Get(track, SEQ_CC_MIDI_EVENT_MODE);
1482
  u8 par_layers = SEQ_PAR_NumLayersGet(track);
1483
  u16 par_steps = SEQ_PAR_NumStepsGet(track);
1484
  u8 trg_layers = SEQ_TRG_NumLayersGet(track);
1485
  u16 trg_steps = SEQ_TRG_NumStepsGet(track);
328 tk 1486
  u8 num_instruments = SEQ_PAR_NumInstrumentsGet(track);
323 tk 1487
 
1488
  for(i=0; i<(sizeof(layer_config)/sizeof(layer_config_t)); ++i) {
1489
    layer_config_t *lc = (layer_config_t *)&layer_config[i];
1490
    if( lc->event_mode == event_mode &&
1491
    lc->par_layers == par_layers && lc->par_steps == par_steps &&
325 tk 1492
    lc->trg_layers == trg_layers && lc->trg_steps == trg_steps &&
328 tk 1493
    lc->instruments == num_instruments ) {
323 tk 1494
      return i;
176 tk 1495
    }
1496
  }
1497
 
323 tk 1498
  return 0; // not found, return index to first config
176 tk 1499
}
178 tk 1500
 
756 tk 1501
/////////////////////////////////////////////////////////////////////////////
1502
// help function for Init button function
1503
/////////////////////////////////////////////////////////////////////////////
1504
static void InitReq(u32 dummy)
1505
{
1506
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1507
 
1508
  // TODO: copy preset for all selected tracks!
1509
  CopyPreset(visible_track, selected_layer_config);
1510
 
1511
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 1000, "Track has been", "initialized!");
1512
}
766 tk 1513
 
1514
 
1515
/////////////////////////////////////////////////////////////////////////////
1516
// help function to scan presets directory
1517
/////////////////////////////////////////////////////////////////////////////
1518
static s32 SEQ_UI_TRKEVNT_UpdateDirList(void)
1519
{
1520
  int item;
1521
 
1522
  MUTEX_SDCARD_TAKE;
1261 tk 1523
  dir_num_items = FILE_GetFiles("/PRESETS", "V4T", (char *)&ui_global_dir_list[0], NUM_LIST_DISPLAYED_ITEMS, dir_view_offset);
766 tk 1524
  MUTEX_SDCARD_GIVE;
1525
 
1526
  if( dir_num_items < 0 )
1527
    item = 0;
1528
  else if( dir_num_items < NUM_LIST_DISPLAYED_ITEMS )
1529
    item = dir_num_items;
1530
  else
1531
    item = NUM_LIST_DISPLAYED_ITEMS;
1532
 
1533
  while( item < NUM_LIST_DISPLAYED_ITEMS ) {
1534
    ui_global_dir_list[LIST_ENTRY_WIDTH*item] = 0;
1535
    ++item;
1536
  }
1537
 
1538
  return 0; // no error
1539
}
1540
 
1541
 
1542
/////////////////////////////////////////////////////////////////////////////
1543
// help function to start Track preset file export
1544
// returns 0 on success
1545
// returns != 0 on errors (dialog page will be changed accordingly)
1546
/////////////////////////////////////////////////////////////////////////////
1547
static s32 DoExport(u8 force_overwrite)
1548
{
1549
  s32 status;
1550
  int i;
1023 tk 1551
  char path[30];
766 tk 1552
 
1553
  // if an error is detected, we jump back to FNAME page
1554
  ui_selected_item = 0;
1555
  pr_dialog = PR_DIALOG_EXPORT_FNAME;
1556
 
1557
  u8 filename_valid = 1;
1558
  for(i=0; i<8; ++i)
1559
    if( dir_name[i] == '.' || dir_name[i] == '?' || dir_name[i] == ',' || dir_name[i] == '!' )
1560
      filename_valid = 0;
1561
 
1562
  if( !filename_valid ) {
1563
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Filename not valid!", "(remove . ? , !)");
1564
    return -1;
1565
  }
1566
 
1567
  if( dir_name[0] == ' ') {
1568
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Please enter", "Filename!");
1569
    return -2;
1570
  }
1571
 
956 tk 1572
  strcpy(path, "/PRESETS");
766 tk 1573
  MUTEX_SDCARD_TAKE;
1261 tk 1574
  status = FILE_MakeDir(path); // create directory if it doesn't exist
1575
  status = FILE_DirExists(path);
766 tk 1576
  MUTEX_SDCARD_GIVE;
1577
 
1578
  if( status < 0 ) {
1579
    SEQ_UI_SDCardErrMsg(2000, status);
1580
    return -3;
1581
  }
1582
 
1583
  if( status == 0 ) {
959 tk 1584
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "/PRESETS directory", "cannot be created!");
766 tk 1585
    return -4;
1586
  }
1587
 
1023 tk 1588
  char v4t_file[30];
956 tk 1589
  char *p = (char *)&v4t_file[0];
1590
  for(i=0; i<8; ++i) {
1591
    char c = dir_name[i];
1592
    if( c != ' ' )
1593
      *p++ = c;
1594
  }
1595
  *p++ = 0;
766 tk 1596
 
956 tk 1597
  sprintf(path, "/PRESETS/%s.v4t", v4t_file);
1598
 
766 tk 1599
  MUTEX_SDCARD_TAKE;
1261 tk 1600
  status = FILE_FileExists(path);
766 tk 1601
  MUTEX_SDCARD_GIVE;
1602
 
1603
  if( status < 0 ) {
1604
    SEQ_UI_SDCardErrMsg(2000, status);
1605
    return -5;
1606
  }
1607
 
1608
 
1609
  if( !force_overwrite && status == 1) {
1610
    // file exists - ask if it should be overwritten in a special dialog page
1611
    pr_dialog = PR_DIALOG_EXPORT_FEXISTS;
1612
    return 1;
1613
  }
1614
 
1615
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Exporting", path);
1616
 
769 tk 1617
  MUTEX_SDCARD_TAKE;
1618
  status=SEQ_FILE_T_Write(path, SEQ_UI_VisibleTrackGet());
1619
  MUTEX_SDCARD_GIVE;
1620
 
1621
  if( status < 0 ) {
766 tk 1622
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Error during Export!", "see MIOS Terminal!");
1623
    return -6;
1624
  }
1625
 
1626
  SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, "Export", "successfull!");
1627
 
1628
  return 0; // no error
1629
}
1630
 
1631
 
1632
/////////////////////////////////////////////////////////////////////////////
1633
// help function to start Track preset file export
1634
// returns 0 on success
1635
// returns != 0 on errors (dialog page will be changed accordingly)
1636
/////////////////////////////////////////////////////////////////////////////
1637
static s32 DoImport(void)
1638
{
1639
  s32 status;
1023 tk 1640
  char path[30];
766 tk 1641
  u8 visible_track = SEQ_UI_VisibleTrackGet();
1642
 
956 tk 1643
  sprintf(path, "/PRESETS/%s.V4T", dir_name);
766 tk 1644
 
769 tk 1645
  // mute track to avoid random effects while loading the file
1646
  MIOS32_IRQ_Disable(); // this operation should be atomic!
1015 tk 1647
  u8 muted = seq_core_trk_muted & (1 << visible_track);
769 tk 1648
  if( !muted )
1015 tk 1649
    seq_core_trk_muted |= (1 << visible_track);
769 tk 1650
  MIOS32_IRQ_Enable();
1651
 
1652
  // read file
766 tk 1653
  MUTEX_SDCARD_TAKE;
1654
  status = SEQ_FILE_T_Read(path, visible_track, import_flags);
1655
  MUTEX_SDCARD_GIVE;
1656
 
769 tk 1657
  // unmute track if it wasn't muted before
1658
  MIOS32_IRQ_Disable(); // this operation should be atomic!
1659
  if( !muted )
1015 tk 1660
    seq_core_trk_muted &= ~(1 << visible_track);
769 tk 1661
  MIOS32_IRQ_Enable();
1662
 
766 tk 1663
  if( status < 0 ) {
1664
    SEQ_UI_SDCardErrMsg(2000, status);
1665
  } else {
1666
    SEQ_UI_Msg(SEQ_UI_MSG_USER_R, 2000, path, "imported!");
1667
 
1668
    // fix layer config
1669
    selected_layer_config_track = visible_track;
1670
    selected_layer_config = GetLayerConfig(selected_layer_config_track);
1671
  }
1672
 
1673
  return 0; // no error
1674
}