Subversion Repositories svn.mios32

Rev

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