Subversion Repositories svn.mios32

Rev

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