Subversion Repositories svn.mios32

Rev

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