Subversion Repositories svn.mios32

Rev

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