1/*
2 * Copyright 2006, Haiku.
3 *
4 * Copyright (c) 2002-2003 Matthijs Hollemans
5 * Copyright (c) 2002 Jerome Leveque
6 * Copyright (c) 2002 Paul Stadler
7 * Distributed under the terms of the MIT License.
8 *
9 * Authors:
10 *		Jérôme Leveque
11 *		Matthijs Hollemans
12 * 		Paul Stadler
13 */
14
15#include <stdio.h>
16#include <MidiText.h>
17
18#include "debug.h"
19
20
21BMidiText::BMidiText()
22{
23	fStartTime = 0;
24}
25
26
27BMidiText::~BMidiText()
28{
29	// do nothing
30}
31
32
33void
34BMidiText::NoteOff(
35	uchar channel, uchar note, uchar velocity, uint32 time)
36{
37	_WaitAndPrint(time);
38	printf(
39		"B_NOTE OFF; channel = %d, note = %d, velocity = %d\n",
40		channel, note, velocity);
41}
42
43
44void
45BMidiText::NoteOn(
46	uchar channel, uchar note, uchar velocity, uint32 time)
47{
48	_WaitAndPrint(time);
49	printf(
50		"B_NOTE ON; channel = %d, note = %d, velocity = %d\n",
51		channel, note, velocity);
52}
53
54
55void
56BMidiText::KeyPressure(
57	uchar channel, uchar note, uchar pressure, uint32 time)
58{
59	_WaitAndPrint(time);
60	printf(
61		"KEY PRESSURE; channel = %d, note = %d, pressure = %d\n",
62		channel, note, pressure);
63}
64
65
66void
67BMidiText::ControlChange(
68	uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
69{
70	_WaitAndPrint(time);
71	printf(
72		"CONTROL CHANGE; channel = %d, control = %d, value = %d\n",
73		channel, controlNumber, controlValue);
74}
75
76
77void
78BMidiText::ProgramChange(
79	uchar channel, uchar programNumber, uint32 time)
80{
81	_WaitAndPrint(time);
82	printf(
83		"PROGRAM CHANGE; channel = %d, program = %d\n",
84		channel, programNumber);
85}
86
87
88void
89BMidiText::ChannelPressure(uchar channel, uchar pressure, uint32 time)
90{
91	_WaitAndPrint(time);
92	printf(
93		"CHANNEL PRESSURE; channel = %d, pressure = %d\n",
94		channel, pressure);
95}
96
97
98void
99BMidiText::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
100{
101	_WaitAndPrint(time);
102	printf(
103		"PITCH BEND; channel = %d, lsb = %d, msb = %d\n",
104		channel, lsb, msb);
105}
106
107
108void
109BMidiText::SystemExclusive(void* data, size_t length, uint32 time)
110{
111	_WaitAndPrint(time);
112
113	printf("SYSTEM EXCLUSIVE;\n");
114	for (size_t t = 0; t < length; ++t)
115		printf("%02X ", ((uint8*) data)[t]);
116	printf("\n");
117}
118
119
120void
121BMidiText::SystemCommon(
122	uchar status, uchar data1, uchar data2, uint32 time)
123{
124	_WaitAndPrint(time);
125	printf(
126		"SYSTEM COMMON; status = %d, data1 = %d, data2 = %d\n",
127		status, data1, data2);
128}
129
130
131void
132BMidiText::SystemRealTime(uchar status, uint32 time)
133{
134	_WaitAndPrint(time);
135	printf("SYSTEM REAL TIME; status = %d\n", status);
136}
137
138
139void
140BMidiText::ResetTimer(bool start)
141{
142	fStartTime = start ? B_NOW : 0;
143}
144
145
146void BMidiText::_ReservedMidiText1() { }
147void BMidiText::_ReservedMidiText2() { }
148void BMidiText::_ReservedMidiText3() { }
149
150
151void
152BMidiText::Run()
153{
154	while (KeepRunning())
155		snooze(50000);
156}
157
158
159void
160BMidiText::_WaitAndPrint(uint32 time)
161{
162	if (fStartTime == 0)
163		fStartTime = time;
164
165	SnoozeUntil(time);
166
167	printf("%" B_PRIu32 ": ", time - fStartTime);
168}
169
170