Subversion Repositories svn.mios32

Rev

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