-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannel_display_object.js
164 lines (130 loc) · 3.37 KB
/
channel_display_object.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
* Copyright 2015 Alan Drees
*
* Purpose:
* Implements an object representing a display output
*
* Dependencies:
*/
var ChannelDisplay = ChannelDisplay || {};
/**\fn ChannelDisplay.ChannelDisplay
*
* Channel Display object constructor
*
* @param options (object) options object
* @param parse_func (function) function which determines how to parse the string
* @param instance (integer) represents the control to send data for
* @param midi_instance (integer) midi instance to send data for
*
* @returns None
*/
ChannelDisplay.ChannelDisplay = function(options, parse_func, instance, midi_instance)
{
this.midi_instance = midi_instance;
this.parse_func = parse_func;
this.instance = instance;
this.line_length = options.line_length;
if(options.osc === true)
{
this._init_osc();
this._send_data = ChannelDisplay.ChannelDisplay.prototype._send_osc;
}
else
{
this._send_data = ChannelDisplay.ChannelDisplay.prototype._send_midi;
}
}
/**\fn ChannelDisplay.ChannelDisplay.prototype.send_text
*
* Parses the text 4 lines, and sends it to display
*
* @param text (string) string to send to the display
*
* @returns None
*/
ChannelDisplay.ChannelDisplay.prototype.send_text = function(text)
{
var lines = {0 : '',
1 : '',
2 : '',
3 : ''};
if(typeof this.parse_func === 'function')
{
lines = this.parse_func(text);
}
else
{
lines[1] = text.substring(0, this.line_length);
}
if(text !== '')
{
var midi_out = host.getMidiOutPort(this.midi_instance);
midi_out.sendMidi(0xA0 + this.instance,
0,
0);
for(var line in lines)
{
this._send_data(this.instance, parseInt(line), lines[line]);
}
midi_out.sendMidi(0xC0 + this.instance,
0,
0);
}
}
/**\fn ChannelDisplay.ChannelDisplay.prototype.set_parse_func
*
* Updates the text line parsing function. I do no type checking in case you want to remove the parser.
*
* @param func (function) Function to set the line parser to
*
* @returns None
*/
ChannelDisplay.ChannelDisplay.prototype.set_parse_func = function(func)
{
this.parse_func = func;
}
/**\fn ChannelDisplay.ChannelDisplay.prototype._send_midi
*
* Sends the data to the controller via MIDI
*
* @param instance (integer) display object instance
* @param line (integer) line number to output for
* @param text (string) string text to output
*
* @returns None
*/
ChannelDisplay.ChannelDisplay.prototype._send_midi = function(instance, line, text)
{
if(text.length > 20){ text = text.substring(0, 20); }
//send the control initialization
var midi_out = host.getMidiOutPort(this.midi_instance);
var i = 0;
var line_output = line << 5;
var charcode = 0;
for(i = 0; i < text.length; i++)
{
charcode = text.substring(i, i + 1).charCodeAt();
midi_out.sendMidi(0xB0 + instance,
line_output + i,
charcode);
}
}
/**\fn ChannelDisplay.ChannelDisplay.prototype._send_osc
*
* Sends the data to the controller via OSC
*
* @param line (integer) line number to output for
* @param text (string) string text to output
*
* @returns None
*/
ChannelDisplay.ChannelDisplay.prototype._send_osc = function(line, text){ }
/**\fn ChannelDisplay.ChannelDisplay.prototype._init_osc
*
* Initialize the OSC subsystem
*
* @param None
*
* @returns None
*/
ChannelDisplay.ChannelDisplay.prototype._init_osc = function(){ }