Subversion Repositories svn.mios32

Rev

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