Subversion Repositories svn.mios32

Rev

Rev 2128 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2532 tk 1
// $Id: seq_ui_fx_dupl.c 2532 2017-10-12 21:50:45Z tk $
1859 tk 2
/*
3
 * Duplicate Note Fx 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_midi_port.h"
23
 
24
 
25
/////////////////////////////////////////////////////////////////////////////
26
// Local definitions
27
/////////////////////////////////////////////////////////////////////////////
28
 
2128 borfo 29
#define NUM_OF_ITEMS       7
1859 tk 30
#define ITEM_GXTY          0
2128 borfo 31
#define ITEM_ENABLE        1
32
#define ITEM_NUM_CHN       2
33
#define ITEM_FIRST_CHN     3
34
#define ITEM_PORT          4
35
#define ITEM_FWD_NON_NOTES 5
36
#define ITEM_BEH           6
1859 tk 37
 
38
 
39
/////////////////////////////////////////////////////////////////////////////
40
// Local LED handler function
41
/////////////////////////////////////////////////////////////////////////////
42
static s32 LED_Handler(u16 *gp_leds)
43
{
44
  if( ui_cursor_flash ) // if flashing flag active: no LED flag set
45
    return 0;
46
 
47
  switch( ui_selected_item ) {
48
  case ITEM_GXTY:          *gp_leds = 0x0001; break;
2128 borfo 49
  case ITEM_ENABLE:        *gp_leds = 0x0002; break;
50
  case ITEM_NUM_CHN:       *gp_leds = 0x001c; break;
1859 tk 51
  case ITEM_FIRST_CHN:     *gp_leds = 0x00e0; break;
52
  case ITEM_PORT:          *gp_leds = 0x0100; break;
53
  case ITEM_FWD_NON_NOTES: *gp_leds = 0x0600; break;
54
  case ITEM_BEH:           *gp_leds = 0xf800; break;
55
  }
56
 
57
  return 0; // no error
58
}
59
 
60
 
61
/////////////////////////////////////////////////////////////////////////////
62
// Local encoder callback function
63
// Should return:
64
//   1 if value has been changed
65
//   0 if value hasn't been changed
66
//  -1 if invalid or unsupported encoder
67
/////////////////////////////////////////////////////////////////////////////
68
static s32 Encoder_Handler(seq_ui_encoder_t encoder, s32 incrementer)
69
{
70
  u8 visible_track = SEQ_UI_VisibleTrackGet();
71
 
72
  switch( encoder ) {
73
  case SEQ_UI_ENCODER_GP1:
74
    ui_selected_item = ITEM_GXTY;
75
    break;
76
 
77
  case SEQ_UI_ENCODER_GP2:
2128 borfo 78
    ui_selected_item = ITEM_ENABLE;
79
    break;
80
 
1859 tk 81
  case SEQ_UI_ENCODER_GP3:
82
  case SEQ_UI_ENCODER_GP4:
83
  case SEQ_UI_ENCODER_GP5:
84
    ui_selected_item = ITEM_NUM_CHN;
85
    break;
86
 
87
  case SEQ_UI_ENCODER_GP6:
88
  case SEQ_UI_ENCODER_GP7:
89
  case SEQ_UI_ENCODER_GP8:
90
    ui_selected_item = ITEM_FIRST_CHN;
91
    break;
92
 
93
  case SEQ_UI_ENCODER_GP9:
94
    ui_selected_item = ITEM_PORT;
95
    break;
96
 
97
  case SEQ_UI_ENCODER_GP10:
98
  case SEQ_UI_ENCODER_GP11:
99
    ui_selected_item = ITEM_FWD_NON_NOTES;
100
    break;
101
 
102
  case SEQ_UI_ENCODER_GP12:
103
  case SEQ_UI_ENCODER_GP13:
104
  case SEQ_UI_ENCODER_GP14:
105
  case SEQ_UI_ENCODER_GP15:
106
  case SEQ_UI_ENCODER_GP16:
107
    ui_selected_item = ITEM_BEH;
108
    break;
109
  }
110
 
111
  // for GP encoders and Datawheel
112
  switch( ui_selected_item ) {
113
  case ITEM_GXTY:          return SEQ_UI_GxTyInc(incrementer);
2128 borfo 114
 
115
  case ITEM_ENABLE: {
116
    u8 value = (SEQ_CC_Get(visible_track, SEQ_CC_FX_MIDI_NUM_CHANNELS) & 0x40) ? 0 : 1; // inverted
117
 
118
    if( incrementer )
119
      value = incrementer > 0 ? 1 : 0;
120
    else
121
      value ^= 1;
122
 
123
    SEQ_UI_CC_SetFlags(SEQ_CC_FX_MIDI_NUM_CHANNELS, 0x40, value ? 0x00 : 0x40);
124
    return 1; // value changed
125
  } break;
126
 
127
  case ITEM_NUM_CHN: {
128
    u8 value = SEQ_CC_Get(visible_track, SEQ_CC_FX_MIDI_NUM_CHANNELS) & 0x3f;
129
    if( SEQ_UI_Var8_Inc(&value, 0, 16, incrementer) >= 1 ) {
130
      SEQ_UI_CC_SetFlags(SEQ_CC_FX_MIDI_NUM_CHANNELS, 0x3f, value);
131
      return 1; // value changed
132
    }
133
    return 0; // no change
134
  } break;
135
 
1859 tk 136
  case ITEM_FIRST_CHN:     return SEQ_UI_CC_Inc(SEQ_CC_FX_MIDI_CHANNEL, 0, 15, incrementer);
137
  case ITEM_PORT: {
138
    mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_FX_MIDI_PORT);
139
    u8 port_ix = SEQ_MIDI_PORT_OutIxGet(port);
1860 tk 140
    if( SEQ_UI_Var8_Inc(&port_ix, 0, SEQ_MIDI_PORT_OutNumGet()-1-4, incrementer) ) { // -4 so that Bus1..Bus4 can't be selected (not supported)
1859 tk 141
      mios32_midi_port_t new_port = SEQ_MIDI_PORT_OutPortGet(port_ix);
142
      SEQ_UI_CC_Set(SEQ_CC_FX_MIDI_PORT, new_port);
143
      return 1; // value changed
144
    }
145
    return 0; // value not changed
146
  } break;
147
  case ITEM_FWD_NON_NOTES: {
148
    if( !incrementer ) // toggle flag
149
      incrementer = (SEQ_CC_Get(visible_track, SEQ_CC_FX_MIDI_MODE) & (1<<3)) ? -1 : 1;
150
    return SEQ_UI_CC_SetFlags(SEQ_CC_FX_MIDI_MODE, (1<<3), (incrementer >= 0) ? (1<<3) : 0);
151
  }
152
  case ITEM_BEH: {
153
    u8 beh = SEQ_CC_Get(visible_track, SEQ_CC_FX_MIDI_MODE) & 7;
154
    if( SEQ_UI_Var8_Inc(&beh, 0, 3, incrementer) > 0 ) {
155
      return SEQ_UI_CC_SetFlags(SEQ_CC_FX_MIDI_MODE, (7<<0), beh);
156
    }
157
    return 0;
158
  }
159
  }
160
 
161
  return -1; // invalid or unsupported encoder
162
}
163
 
164
 
165
/////////////////////////////////////////////////////////////////////////////
166
// Local button callback function
167
// Should return:
168
//   1 if value has been changed
169
//   0 if value hasn't been changed
170
//  -1 if invalid or unsupported button
171
/////////////////////////////////////////////////////////////////////////////
172
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
173
{
174
  if( depressed ) return 0; // ignore when button depressed
175
 
176
#if 0
177
  // leads to: comparison is always true due to limited range of data type
178
  if( button >= SEQ_UI_BUTTON_GP1 && button <= SEQ_UI_BUTTON_GP16 ) {
179
#else
180
  if( button <= SEQ_UI_BUTTON_GP16 ) {
181
#endif
182
    // re-use encoder handler - only select UI item, don't increment
183
    return Encoder_Handler((int)button, 0);
184
  }
185
 
186
  // remaining buttons:
187
  switch( button ) {
188
    case SEQ_UI_BUTTON_Select:
189
    case SEQ_UI_BUTTON_Right:
190
      if( ++ui_selected_item >= NUM_OF_ITEMS )
191
    ui_selected_item = 0;
192
      return 1; // value always changed
193
 
194
    case SEQ_UI_BUTTON_Left:
195
      if( ui_selected_item == 0 )
196
    ui_selected_item = NUM_OF_ITEMS-1;
197
      else
198
    --ui_selected_item;
199
      return 1; // value always changed
200
 
201
    case SEQ_UI_BUTTON_Up:
202
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);
203
 
204
    case SEQ_UI_BUTTON_Down:
205
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
206
  }
207
 
208
  return -1; // invalid or unsupported button
209
}
210
 
211
 
212
/////////////////////////////////////////////////////////////////////////////
213
// Local Display Handler function
214
// IN: <high_prio>: if set, a high-priority LCD update is requested
215
/////////////////////////////////////////////////////////////////////////////
216
static s32 LCD_Handler(u8 high_prio)
217
{
218
  if( high_prio )
219
    return 0; // there are no high-priority updates
220
 
221
  // layout:
222
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
223
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
224
  // <--------------------------------------><-------------------------------------->
225
  // Trk. Number of additional  First ChannelPort Non-Notes  Mode                    
1860 tk 226
  // GxTy     Channels:  3            2      Same Forwarded  Alternate with EchoSynch
1859 tk 227
 
228
  u8 visible_track = SEQ_UI_VisibleTrackGet();
229
 
230
  ///////////////////////////////////////////////////////////////////////////
231
  SEQ_LCD_CursorSet(0, 0);
2128 borfo 232
  SEQ_LCD_PrintString("Trk. Dupl       Aditional  First ChannelPort Non-Notes  Mode");
1859 tk 233
  SEQ_LCD_PrintSpaces(20);
234
 
235
  ///////////////////////////////////////////////////////////////////////////
236
  SEQ_LCD_CursorSet(0, 1);
237
 
238
  if( ui_selected_item == ITEM_GXTY && ui_cursor_flash ) {
239
    SEQ_LCD_PrintSpaces(4);
240
  } else {
241
    SEQ_LCD_PrintGxTy(ui_selected_group, ui_selected_tracks);
242
  }
2128 borfo 243
  SEQ_LCD_PrintSpaces(1);
1859 tk 244
 
245
  ///////////////////////////////////////////////////////////////////////////
2128 borfo 246
  if( ui_selected_item == ITEM_ENABLE && ui_cursor_flash ) {
247
    SEQ_LCD_PrintSpaces(3);
248
  } else {
249
    SEQ_LCD_PrintString((SEQ_CC_Get(visible_track, SEQ_CC_FX_MIDI_NUM_CHANNELS) & 0x40) ? "off" : "on ");
250
  }
251
  SEQ_LCD_PrintSpaces(4);
252
 
253
  ///////////////////////////////////////////////////////////////////////////
1859 tk 254
  SEQ_LCD_PrintString("Channels: ");
255
  if( ui_selected_item == ITEM_NUM_CHN && ui_cursor_flash ) {
256
    SEQ_LCD_PrintSpaces(2);
257
  } else {
2128 borfo 258
    SEQ_LCD_PrintFormattedString("%2d", SEQ_CC_Get(visible_track, SEQ_CC_FX_MIDI_NUM_CHANNELS) & 0x3f);
1859 tk 259
  }
2128 borfo 260
  SEQ_LCD_PrintSpaces(8);
1859 tk 261
 
262
  ///////////////////////////////////////////////////////////////////////////
263
  if( ui_selected_item == ITEM_FIRST_CHN && ui_cursor_flash ) {
264
    SEQ_LCD_PrintSpaces(2);
265
  } else {
266
    SEQ_LCD_PrintFormattedString("%2d", SEQ_CC_Get(visible_track, SEQ_CC_FX_MIDI_CHANNEL) + 1);
267
  }
268
 
269
  SEQ_LCD_PrintSpaces(6);
270
 
271
  ///////////////////////////////////////////////////////////////////////////
272
  mios32_midi_port_t port = SEQ_CC_Get(visible_track, SEQ_CC_FX_MIDI_PORT);
273
  if( ui_selected_item == ITEM_PORT && ui_cursor_flash ) {
274
    SEQ_LCD_PrintSpaces(5);
275
  } else {
1860 tk 276
    if( port == DEFAULT ) {
277
      SEQ_LCD_PrintString("Same ");
278
    } else {
279
      SEQ_LCD_PrintMIDIOutPort(port);
280
      SEQ_LCD_PrintChar(SEQ_MIDI_PORT_OutCheckAvailable(port) ? ' ' : '*');
281
    }
1859 tk 282
  }
283
 
284
  ///////////////////////////////////////////////////////////////////////////
285
  seq_core_fx_midi_mode_t fx_midi_mode;
286
  fx_midi_mode.ALL = SEQ_CC_Get(visible_track, SEQ_CC_FX_MIDI_MODE);
287
  if( ui_selected_item == ITEM_FWD_NON_NOTES && ui_cursor_flash ) {
288
    SEQ_LCD_PrintSpaces(9);
289
  } else {
290
    if( fx_midi_mode.fwd_non_notes ) {
291
      SEQ_LCD_PrintString("Forwarded");
292
    } else {
293
      SEQ_LCD_PrintString("Filtered ");
294
    }
295
  }
296
  SEQ_LCD_PrintSpaces(2);
297
 
298
  ///////////////////////////////////////////////////////////////////////////
299
  if( ui_selected_item == ITEM_BEH && ui_cursor_flash ) {
300
    SEQ_LCD_PrintSpaces(24);
301
  } else {
302
    const char *mode_str[4] = {
303
      "Forward to all Channels",
304
      "Alternate Channels",
305
      "Alternate with EchoSynch",
306
      "Random Channel Selection",
307
    };
308
    SEQ_LCD_PrintStringPadded((char *)mode_str[(fx_midi_mode.beh < 4) ? fx_midi_mode.beh : 3], 24);
309
  }
310
 
311
 
312
  ///////////////////////////////////////////////////////////////////////////
313
 
314
  return 0; // no error
315
}
316
 
317
 
318
/////////////////////////////////////////////////////////////////////////////
319
// Initialisation
320
/////////////////////////////////////////////////////////////////////////////
321
s32 SEQ_UI_FX_DUPL_Init(u32 mode)
322
{
323
  // install callback routines
324
  SEQ_UI_InstallButtonCallback(Button_Handler);
325
  SEQ_UI_InstallEncoderCallback(Encoder_Handler);
326
  SEQ_UI_InstallLEDCallback(LED_Handler);
327
  SEQ_UI_InstallLCDCallback(LCD_Handler);
328
 
329
  return 0; // no error
330
}