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 21 BMidiText::BMidiText() 22 { 23 fStartTime = 0; 24 } 25 26 27 BMidiText::~BMidiText() 28 { 29 // do nothing 30 } 31 32 33 void 34 BMidiText::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 44 void 45 BMidiText::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 55 void 56 BMidiText::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 66 void 67 BMidiText::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 77 void 78 BMidiText::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 88 void 89 BMidiText::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 98 void 99 BMidiText::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 108 void 109 BMidiText::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 120 void 121 BMidiText::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 131 void 132 BMidiText::SystemRealTime(uchar status, uint32 time) 133 { 134 _WaitAndPrint(time); 135 printf("SYSTEM REAL TIME; status = %d\n", status); 136 } 137 138 139 void 140 BMidiText::ResetTimer(bool start) 141 { 142 fStartTime = start ? B_NOW : 0; 143 } 144 145 146 void BMidiText::_ReservedMidiText1() { } 147 void BMidiText::_ReservedMidiText2() { } 148 void BMidiText::_ReservedMidiText3() { } 149 150 151 void 152 BMidiText::Run() 153 { 154 while (KeepRunning()) 155 snooze(50000); 156 } 157 158 159 void 160 BMidiText::_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