149fa1748Smahlzeit/*
277f87987SJérôme Duval * Copyright 2006, Haiku.
377f87987SJérôme Duval *
477f87987SJérôme Duval * Copyright (c) 2002-2003 Matthijs Hollemans
577f87987SJérôme Duval * Copyright (c) 2002 Jerome Leveque
677f87987SJérôme Duval * Copyright (c) 2002 Paul Stadler
74810cdcdSJérôme Duval * Distributed under the terms of the MIT License.
86ba60405Smahlzeit *
94810cdcdSJérôme Duval * Authors:
104810cdcdSJérôme Duval *		J��r��me Leveque
114810cdcdSJérôme Duval *		Matthijs Hollemans
124810cdcdSJérôme Duval * 		Paul Stadler
136ba60405Smahlzeit */
146ba60405Smahlzeit
1549fa1748Smahlzeit#include <stdio.h>
164810cdcdSJérôme Duval#include <MidiText.h>
176ba60405Smahlzeit
186ba60405Smahlzeit#include "debug.h"
196ba60405Smahlzeit
2052a38012Sejakowatz
216ba60405SmahlzeitBMidiText::BMidiText()
226ba60405Smahlzeit{
234810cdcdSJérôme Duval	fStartTime = 0;
2452a38012Sejakowatz}
2552a38012Sejakowatz
266ba60405Smahlzeit
276ba60405SmahlzeitBMidiText::~BMidiText()
286ba60405Smahlzeit{
2949fa1748Smahlzeit	// do nothing
3052a38012Sejakowatz}
3152a38012Sejakowatz
326ba60405Smahlzeit
334810cdcdSJérôme Duvalvoid
344810cdcdSJérôme DuvalBMidiText::NoteOff(
356ba60405Smahlzeit	uchar channel, uchar note, uchar velocity, uint32 time)
366ba60405Smahlzeit{
374810cdcdSJérôme Duval	_WaitAndPrint(time);
3849fa1748Smahlzeit	printf(
3949fa1748Smahlzeit		"B_NOTE OFF; channel = %d, note = %d, velocity = %d\n",
4049fa1748Smahlzeit		channel, note, velocity);
4152a38012Sejakowatz}
4252a38012Sejakowatz
436ba60405Smahlzeit
444810cdcdSJérôme Duvalvoid
454810cdcdSJérôme DuvalBMidiText::NoteOn(
466ba60405Smahlzeit	uchar channel, uchar note, uchar velocity, uint32 time)
476ba60405Smahlzeit{
484810cdcdSJérôme Duval	_WaitAndPrint(time);
4949fa1748Smahlzeit	printf(
5049fa1748Smahlzeit		"B_NOTE ON; channel = %d, note = %d, velocity = %d\n",
5149fa1748Smahlzeit		channel, note, velocity);
5252a38012Sejakowatz}
5352a38012Sejakowatz
546ba60405Smahlzeit
554810cdcdSJérôme Duvalvoid
564810cdcdSJérôme DuvalBMidiText::KeyPressure(
576ba60405Smahlzeit	uchar channel, uchar note, uchar pressure, uint32 time)
586ba60405Smahlzeit{
594810cdcdSJérôme Duval	_WaitAndPrint(time);
6049fa1748Smahlzeit	printf(
6149fa1748Smahlzeit		"KEY PRESSURE; channel = %d, note = %d, pressure = %d\n",
6249fa1748Smahlzeit		channel, note, pressure);
6352a38012Sejakowatz}
6452a38012Sejakowatz
656ba60405Smahlzeit
664810cdcdSJérôme Duvalvoid
674810cdcdSJérôme DuvalBMidiText::ControlChange(
686ba60405Smahlzeit	uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
696ba60405Smahlzeit{
704810cdcdSJérôme Duval	_WaitAndPrint(time);
7149fa1748Smahlzeit	printf(
7249fa1748Smahlzeit		"CONTROL CHANGE; channel = %d, control = %d, value = %d\n",
7349fa1748Smahlzeit		channel, controlNumber, controlValue);
7452a38012Sejakowatz}
7552a38012Sejakowatz
766ba60405Smahlzeit
774810cdcdSJérôme Duvalvoid
784810cdcdSJérôme DuvalBMidiText::ProgramChange(
796ba60405Smahlzeit	uchar channel, uchar programNumber, uint32 time)
806ba60405Smahlzeit{
814810cdcdSJérôme Duval	_WaitAndPrint(time);
8249fa1748Smahlzeit	printf(
8349fa1748Smahlzeit		"PROGRAM CHANGE; channel = %d, program = %d\n",
8449fa1748Smahlzeit		channel, programNumber);
8552a38012Sejakowatz}
8652a38012Sejakowatz
876ba60405Smahlzeit
884810cdcdSJérôme Duvalvoid
894810cdcdSJérôme DuvalBMidiText::ChannelPressure(uchar channel, uchar pressure, uint32 time)
906ba60405Smahlzeit{
914810cdcdSJérôme Duval	_WaitAndPrint(time);
9249fa1748Smahlzeit	printf(
9349fa1748Smahlzeit		"CHANNEL PRESSURE; channel = %d, pressure = %d\n",
9449fa1748Smahlzeit		channel, pressure);
9552a38012Sejakowatz}
9652a38012Sejakowatz
976ba60405Smahlzeit
984810cdcdSJérôme Duvalvoid
994810cdcdSJérôme DuvalBMidiText::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
1006ba60405Smahlzeit{
1014810cdcdSJérôme Duval	_WaitAndPrint(time);
10249fa1748Smahlzeit	printf(
10349fa1748Smahlzeit		"PITCH BEND; channel = %d, lsb = %d, msb = %d\n",
10449fa1748Smahlzeit		channel, lsb, msb);
10552a38012Sejakowatz}
10652a38012Sejakowatz
1076ba60405Smahlzeit
1084810cdcdSJérôme Duvalvoid
1094810cdcdSJérôme DuvalBMidiText::SystemExclusive(void* data, size_t length, uint32 time)
1106ba60405Smahlzeit{
1114810cdcdSJérôme Duval	_WaitAndPrint(time);
1126ba60405Smahlzeit
11349fa1748Smahlzeit	printf("SYSTEM EXCLUSIVE;\n");
11449fa1748Smahlzeit	for (size_t t = 0; t < length; ++t)
11549fa1748Smahlzeit		printf("%02X ", ((uint8*) data)[t]);
11649fa1748Smahlzeit	printf("\n");
11752a38012Sejakowatz}
11852a38012Sejakowatz
1196ba60405Smahlzeit
1204810cdcdSJérôme Duvalvoid
1214810cdcdSJérôme DuvalBMidiText::SystemCommon(
1226ba60405Smahlzeit	uchar status, uchar data1, uchar data2, uint32 time)
1236ba60405Smahlzeit{
1244810cdcdSJérôme Duval	_WaitAndPrint(time);
12549fa1748Smahlzeit	printf(
12649fa1748Smahlzeit		"SYSTEM COMMON; status = %d, data1 = %d, data2 = %d\n",
12749fa1748Smahlzeit		status, data1, data2);
12852a38012Sejakowatz}
12952a38012Sejakowatz
1306ba60405Smahlzeit
1314810cdcdSJérôme Duvalvoid
1324810cdcdSJérôme DuvalBMidiText::SystemRealTime(uchar status, uint32 time)
1336ba60405Smahlzeit{
1344810cdcdSJérôme Duval	_WaitAndPrint(time);
13549fa1748Smahlzeit	printf("SYSTEM REAL TIME; status = %d\n", status);
13652a38012Sejakowatz}
13752a38012Sejakowatz
1386ba60405Smahlzeit
1394810cdcdSJérôme Duvalvoid
1404810cdcdSJérôme DuvalBMidiText::ResetTimer(bool start)
1416ba60405Smahlzeit{
1424810cdcdSJérôme Duval	fStartTime = start ? B_NOW : 0;
14352a38012Sejakowatz}
14452a38012Sejakowatz
1456ba60405Smahlzeit
1466ba60405Smahlzeitvoid BMidiText::_ReservedMidiText1() { }
14749fa1748Smahlzeitvoid BMidiText::_ReservedMidiText2() { }
14849fa1748Smahlzeitvoid BMidiText::_ReservedMidiText3() { }
1496ba60405Smahlzeit
1506ba60405Smahlzeit
1514810cdcdSJérôme Duvalvoid
1524810cdcdSJérôme DuvalBMidiText::Run()
1536ba60405Smahlzeit{
1546ba60405Smahlzeit	while (KeepRunning())
1556ba60405Smahlzeit		snooze(50000);
15652a38012Sejakowatz}
15752a38012Sejakowatz
1586ba60405Smahlzeit
1594810cdcdSJérôme Duvalvoid
1604810cdcdSJérôme DuvalBMidiText::_WaitAndPrint(uint32 time)
1616ba60405Smahlzeit{
1624810cdcdSJérôme Duval	if (fStartTime == 0)
1634810cdcdSJérôme Duval		fStartTime = time;
1646ba60405Smahlzeit
1656ba60405Smahlzeit	SnoozeUntil(time);
1666ba60405Smahlzeit
16701c5671dSJérôme Duval	printf("%" B_PRIu32 ": ", time - fStartTime);
16852a38012Sejakowatz}
1696ba60405Smahlzeit
170