xref: /haiku/src/kits/midi/MidiText.cpp (revision 7120e97489acbf17d86d3f33e3b2e68974fd4b23)
1 /**
2  * @file MidiText.cpp
3  *
4  * @author Matthijs Hollemans
5  * @author Jerome Leveque
6  * @author Paul Stadler
7  */
8 
9 #include <iostream>
10 
11 #include "debug.h"
12 #include "MidiEvent.h"
13 #include "MidiText.h"
14 
15 //------------------------------------------------------------------------------
16 
17 BMidiText::BMidiText()
18 {
19 	startTime = 0;
20 }
21 
22 //------------------------------------------------------------------------------
23 
24 BMidiText::~BMidiText()
25 {
26 	// Do nothing
27 }
28 
29 //------------------------------------------------------------------------------
30 
31 void BMidiText::NoteOff(
32 	uchar channel, uchar note, uchar velocity, uint32 time)
33 {
34 	WaitAndPrint(time);
35 	cout << ": NOTE OFF; channel = " << (int) channel
36 		 << ", note = " << (int) note
37 		 << ", velocity = " << (int) velocity << endl;
38 }
39 
40 //------------------------------------------------------------------------------
41 
42 void BMidiText::NoteOn(
43 	uchar channel, uchar note, uchar velocity, uint32 time)
44 {
45 	WaitAndPrint(time);
46 	cout << ": NOTE ON; channel = " << (int) channel
47 		 << ", note = " << (int) note
48 		 << ", velocity = " << (int) velocity << endl;
49 }
50 
51 //------------------------------------------------------------------------------
52 
53 void BMidiText::KeyPressure(
54 	uchar channel, uchar note, uchar pressure, uint32 time)
55 {
56 	WaitAndPrint(time);
57 	cout << ": KEY PRESSURE; channel = " << (int) channel
58 		 << ", note = " << (int) note
59 		 << ", pressure = " << (int) pressure << endl;
60 }
61 
62 //------------------------------------------------------------------------------
63 
64 void BMidiText::ControlChange(
65 	uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
66 {
67 	WaitAndPrint(time);
68 	cout << ": CONTROL CHANGE; channel = " << (int) channel
69 		 << ", control = " << (int) controlNumber
70 		 << ", value = "<< (int) controlValue << endl;
71 }
72 
73 //------------------------------------------------------------------------------
74 
75 void BMidiText::ProgramChange(
76 	uchar channel, uchar programNumber, uint32 time)
77 {
78 	WaitAndPrint(time);
79 	cout << ": PROGRAM CHANGE; channel = " << (int) channel
80 		 << ", program = " << (int) programNumber << endl;
81 }
82 
83 //------------------------------------------------------------------------------
84 
85 void BMidiText::ChannelPressure(uchar channel, uchar pressure, uint32 time)
86 {
87 	WaitAndPrint(time);
88 	cout << ": CHANNEL PRESSURE; channel = " << (int) channel
89 		 << ", pressure = " << (int) pressure << endl;
90 }
91 
92 //------------------------------------------------------------------------------
93 
94 void BMidiText::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
95 {
96 	WaitAndPrint(time);
97 	cout << ": PITCH BEND; channel = " << (int) channel << hex
98 		 << ", lsb = " << (int) lsb
99 		 << ", msb = " << (int) msb << endl;
100 }
101 
102 //------------------------------------------------------------------------------
103 
104 void BMidiText::SystemExclusive(void* data, size_t dataLength, uint32 time)
105 {
106 	WaitAndPrint(time);
107 
108 	cout << ": SYSTEM EXCLUSIVE;";
109 	for (size_t i = 0; i < dataLength; i++)
110 	{
111 		cout << " " << hex << (int) ((uint8*) data)[i];
112 	}
113 	cout << endl;
114 }
115 
116 //------------------------------------------------------------------------------
117 
118 void BMidiText::SystemCommon(
119 	uchar status, uchar data1, uchar data2, uint32 time)
120 {
121 	WaitAndPrint(time);
122 	cout << ": SYSTEM COMMON; status = " << hex << (int) status
123 		 << ", data1 = " << (int) data1
124 		 << ", data2 = " << (int) data2 << endl;
125 }
126 
127 //------------------------------------------------------------------------------
128 
129 void BMidiText::SystemRealTime(uchar status, uint32 time)
130 {
131 	WaitAndPrint(time);
132 	cout << ": SYSTEM REAL TIME; status = " << hex << (int) status << endl;
133 }
134 
135 //------------------------------------------------------------------------------
136 
137 void BMidiText::TempoChange(int32 beatsPerMinute, uint32 time)
138 {
139 	WaitAndPrint(time);
140 	cout << ": TEMPO CHANGE; beatsperminute = " << beatsPerMinute << endl;
141 }
142 
143 //------------------------------------------------------------------------------
144 
145 void BMidiText::AllNotesOff(bool justChannel, uint32 time)
146 {
147 	WaitAndPrint(time);
148 	cout << ": ALL NOTES OFF;" << endl;
149 }
150 
151 //------------------------------------------------------------------------------
152 
153 void BMidiText::ResetTimer(bool start)
154 {
155 	startTime = start ? B_NOW : 0;
156 }
157 
158 //------------------------------------------------------------------------------
159 
160 void BMidiText::_ReservedMidiText1() { }
161 
162 //------------------------------------------------------------------------------
163 
164 void BMidiText::Run()
165 {
166 	while (KeepRunning())
167 	{
168 		snooze(50000);
169 	}
170 }
171 
172 //------------------------------------------------------------------------------
173 
174 void BMidiText::WaitAndPrint(uint32 time)
175 {
176 	if (startTime == 0) { startTime = time;	}
177 
178 	SnoozeUntil(time);
179 
180 	cout << dec << (time - startTime);
181 }
182 
183 //------------------------------------------------------------------------------
184 
185