1 : <?php
2 :
3 : /**
4 : * \Midi\Event\TimeSignatureEvent
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 set time signature meta event
16 : *
17 : * This event should be in the first track. There may be
18 : * multiple time signature events (if the time signature
19 : * changes in the middle of the song, for example).
20 : *
21 : * @package Midi
22 : * @subpackage Event
23 : * @since 1.0
24 : */
25 1 : class TimeSignatureEvent extends MetaEvent {
26 :
27 : /**
28 : * @since 1.0
29 : *
30 : * @param int $numerator
31 : * @param int $denominator
32 : * @param int $metronomePulse The number of clock ticks per metronome pulse
33 : * @param int $thirtySecondNotesPerQuarterNote
34 : */
35 : public function __construct($numerator, $denominator, $metronomePulse = 24, $thirtySecondNotesPerQuarterNote = 8) {
36 3 : parent::__construct(array($numerator, log($denominator, 2), $metronomePulse, $thirtySecondNotesPerQuarterNote));
37 3 : }
38 :
39 : /**
40 : * @since 1.0
41 : * @uses getTimeSignature()
42 : *
43 : * @return string
44 : */
45 : public function getParamDescription() {
46 : return
47 1 : self::getTimeSignature($this->data[0], $this->data[1]) .
48 1 : ', metronome pulses every ' . $this->data[2] . ' clock ticks, ' .
49 1 : $this->data[3] . ' 32nd notes per quarter note';
50 : }
51 :
52 : /**
53 : * Gets a user-friendly time signature
54 : *
55 : * @since 1.0
56 : * @todo Move to Util
57 : *
58 : * @param int $numerator
59 : * @param int $logarithmicDenominator The base 2 logarithm of the actual denominator
60 : * (e.g. 1 instead of 2, 2 instead of 4, 4 instead of 16, etc.)
61 : * @return string
62 : */
63 : public static function getTimeSignature($numerator, $logarithmicDenominator) {
64 1 : return $numerator . '/' . pow($logarithmicDenominator, 2);
65 : }
66 :
67 : /**
68 : * @since 1.0
69 : * @uses MetaEventType::TIME_SIGNATURE
70 : *
71 : * @return int
72 : */
73 : public function getSubtype() {
74 1 : return MetaEventType::TIME_SIGNATURE;
75 : }
76 :
77 : }
78 :
|