1 : <?php
2 :
3 : /**
4 : * \Midi\Event\PitchBendEvent
5 : *
6 : * @package Midi
7 : * @subpackage Event
8 : * @copyright © 2009 Tommy Montgomery <http://phpmidiparser.com/>
9 : * @since 1.0
10 : */
11 :
12 : namespace Midi\Event;
13 :
14 : /**
15 : * Represents the pitch bend channel event
16 : *
17 : * @package Midi
18 : * @subpackage Event
19 : * @since 1.0
20 : */
21 1 : class PitchBendEvent extends ChannelEvent {
22 :
23 : /**
24 : * @since 1.0
25 : * @uses pitchBendToCents()
26 : *
27 : * @return string
28 : */
29 : public function getParamDescription() {
30 1 : $cents = self::pitchBendToCents($this->param1, $this->param2);
31 1 : if ($cents > 0) {
32 1 : $cents = '+' . $cents;
33 1 : }
34 :
35 1 : return $cents . ' cents';
36 : }
37 :
38 : /**
39 : * Converts the internal MIDI pitch bend value to
40 : * cents (100ths of a whole tone)
41 : *
42 : * @since 1.0
43 : *
44 : * @param int $param1 16-bit integer
45 : * @param int $param2 16-bit integer
46 : * @return int Return value is between -100 (one whole tone down) and 100 (one whole tone up)
47 : */
48 : public static function pitchBendToCents($param1, $param2) {
49 1 : $param1 &= 0x0FFF;
50 1 : $param2 = ($param2 & 0x0FFF) << 2;
51 1 : $total = $param2 | $param1;
52 :
53 1 : $total -= 8192;
54 1 : $cents = round($total / 81.92);
55 1 : return $cents;
56 : }
57 :
58 : /**
59 : * @since 1.0
60 : * @uses EventType::PITCH_BEND
61 : *
62 : * @return int
63 : */
64 : public function getType() {
65 1 : return EventType::PITCH_BEND;
66 : }
67 :
68 : }
69 :
|