xref: /haiku/src/kits/midi/MidiText.cpp (revision 81f5654c124bf46fba0fd251f208e2d88d81e1ce)
1 /*
2  * Copyright (c) 2002-2003 Matthijs Hollemans
3  * Copyright (c) 2002 Jerome Leveque
4  * Copyright (c) 2002 Paul Stadler
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #include <stdio.h>
26 
27 #include "debug.h"
28 #include "MidiText.h"
29 
30 //------------------------------------------------------------------------------
31 
32 BMidiText::BMidiText()
33 {
34 	startTime = 0;
35 }
36 
37 //------------------------------------------------------------------------------
38 
39 BMidiText::~BMidiText()
40 {
41 	// do nothing
42 }
43 
44 //------------------------------------------------------------------------------
45 
46 void BMidiText::NoteOff(
47 	uchar channel, uchar note, uchar velocity, uint32 time)
48 {
49 	WaitAndPrint(time);
50 	printf(
51 		"B_NOTE OFF; channel = %d, note = %d, velocity = %d\n",
52 		channel, note, velocity);
53 }
54 
55 //------------------------------------------------------------------------------
56 
57 void BMidiText::NoteOn(
58 	uchar channel, uchar note, uchar velocity, uint32 time)
59 {
60 	WaitAndPrint(time);
61 	printf(
62 		"B_NOTE ON; channel = %d, note = %d, velocity = %d\n",
63 		channel, note, velocity);
64 }
65 
66 //------------------------------------------------------------------------------
67 
68 void BMidiText::KeyPressure(
69 	uchar channel, uchar note, uchar pressure, uint32 time)
70 {
71 	WaitAndPrint(time);
72 	printf(
73 		"KEY PRESSURE; channel = %d, note = %d, pressure = %d\n",
74 		channel, note, pressure);
75 }
76 
77 //------------------------------------------------------------------------------
78 
79 void BMidiText::ControlChange(
80 	uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
81 {
82 	WaitAndPrint(time);
83 	printf(
84 		"CONTROL CHANGE; channel = %d, control = %d, value = %d\n",
85 		channel, controlNumber, controlValue);
86 }
87 
88 //------------------------------------------------------------------------------
89 
90 void BMidiText::ProgramChange(
91 	uchar channel, uchar programNumber, uint32 time)
92 {
93 	WaitAndPrint(time);
94 	printf(
95 		"PROGRAM CHANGE; channel = %d, program = %d\n",
96 		channel, programNumber);
97 }
98 
99 //------------------------------------------------------------------------------
100 
101 void BMidiText::ChannelPressure(uchar channel, uchar pressure, uint32 time)
102 {
103 	WaitAndPrint(time);
104 	printf(
105 		"CHANNEL PRESSURE; channel = %d, pressure = %d\n",
106 		channel, pressure);
107 }
108 
109 //------------------------------------------------------------------------------
110 
111 void BMidiText::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
112 {
113 	WaitAndPrint(time);
114 	printf(
115 		"PITCH BEND; channel = %d, lsb = %d, msb = %d\n",
116 		channel, lsb, msb);
117 }
118 
119 //------------------------------------------------------------------------------
120 
121 void BMidiText::SystemExclusive(void* data, size_t length, uint32 time)
122 {
123 	WaitAndPrint(time);
124 
125 	printf("SYSTEM EXCLUSIVE;\n");
126 	for (size_t t = 0; t < length; ++t)
127 	{
128 		printf("%02X ", ((uint8*) data)[t]);
129 	}
130 	printf("\n");
131 }
132 
133 //------------------------------------------------------------------------------
134 
135 void BMidiText::SystemCommon(
136 	uchar status, uchar data1, uchar data2, uint32 time)
137 {
138 	WaitAndPrint(time);
139 	printf(
140 		"SYSTEM COMMON; status = %d, data1 = %d, data2 = %d\n",
141 		status, data1, data2);
142 }
143 
144 //------------------------------------------------------------------------------
145 
146 void BMidiText::SystemRealTime(uchar status, uint32 time)
147 {
148 	WaitAndPrint(time);
149 	printf("SYSTEM REAL TIME; status = %d\n", status);
150 }
151 
152 //------------------------------------------------------------------------------
153 
154 void BMidiText::ResetTimer(bool start)
155 {
156 	startTime = start ? B_NOW : 0;
157 }
158 
159 //------------------------------------------------------------------------------
160 
161 void BMidiText::_ReservedMidiText1() { }
162 void BMidiText::_ReservedMidiText2() { }
163 void BMidiText::_ReservedMidiText3() { }
164 
165 //------------------------------------------------------------------------------
166 
167 void BMidiText::Run()
168 {
169 	while (KeepRunning())
170 	{
171 		snooze(50000);
172 	}
173 }
174 
175 //------------------------------------------------------------------------------
176 
177 void BMidiText::WaitAndPrint(uint32 time)
178 {
179 	if (startTime == 0) { startTime = time;	}
180 
181 	SnoozeUntil(time);
182 
183 	printf("%lu: ", time - startTime);
184 }
185 
186 //------------------------------------------------------------------------------
187