Subversion Repositories svn.mios32

Rev

Rev 176 | Rev 179 | 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 178 2008-12-13 15:19:25Z tk $
2
/*
3
 * Track clock divider page
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>
19
#include "seq_lcd.h"
20
#include "seq_ui.h"
21
#include "seq_cc.h"
22
#include "seq_layer.h"
23
 
24
 
25
/////////////////////////////////////////////////////////////////////////////
26
// Local definitions
27
/////////////////////////////////////////////////////////////////////////////
28
 
29
#define NUM_OF_ITEMS       8
30
#define ITEM_GXTY          0
31
#define ITEM_EVNT_MODE     1
32
#define ITEM_EVNT_CONST1   2
33
#define ITEM_EVNT_CONST2   3
34
#define ITEM_EVNT_CONST3   4
35
#define ITEM_MIDI_CHANNEL  5
36
#define ITEM_MIDI_PORT     6
37
#define ITEM_PRESET        7
38
 
39
 
40
/////////////////////////////////////////////////////////////////////////////
176 tk 41
// Local prototypes
42
/////////////////////////////////////////////////////////////////////////////
43
 
44
static s32 PrintCValue(u8 track, u8 const_ix);
178 tk 45
static s32 CopyPreset(u8 track);
176 tk 46
 
47
 
48
/////////////////////////////////////////////////////////////////////////////
178 tk 49
// Local variables
50
/////////////////////////////////////////////////////////////////////////////
51
 
52
static u8 preset_copied;
53
static u8 old_evnt_mode[SEQ_CORE_NUM_TRACKS];
54
 
55
 
56
/////////////////////////////////////////////////////////////////////////////
174 tk 57
// Local LED handler function
58
/////////////////////////////////////////////////////////////////////////////
59
static s32 LED_Handler(u16 *gp_leds)
60
{
178 tk 61
  if( ui_cursor_flash ) { // if flashing flag active: no LED flag set
62
    // flash preset LEDs if current preset doesn't match with old preset
63
    // this notifies the user, that he should press the "copy preset" button
64
    u8 visible_track = SEQ_UI_VisibleTrackGet();
65
    if( old_evnt_mode[visible_track] != SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVNT_MODE) )
66
      *gp_leds = 0xc000;
67
 
174 tk 68
    return 0;
178 tk 69
  }
174 tk 70
 
71
  switch( ui_selected_item ) {
72
    case ITEM_GXTY: *gp_leds = 0x0001; break;
73
    case ITEM_EVNT_MODE: *gp_leds = 0x001e; break;
74
    case ITEM_EVNT_CONST1: *gp_leds = 0x0020; break;
75
    case ITEM_EVNT_CONST2: *gp_leds = 0x0040; break;
76
    case ITEM_EVNT_CONST3: *gp_leds = 0x0080; break;
77
    case ITEM_MIDI_CHANNEL: *gp_leds = 0x0100; break;
78
    case ITEM_MIDI_PORT: *gp_leds = 0x0200; break;
178 tk 79
    // case ITEM_PRESET: *gp_leds = 0xc000; break;
174 tk 80
  }
81
 
82
  return 0; // no error
83
}
84
 
85
 
86
/////////////////////////////////////////////////////////////////////////////
87
// Local encoder callback function
88
// Should return:
89
//   1 if value has been changed
90
//   0 if value hasn't been changed
91
//  -1 if invalid or unsupported encoder
92
/////////////////////////////////////////////////////////////////////////////
93
static s32 Encoder_Handler(seq_ui_encoder_t encoder, s32 incrementer)
94
{
178 tk 95
  preset_copied = 0; // for display notification
96
 
174 tk 97
  switch( encoder ) {
98
    case SEQ_UI_ENCODER_GP1:
99
      ui_selected_item = ITEM_GXTY;
100
      break;
101
 
102
    case SEQ_UI_ENCODER_GP2:
103
    case SEQ_UI_ENCODER_GP3:
104
    case SEQ_UI_ENCODER_GP4:
105
    case SEQ_UI_ENCODER_GP5:
106
      ui_selected_item = ITEM_EVNT_MODE;
107
      break;
108
 
109
    case SEQ_UI_ENCODER_GP6:
110
      ui_selected_item = ITEM_EVNT_CONST1;
111
      break;
112
 
113
    case SEQ_UI_ENCODER_GP7:
114
      ui_selected_item = ITEM_EVNT_CONST2;
115
      break;
116
 
117
    case SEQ_UI_ENCODER_GP8:
118
      ui_selected_item = ITEM_EVNT_CONST3;
119
      break;
120
 
121
    case SEQ_UI_ENCODER_GP9:
122
      ui_selected_item = ITEM_MIDI_CHANNEL;
123
      break;
124
 
125
    case SEQ_UI_ENCODER_GP10:
126
      ui_selected_item = ITEM_MIDI_PORT;
127
      break;
128
 
129
    case SEQ_UI_ENCODER_GP11:
130
    case SEQ_UI_ENCODER_GP12:
131
    case SEQ_UI_ENCODER_GP13:
132
    case SEQ_UI_ENCODER_GP14:
133
      return -1; // not mapped
134
 
135
    case SEQ_UI_ENCODER_GP15:
136
    case SEQ_UI_ENCODER_GP16:
137
      ui_selected_item = ITEM_PRESET;
138
      break;
139
  }
140
 
141
  // for GP encoders and Datawheel
142
  switch( ui_selected_item ) {
143
    case ITEM_GXTY:          return SEQ_UI_GxTyInc(incrementer);
144
    case ITEM_EVNT_MODE:     return SEQ_UI_CCInc(SEQ_CC_MIDI_EVNT_MODE, 0, SEQ_LAYER_EVNTMODE_NUM-1, incrementer);
145
    case ITEM_EVNT_CONST1:   return SEQ_UI_CCInc(SEQ_CC_MIDI_EVNT_CONST1, 0, 127, incrementer);
146
    case ITEM_EVNT_CONST2:   return SEQ_UI_CCInc(SEQ_CC_MIDI_EVNT_CONST2, 0, 127, incrementer);
147
    case ITEM_EVNT_CONST3:   return SEQ_UI_CCInc(SEQ_CC_MIDI_EVNT_CONST3, 0, 127, incrementer);
178 tk 148
    case ITEM_MIDI_CHANNEL:  return SEQ_UI_CCInc(SEQ_CC_MIDI_CHANNEL, 0, 15, incrementer);
149
    case ITEM_MIDI_PORT:     return SEQ_UI_CCInc(SEQ_CC_MIDI_PORT, 0, 3, incrementer); // TODO: use global define for number of MIDI ports!
150
    case ITEM_PRESET:        CopyPreset(SEQ_UI_VisibleTrackGet()); return 1;
174 tk 151
  }
152
 
153
  return -1; // invalid or unsupported encoder
154
}
155
 
156
 
157
/////////////////////////////////////////////////////////////////////////////
158
// Local button callback function
159
// Should return:
160
//   1 if value has been changed
161
//   0 if value hasn't been changed
162
//  -1 if invalid or unsupported button
163
/////////////////////////////////////////////////////////////////////////////
164
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
165
{
178 tk 166
  preset_copied = 0; // for display notification - always clear this flag when any button has been pressed/depressed
167
 
174 tk 168
  if( depressed ) return 0; // ignore when button depressed
169
 
170
  u8 visible_track = SEQ_UI_VisibleTrackGet();
171
 
172
  switch( button ) {
173
    case SEQ_UI_BUTTON_GP1:
174
      ui_selected_item = ITEM_GXTY;
175
      return 0; // value hasn't been changed
176
 
177
    case SEQ_UI_BUTTON_GP2:
178
    case SEQ_UI_BUTTON_GP3:
179
    case SEQ_UI_BUTTON_GP4:
180
    case SEQ_UI_BUTTON_GP5:
181
      ui_selected_item = ITEM_EVNT_MODE;
182
      return 0; // value hasn't been changed
183
 
184
    case SEQ_UI_BUTTON_GP6:
185
      ui_selected_item = ITEM_EVNT_CONST1;
186
      return 0; // value hasn't been changed
187
 
188
    case SEQ_UI_BUTTON_GP7:
189
      ui_selected_item = ITEM_EVNT_CONST2;
190
      return 0; // value hasn't been changed
191
 
192
    case SEQ_UI_BUTTON_GP8:
193
      ui_selected_item = ITEM_EVNT_CONST3;
194
      return 0; // value hasn't been changed
195
 
196
    case SEQ_UI_BUTTON_GP9:
197
      ui_selected_item = ITEM_MIDI_CHANNEL;
198
      return 0; // value hasn't been changed
199
 
200
    case SEQ_UI_BUTTON_GP10:
178 tk 201
      ui_selected_item = ITEM_MIDI_PORT;
174 tk 202
      return 0; // value hasn't been changed
203
 
204
    case SEQ_UI_BUTTON_GP11:
205
    case SEQ_UI_BUTTON_GP12:
206
    case SEQ_UI_BUTTON_GP13:
207
    case SEQ_UI_BUTTON_GP14:
178 tk 208
      return -1; // not mapped
174 tk 209
 
210
    case SEQ_UI_BUTTON_GP15:
211
    case SEQ_UI_BUTTON_GP16:
178 tk 212
      // ui_selected_item = ITEM_PRESET;
213
      CopyPreset(SEQ_UI_VisibleTrackGet());
214
      return 1; // value has been changed
174 tk 215
 
216
    case SEQ_UI_BUTTON_Select:
217
    case SEQ_UI_BUTTON_Right:
218
      if( ++ui_selected_item >= NUM_OF_ITEMS )
219
    ui_selected_item = 0;
220
      return 1; // value always changed
221
 
222
    case SEQ_UI_BUTTON_Left:
223
      if( ui_selected_item == 0 )
224
    ui_selected_item = NUM_OF_ITEMS-1;
225
      return 1; // value always changed
226
 
227
    case SEQ_UI_BUTTON_Up:
228
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
229
 
230
    case SEQ_UI_BUTTON_Down:
231
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
232
  }
233
 
234
  return -1; // invalid or unsupported button
235
}
236
 
237
 
238
/////////////////////////////////////////////////////////////////////////////
239
// Local Display Handler function
240
// IN: <high_prio>: if set, a high-priority LCD update is requested
241
/////////////////////////////////////////////////////////////////////////////
242
static s32 LCD_Handler(u8 high_prio)
243
{
244
  if( high_prio )
245
    return 0; // there are no high-priority updates
246
 
247
  // layout:
248
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
249
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
250
  // <--------------------------------------><-------------------------------------->
251
  // Trk. Layer Assignments:xx Val1 Val2 Val3Chn. Port                     >> COPY <<
252
  // G1T1 A:Chrd B:Vel. C:Len.  127  127  127 16  IIC2 (not available)     > PRESET <
253
 
254
  u8 visible_track = SEQ_UI_VisibleTrackGet();
255
  u8 evnt_mode = SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVNT_MODE);
256
 
257
  ///////////////////////////////////////////////////////////////////////////
258
  MIOS32_LCD_DeviceSet(0);
259
  MIOS32_LCD_CursorSet(0, 0);
260
  MIOS32_LCD_PrintString("Trk. Layer Assignments:");
261
  ///
262
  if( ui_selected_item == ITEM_EVNT_MODE && ui_cursor_flash ) {
263
    SEQ_LCD_PrintSpaces(2);
264
  } else {
265
    MIOS32_LCD_PrintFormattedString("%2d", evnt_mode + 1);
266
  }
267
  MIOS32_LCD_PrintFormattedString(" %s %s %s",
268
                  SEQ_LAYER_CTypeStr(evnt_mode, 0),
269
                  SEQ_LAYER_CTypeStr(evnt_mode, 1),
270
                  SEQ_LAYER_CTypeStr(evnt_mode, 2));
271
  ///
272
  MIOS32_LCD_PrintString(" Val1 Val2 Val3");
273
  MIOS32_LCD_DeviceSet(1);
274
  MIOS32_LCD_CursorSet(0, 0);
178 tk 275
  MIOS32_LCD_PrintString("Chn. Port                     "); // ">> COPY <<" will be printed later
174 tk 276
 
277
 
278
  ///////////////////////////////////////////////////////////////////////////
279
  MIOS32_LCD_DeviceSet(0);
280
  MIOS32_LCD_CursorSet(0, 1);
281
 
282
  if( ui_selected_item == ITEM_GXTY && ui_cursor_flash ) {
283
    SEQ_LCD_PrintSpaces(5);
284
  } else {
285
    SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
286
    SEQ_LCD_PrintSpaces(1);
287
  }
288
 
289
  ///////////////////////////////////////////////////////////////////////////
290
  MIOS32_LCD_PrintString((ui_selected_item == ITEM_EVNT_MODE && ui_cursor_flash) ? "  " : "A:");
291
  MIOS32_LCD_PrintString(SEQ_LAYER_VTypeStr(evnt_mode, 0));
292
  SEQ_LCD_PrintSpaces(1);
293
 
294
  MIOS32_LCD_PrintString((ui_selected_item == ITEM_EVNT_MODE && ui_cursor_flash) ? "  " : "B:");
295
  MIOS32_LCD_PrintString(SEQ_LAYER_VTypeStr(evnt_mode, 1));
296
  SEQ_LCD_PrintSpaces(1);
297
 
298
  MIOS32_LCD_PrintString((ui_selected_item == ITEM_EVNT_MODE && ui_cursor_flash) ? "  " : "C:");
299
  MIOS32_LCD_PrintString(SEQ_LAYER_VTypeStr(evnt_mode, 2));
300
 
301
 
302
  ///////////////////////////////////////////////////////////////////////////
176 tk 303
  int i;
304
  for(i=0; i<3; ++i) {
305
    if( ui_selected_item == (ITEM_EVNT_CONST1+i) && ui_cursor_flash ) {
306
      SEQ_LCD_PrintSpaces(5);
307
    } else {
308
      SEQ_LCD_PrintSpaces(1);
309
      PrintCValue(visible_track, i);
310
    }
174 tk 311
  }
312
 
313
  ///////////////////////////////////////////////////////////////////////////
314
  MIOS32_LCD_DeviceSet(1);
315
  MIOS32_LCD_CursorSet(0, 1);
316
  if( ui_selected_item == ITEM_MIDI_CHANNEL && ui_cursor_flash ) {
317
    SEQ_LCD_PrintSpaces(5);
318
  } else {
319
    MIOS32_LCD_PrintFormattedString("%3d  ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_CHANNEL)+1);
320
  }
321
 
322
  ///////////////////////////////////////////////////////////////////////////
323
  if( ui_selected_item == ITEM_MIDI_PORT && ui_cursor_flash ) {
324
    SEQ_LCD_PrintSpaces(5);
325
  } else {
326
    MIOS32_LCD_PrintFormattedString("0x%02x ", SEQ_CC_Get(visible_track, SEQ_CC_MIDI_PORT)); // TODO: get MIDI port name from SEQ_MIDI
327
  }
328
#if 0
329
  MIOS32_LCD_PrintString(1 ? "(not available)" : "(available)    "); // TODO: get MIDI port availability from SEQ_MIDI
330
#else
331
  SEQ_LCD_PrintSpaces(15);
332
#endif
178 tk 333
  SEQ_LCD_PrintSpaces(5);
174 tk 334
 
335
  ///////////////////////////////////////////////////////////////////////////
336
 
178 tk 337
  if( preset_copied ) {
338
    MIOS32_LCD_CursorSet(30, 0);
339
    MIOS32_LCD_PrintString("> PRESET <");
340
    MIOS32_LCD_CursorSet(30, 1);
341
    MIOS32_LCD_PrintString("> COPIED <");
342
  } else {
343
    MIOS32_LCD_CursorSet(30, 0);
344
    MIOS32_LCD_PrintString(">> COPY <<");
345
    MIOS32_LCD_CursorSet(30, 1);
346
    if( old_evnt_mode[visible_track] != SEQ_CC_Get(visible_track, SEQ_CC_MIDI_EVNT_MODE) )
347
      MIOS32_LCD_PrintString(">PRESET!!<");
348
    else
349
      MIOS32_LCD_PrintString("> PRESET <");
350
  }
174 tk 351
 
178 tk 352
 
174 tk 353
  return 0; // no error
354
}
355
 
356
 
357
/////////////////////////////////////////////////////////////////////////////
358
// Initialisation
359
/////////////////////////////////////////////////////////////////////////////
360
s32 SEQ_UI_TRKEVNT_Init(u32 mode)
361
{
362
  // install callback routines
363
  SEQ_UI_InstallButtonCallback(Button_Handler);
364
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
365
  SEQ_UI_InstallLEDCallback(LED_Handler);
366
  SEQ_UI_InstallLCDCallback(LCD_Handler);
367
 
178 tk 368
  preset_copied = 0;
369
 
370
  u8 track;
371
  for(track=0; track<SEQ_CORE_NUM_TRACKS; ++track)
372
    old_evnt_mode[track] = SEQ_CC_Get(track, SEQ_CC_MIDI_EVNT_MODE);
373
 
174 tk 374
  return 0; // no error
375
}
176 tk 376
 
377
 
378
/////////////////////////////////////////////////////////////////////////////
379
// Help function to print a constant value (4 characters)
380
/////////////////////////////////////////////////////////////////////////////
381
static s32 PrintCValue(u8 track, u8 const_ix)
382
{
383
  u8 value = SEQ_CC_Get(track, SEQ_CC_MIDI_EVNT_CONST1 + const_ix);
384
 
385
  switch( SEQ_LAYER_GetCControlType(track, const_ix) ) {
386
    case SEQ_LAYER_ControlType_None:
387
      SEQ_LCD_PrintSpaces(4);
388
      break;
389
 
390
    case SEQ_LAYER_ControlType_Note:
391
      MIOS32_LCD_PrintChar(' ');
392
      SEQ_LCD_PrintNote(value);
393
      break;
394
 
395
    case SEQ_LAYER_ControlType_Velocity:
396
    case SEQ_LAYER_ControlType_CC:
397
      MIOS32_LCD_PrintFormattedString(" %3d", value);
398
      break;
399
 
400
    case SEQ_LAYER_ControlType_Length:
178 tk 401
      SEQ_LCD_PrintGatelength(value);
176 tk 402
      break;
403
 
404
    case SEQ_LAYER_ControlType_CMEM_T:
405
    {
406
      u8 cmem_track = value % SEQ_CORE_NUM_TRACKS;
407
      MIOS32_LCD_PrintFormattedString("G%dT%d", (cmem_track >> 2)+1, (cmem_track & 3)+1);
408
    }
409
    break;
410
 
411
    default:
412
      MIOS32_LCD_PrintString(" ???");
413
      break;
414
  }
415
 
416
  return 0; // no error
417
}
178 tk 418
 
419
 
420
/////////////////////////////////////////////////////////////////////////////
421
// Copies preset
422
/////////////////////////////////////////////////////////////////////////////
423
s32 CopyPreset(u8 track)
424
{
425
  preset_copied = 1;
426
  old_evnt_mode[track] = SEQ_CC_Get(track, SEQ_CC_MIDI_EVNT_MODE);
427
  return SEQ_LAYER_CopyPreset(track, 0); // 0=all settings
428
}