changed the type of onset and offset times to long, and so on
@@ -41,6 +41,6 @@ | ||
41 | 41 | else |
42 | 42 | mkdir doc |
43 | 43 | fi |
44 | -#javadoc -d doc -protected -version -author -nodeprecated -encoding utf-8 src/**/*.java | |
44 | +javadoc -d doc -protected -version -author -nodeprecated -encoding utf-8 src/**/*.java | |
45 | 45 | |
46 | 46 | ( cd ../ ; if [ -e ${release}.zip ] ; then rm ${release}.zip ; fi ; zip -r ${release}.zip $release ) |
@@ -168,8 +168,8 @@ | ||
168 | 168 | scc.processNotes(new SCCHandlerAdapter() { |
169 | 169 | public void processNote(SCCXMLWrapper.Note note, |
170 | 170 | SCCXMLWrapper scc2) { |
171 | - int onset = note.onsetInMilliSec() * fs / 1000; | |
172 | - int offset = note.offsetInMilliSec() * fs / 1000; | |
171 | + int onset = (int)(note.onsetInMilliSec() * fs / 1000); | |
172 | + int offset = (int)(note.offsetInMilliSec() * fs / 1000); | |
173 | 173 | AudioDataCompatible w = readWaveform(note.part().prognum(), |
174 | 174 | note.notenum(), sty, var); |
175 | 175 | if (w == null && sty2 != null) |
@@ -362,4 +362,4 @@ | ||
362 | 362 | return S; |
363 | 363 | } |
364 | 364 | |
365 | -} | |
\ No newline at end of file | ||
365 | +} |
@@ -57,11 +57,11 @@ | ||
57 | 57 | |
58 | 58 | /** "from" and "thru" in milli sec. */ |
59 | 59 | public void setInputData(AudioDataCompatible audiodata, |
60 | - int from, int thru) { | |
60 | + long from, long thru) { | |
61 | 61 | long fs = audiodata.sampleRate(); |
62 | 62 | setInputData(excerpt(audiodata, |
63 | - (int)((long)from * fs / 1000), | |
64 | - (int)((long)thru * fs / 1000))); | |
63 | + (int)(from * fs / 1000), | |
64 | + (int)(thru * fs / 1000))); | |
65 | 65 | } |
66 | 66 | |
67 | 67 | public AudioDataCompatible getTargetWaveform() { |
@@ -36,7 +36,7 @@ | ||
36 | 36 | public void endPart(SCCXMLWrapper.Part part, SCCXMLWrapper w) { |
37 | 37 | outdata.endPart(); |
38 | 38 | } |
39 | - public void processHeaderElement(int timestamp, java.lang.String name, | |
39 | + public void processHeaderElement(long timestamp, java.lang.String name, | |
40 | 40 | java.lang.String content, SCCXMLWrapper w){ |
41 | 41 | outdata2.addHeaderElement(timestamp - t0 + t1, |
42 | 42 | name, content); |
@@ -61,7 +61,7 @@ | ||
61 | 61 | public void endPart(SCCXMLWrapper.Part part, SCCXMLWrapper w) { |
62 | 62 | outdata2.endPart(); |
63 | 63 | } |
64 | - public void processHeaderElement(int timestamp, String name, | |
64 | + public void processHeaderElement(long timestamp, String name, | |
65 | 65 | String content, SCCXMLWrapper w){} |
66 | 66 | public void processNote(SCCXMLWrapper.Note note, SCCXMLWrapper w) { |
67 | 67 | outdata2.addNoteElement(note.onset(), note.offset(), |
@@ -81,4 +81,4 @@ | ||
81 | 81 | System.exit(1); |
82 | 82 | } |
83 | 83 | } |
84 | -} | |
\ No newline at end of file | ||
84 | +} |
@@ -4,7 +4,7 @@ | ||
4 | 4 | |
5 | 5 | private double value; |
6 | 6 | |
7 | - public BaseDynamicsEvent(int timeStamp, double value, int ticksPerBeat){ | |
7 | + public BaseDynamicsEvent(long timeStamp, double value, int ticksPerBeat){ | |
8 | 8 | // public BaseDynamicsEvent(int timeStamp, int ticksPerBeat, double value){ |
9 | 9 | super(Type.CONTROL_CHANGE, timeStamp, timeStamp, ticksPerBeat); |
10 | 10 | this.value = value; |
@@ -6,7 +6,7 @@ | ||
6 | 6 | private String content; |
7 | 7 | private String name; |
8 | 8 | |
9 | - public MutableAnnotation(int onset, int offset, String type, String content, | |
9 | + public MutableAnnotation(long onset, long offset, String type, String content, | |
10 | 10 | int ticksPerBeat) { |
11 | 11 | super(Type.ANNOTATION, onset, offset, ticksPerBeat); |
12 | 12 | this.content = content; |
@@ -1,7 +1,7 @@ | ||
1 | 1 | package jp.crestmuse.cmx.elements; |
2 | 2 | |
3 | 3 | public class MutableControlChange extends MutableMusicEvent { |
4 | - public MutableControlChange(int timestamp, int ctrlnum, int value, | |
4 | + public MutableControlChange(long timestamp, int ctrlnum, int value, | |
5 | 5 | int ticksPerBeat) { |
6 | 6 | super(Type.CONTROL_CHANGE, timestamp, timestamp, ticksPerBeat); |
7 | 7 | value1 = ctrlnum; |
@@ -19,4 +19,4 @@ | ||
19 | 19 | public int value() { |
20 | 20 | return value2; |
21 | 21 | } |
22 | -} | |
\ No newline at end of file | ||
22 | +} |
@@ -4,9 +4,11 @@ | ||
4 | 4 | import javax.sound.midi.*; |
5 | 5 | |
6 | 6 | public abstract class MutableMusicEvent |
7 | - implements Comparable<MutableMusicEvent>, NoteCompatible { | |
7 | + implements Comparable<MutableMusicEvent>, SCC.Note { | |
8 | 8 | |
9 | - int onset, offset, value1, value2, value3; | |
9 | + long onset, offset; | |
10 | + int value1, value2, value3; | |
11 | + long onsetInMSec = -1, offsetInMSec = -1; | |
10 | 12 | int ticksPerBeat; |
11 | 13 | Type type; |
12 | 14 | enum Type {NOTE, CONTROL_CHANGE, PROGRAM_CHANGE, PITCH_BEND, ANNOTATION}; |
@@ -16,7 +18,7 @@ | ||
16 | 18 | Map<String,String> attr = new TreeMap<String,String>(); |
17 | 19 | |
18 | 20 | |
19 | - MutableMusicEvent(Type type, int onset, int offset, int ticksPerBeat) { | |
21 | + MutableMusicEvent(Type type, long onset, long offset, int ticksPerBeat) { | |
20 | 22 | this.type = type; |
21 | 23 | this.onset = onset; |
22 | 24 | this.offset = offset; |
@@ -24,19 +26,33 @@ | ||
24 | 26 | this.ticksPerBeat = ticksPerBeat; |
25 | 27 | } |
26 | 28 | |
27 | - public void setOnset(int onset) { | |
29 | + public void setOnset(long onset) { | |
30 | + if (midievt1 != null) { | |
31 | + if (this.onset == midievt1.getTick()) | |
32 | + midievt1.setTick(onset); | |
33 | + else | |
34 | + throw new IllegalStateException(); | |
35 | + } | |
28 | 36 | this.onset = onset; |
37 | + onsetInMSec = -1; | |
29 | 38 | } |
30 | 39 | |
31 | - public void setOffset(int offset) { | |
40 | + public void setOffset(long offset) { | |
41 | + if (midievt2 != null) { | |
42 | + if (this.offset == midievt2.getTick()) | |
43 | + midievt2.setTick(offset); | |
44 | + else | |
45 | + throw new IllegalStateException(); | |
46 | + } | |
32 | 47 | this.offset = offset; |
48 | + offsetInMSec = -1; | |
33 | 49 | } |
34 | 50 | |
35 | - public int onset() { | |
51 | + public long onset() { | |
36 | 52 | return onset; |
37 | 53 | } |
38 | 54 | |
39 | - public int onset(int ticksPerBeat) { | |
55 | + public long onset(int ticksPerBeat) { | |
40 | 56 | if (ticksPerBeat == this.ticksPerBeat) |
41 | 57 | return onset; |
42 | 58 | else |
@@ -43,30 +59,40 @@ | ||
43 | 59 | return onset * ticksPerBeat / this.ticksPerBeat; |
44 | 60 | } |
45 | 61 | |
46 | - /**@deprecated*/ | |
47 | - public int onsetInMSec() { | |
48 | - throw new UnsupportedOperationException(); | |
49 | - } | |
62 | + // /**@deprecated*/ | |
63 | + // public int onsetInMSec() { | |
64 | + // throw new UnsupportedOperationException(); | |
65 | + // } | |
50 | 66 | |
51 | 67 | |
52 | - public int onsetInMilliSec() { | |
53 | - throw new UnsupportedOperationException(); | |
68 | + public long onsetInMilliSec() { | |
69 | + if (onsetInMSec == -1) | |
70 | + throw new IllegalStateException(); | |
71 | + else | |
72 | + return onsetInMSec; | |
54 | 73 | } |
55 | 74 | |
56 | - public int offset() { | |
75 | + public long offset() { | |
57 | 76 | return offset; |
58 | 77 | } |
59 | 78 | |
60 | - public int offsetInMilliSec() { | |
61 | - throw new UnsupportedOperationException(); | |
79 | + public long offsetInMilliSec() { | |
80 | + if (offsetInMSec == -1) | |
81 | + throw new IllegalStateException(); | |
82 | + else | |
83 | + return offsetInMSec; | |
62 | 84 | } |
63 | 85 | |
64 | - /**@deprecated*/ | |
65 | - public int offsetInMSec() { | |
66 | - throw new UnsupportedOperationException(); | |
86 | + // /**@deprecated*/ | |
87 | + // public int offsetInMSec() { | |
88 | + // throw new UnsupportedOperationException(); | |
89 | + // } | |
90 | + | |
91 | + public long durationInMilliSec() { | |
92 | + return offsetInMilliSec() - onsetInMilliSec(); | |
67 | 93 | } |
68 | - | |
69 | - public int offset(int ticksPerBeat) { | |
94 | + | |
95 | + public long offset(int ticksPerBeat) { | |
70 | 96 | if (ticksPerBeat == this.ticksPerBeat) |
71 | 97 | return offset; |
72 | 98 | else |
@@ -73,7 +99,7 @@ | ||
73 | 99 | return offset * ticksPerBeat / this.ticksPerBeat; |
74 | 100 | } |
75 | 101 | |
76 | - public int duration(int ticksPerBeat) { | |
102 | + public long duration(int ticksPerBeat) { | |
77 | 103 | return offset(ticksPerBeat) - onset(ticksPerBeat); |
78 | 104 | } |
79 | 105 |
@@ -90,7 +116,7 @@ | ||
90 | 116 | } |
91 | 117 | |
92 | 118 | public int hashCode() { |
93 | - return onset + offset + value1 + value2 + value3; | |
119 | + return (int)(onset + offset + value1 + value2 + value3); | |
94 | 120 | } |
95 | 121 | |
96 | 122 | public int compareTo(MutableMusicEvent another) { |
@@ -102,8 +128,8 @@ | ||
102 | 128 | value3 - another.value3 : value2 - another.value2) |
103 | 129 | : value1 - another.value1) |
104 | 130 | : type.ordinal() - another.type.ordinal()) |
105 | - : offset - another.offset) | |
106 | - : onset - another.onset; | |
131 | + : (int)(offset - another.offset)) | |
132 | + : (int)(onset - another.onset); | |
107 | 133 | } |
108 | 134 | |
109 | 135 | public int velocity() { |
@@ -189,6 +215,17 @@ | ||
189 | 215 | public MidiEvent getMidiEvent2() { |
190 | 216 | return midievt2; |
191 | 217 | } |
192 | - | |
193 | 218 | |
219 | + /** Do not this method in your application. | |
220 | + This is an inner method even though it's public */ | |
221 | + public void setOnsetInMilliSec(long onset) { | |
222 | + onsetInMSec = onset; | |
223 | + } | |
224 | + | |
225 | + /** Do not this method in your application. | |
226 | + This is an inner method even though it's public */ | |
227 | + public void setOffsetInMilliSec(long offset) { | |
228 | + offsetInMSec = offset; | |
229 | + } | |
230 | + | |
194 | 231 | } |
@@ -1,16 +1,17 @@ | ||
1 | 1 | package jp.crestmuse.cmx.elements; |
2 | 2 | import java.util.*; |
3 | +import javax.sound.midi.*; | |
3 | 4 | |
4 | -public class MutableNote extends MutableMusicEvent | |
5 | - implements NoteCompatible { | |
5 | +public class MutableNote extends MutableMusicEvent { | |
6 | 6 | |
7 | + | |
7 | 8 | // private String word = null; |
8 | 9 | |
9 | - public MutableNote(int onset, int offset, int notenum, int velocity, | |
10 | + public MutableNote(long onset, long offset, int notenum, int velocity, | |
10 | 11 | int ticksPerBeat) { |
11 | 12 | this(onset, offset, notenum, velocity, velocity, ticksPerBeat); |
12 | 13 | } |
13 | - public MutableNote(int onset, int offset, int notenum, int velocity, | |
14 | + public MutableNote(long onset, long offset, int notenum, int velocity, | |
14 | 15 | int offVelocity, int ticksPerBeat) { |
15 | 16 | super(Type.NOTE, onset, offset, ticksPerBeat); |
16 | 17 | value1 = notenum; |
@@ -17,7 +18,7 @@ | ||
17 | 18 | value2 = velocity; |
18 | 19 | value3 = offVelocity; |
19 | 20 | } |
20 | - public MutableNote(int onset, int offset, int notenum, int velocity, | |
21 | + public MutableNote(long onset, long offset, int notenum, int velocity, | |
21 | 22 | int offVelocity, int ticksPerBeat, |
22 | 23 | Map<String,String> attr) { |
23 | 24 | this(onset, offset, notenum, velocity, offVelocity, ticksPerBeat); |
@@ -34,25 +35,60 @@ | ||
34 | 35 | setAttribute("word", word); |
35 | 36 | }*/ |
36 | 37 | |
38 | + | |
39 | + private void changeData(int value1, int value2, MidiEvent evt) { | |
40 | + try { | |
41 | + MidiMessage msg = evt.getMessage(); | |
42 | + if (msg instanceof ShortMessage) { | |
43 | + ShortMessage sm = (ShortMessage)msg; | |
44 | + sm.setMessage(sm.getStatus(), | |
45 | + value1 >= 0 ? value1 : sm.getData1(), | |
46 | + value2 >= 0 ? value2 : sm.getData2()); | |
47 | + } else { | |
48 | + throw new IllegalStateException(); | |
49 | + } | |
50 | + } catch (InvalidMidiDataException e) { | |
51 | + e.printStackTrace(); | |
52 | + throw new IllegalStateException(e.toString()); | |
53 | + } | |
54 | + } | |
37 | 55 | |
38 | 56 | public void setNoteNum(int notenum) { |
39 | 57 | value1 = notenum; |
58 | + if (midievt1 != null) { | |
59 | + changeData(notenum, -1, midievt1); | |
60 | + } | |
61 | + if (midievt2 != null) { | |
62 | + changeData(notenum, -1, midievt2); | |
63 | + } | |
40 | 64 | } |
65 | + | |
41 | 66 | public int notenum() { |
42 | 67 | return value1; |
43 | 68 | } |
69 | + | |
44 | 70 | public void setVelocity(int vel) { |
45 | 71 | value2 = vel; |
72 | + if (midievt1 != null) { | |
73 | + changeData(-1, vel, midievt1); | |
74 | + } | |
46 | 75 | } |
76 | + | |
47 | 77 | public int velocity() { |
48 | 78 | return value2; |
49 | 79 | } |
80 | + | |
50 | 81 | public void setOffVelocity(int offvel) { |
51 | 82 | value3 = offvel; |
83 | + if (midievt2 != null) { | |
84 | + changeData(-1, offvel, midievt2); | |
85 | + } | |
52 | 86 | } |
87 | + | |
53 | 88 | public int offVelocity() { |
54 | 89 | return value3; |
55 | 90 | } |
91 | + | |
56 | 92 | // /** @deprecated */ |
57 | 93 | // public String word() { |
58 | 94 | // return getAttribute("word"); |
@@ -61,6 +97,7 @@ | ||
61 | 97 | // public void setWord(String w) { |
62 | 98 | // setAttribute("word", w); |
63 | 99 | // } |
100 | + | |
64 | 101 | public String toString() { |
65 | 102 | return "[onset: " + onset() + ", offset: " + offset() + |
66 | 103 | ", notenum: " + notenum() + ", velocity: " + velocity() + |
@@ -1,7 +1,7 @@ | ||
1 | 1 | package jp.crestmuse.cmx.elements; |
2 | 2 | |
3 | 3 | public class MutablePitchBend extends MutableMusicEvent { |
4 | - public MutablePitchBend(int timestamp, int value, int ticksPerBeat) { | |
4 | + public MutablePitchBend(long timestamp, int value, int ticksPerBeat) { | |
5 | 5 | super(Type.PITCH_BEND, timestamp, timestamp, ticksPerBeat); |
6 | 6 | value1 = value; |
7 | 7 | } |
@@ -11,4 +11,4 @@ | ||
11 | 11 | public int value() { |
12 | 12 | return value1; |
13 | 13 | } |
14 | -} | |
\ No newline at end of file | ||
14 | +} |
@@ -1,7 +1,7 @@ | ||
1 | 1 | package jp.crestmuse.cmx.elements; |
2 | 2 | |
3 | 3 | public class MutableProgramChange extends MutableMusicEvent { |
4 | - public MutableProgramChange(int timestamp, int value, | |
4 | + public MutableProgramChange(long timestamp, int value, | |
5 | 5 | int ticksPerBeat) { |
6 | 6 | super(Type.PROGRAM_CHANGE, timestamp, timestamp, ticksPerBeat); |
7 | 7 | value1 = value; |
@@ -12,4 +12,4 @@ | ||
12 | 12 | public int value() { |
13 | 13 | return value1; |
14 | 14 | } |
15 | -} | |
\ No newline at end of file | ||
15 | +} |
@@ -1,6 +1,8 @@ | ||
1 | 1 | package jp.crestmuse.cmx.elements; |
2 | 2 | import jp.crestmuse.cmx.filewrappers.*; |
3 | 3 | |
4 | +/* | |
4 | 5 | @Deprecated |
5 | 6 | public interface NoteCompatible extends SCC.Note { |
6 | 7 | } |
8 | +*/ |
@@ -896,6 +896,10 @@ | ||
896 | 896 | setAttribute(name, String.valueOf(value)); |
897 | 897 | } |
898 | 898 | |
899 | + public final void setAttribute(String name, long value) { | |
900 | + setAttribute(name, String.valueOf(value)); | |
901 | + } | |
902 | + | |
899 | 903 | /********************************************************************** |
900 | 904 | *<p>Adds an attribute to the current node. |
901 | 905 | *The current node should be an element node.</p> |
@@ -1151,10 +1151,10 @@ | ||
1151 | 1151 | HeaderElement[] headers = scc.getHeaderElementList(); |
1152 | 1152 | for (int i = 0; i < headers.length; i++) { |
1153 | 1153 | if (headers[i].name().equals("TEMPO")) { |
1154 | - int from = headers[i].time() * divisionPerMeasure / 4 / ticksPerBeat; | |
1154 | + int from = (int)(headers[i].time() * divisionPerMeasure / 4 / ticksPerBeat); | |
1155 | 1155 | int to; |
1156 | 1156 | if (i < headers.length - 1) { |
1157 | - to = headers[i + 1].time() * divisionPerMeasure / 4 / ticksPerBeat; | |
1157 | + to = (int)(headers[i + 1].time() * divisionPerMeasure / 4 / ticksPerBeat); | |
1158 | 1158 | } else { |
1159 | 1159 | to = tempos.length - 1; |
1160 | 1160 | } |
@@ -97,10 +97,10 @@ | ||
97 | 97 | } |
98 | 98 | |
99 | 99 | public void addMIDIChannelMessages(MIDIEventList el) { |
100 | - int currentTime = 0; | |
100 | + long currentTime = 0; | |
101 | 101 | for (MIDIEventList.MIDIEvent e : el) { |
102 | 102 | addMIDIChannelMessage(e.msgname(), |
103 | - e.time() - currentTime, | |
103 | + (int)(e.time() - currentTime), | |
104 | 104 | e.channel(), |
105 | 105 | e.value1(), |
106 | 106 | e.value2()); |
@@ -592,7 +592,7 @@ | ||
592 | 592 | final SCCDataSet scc = new SCCDataSet(ticksPerBeat); |
593 | 593 | final SCCDataSet.Part[] parts = new SCCDataSet.Part[17]; // 要検討 |
594 | 594 | processMIDIEvent(new MIDIHandler() { |
595 | - private int totalTime; | |
595 | + private long totalTime; | |
596 | 596 | int partSerial = 0; |
597 | 597 | private MutableNote[] onNotes; |
598 | 598 | public void beginTrack(Track track, MIDIXMLWrapper w) { |
@@ -693,11 +693,14 @@ | ||
693 | 693 | // return dest; |
694 | 694 | } |
695 | 695 | |
696 | + /* | |
696 | 697 | @Deprecated |
697 | 698 | public void toSCCXML(final SCCXMLWrapper dest) throws TransformerException, IOException, ParserConfigurationException, SAXException{ |
698 | 699 | toSCCXML(dest, null); |
699 | 700 | } |
701 | + */ | |
700 | 702 | |
703 | + /* | |
701 | 704 | @Deprecated |
702 | 705 | public void toSCCXML(final SCCXMLWrapper dest, SCCXMLWrapper.EasyChord[] chords) |
703 | 706 | throws TransformerException, IOException, |
@@ -704,6 +707,7 @@ | ||
704 | 707 | ParserConfigurationException, SAXException { |
705 | 708 | toSCCXML(dest, chords, null); |
706 | 709 | } |
710 | + */ | |
707 | 711 | |
708 | 712 | private class Header { |
709 | 713 | int time; |
@@ -716,6 +720,7 @@ | ||
716 | 720 | } |
717 | 721 | } |
718 | 722 | |
723 | + /* | |
719 | 724 | @Deprecated |
720 | 725 | public void toSCCXML(final SCCXMLWrapper dest, |
721 | 726 | SCCXMLWrapper.EasyChord[] chords, String key) |
@@ -777,6 +782,11 @@ | ||
777 | 782 | new MutableControlChange(totalTime, midiEvent.value(0), |
778 | 783 | midiEvent.value(1), ticksPerBeat()); |
779 | 784 | addControlChange(c, midiEvent, channelToNotes); |
785 | + } else if (statusNo == PROGRAM_CHANGE) { // kari | |
786 | + System.err.println("program change"); | |
787 | + MutableProgramChange c = | |
788 | + new MutableProgramChange(totalTime, midiEvent.value(0), ticksPerBeat()); | |
789 | + addControlChange(c, midiEvent, channelToNotes); | |
780 | 790 | } else if (statusNo == PITCH_BEND_CHANGE) { |
781 | 791 | MutablePitchBend c = |
782 | 792 | new MutablePitchBend(totalTime, |
@@ -784,7 +794,7 @@ | ||
784 | 794 | // midiEvent.value(0)+128*midiEvent.value(1), |
785 | 795 | ticksPerBeat()); |
786 | 796 | addControlChange(c, midiEvent, channelToNotes); |
787 | - } | |
797 | + } | |
788 | 798 | } |
789 | 799 | private void addControlChange(MutableMusicEvent c, |
790 | 800 | MIDIEvent e, |
@@ -904,7 +914,8 @@ | ||
904 | 914 | |
905 | 915 | dest.finalizeDocument(); |
906 | 916 | } |
907 | - | |
917 | + */ | |
918 | + | |
908 | 919 | /* |
909 | 920 | private class MyControlChange extends MutableNote { |
910 | 921 | private MyControlChange(int time, int ctrlnum, int value) { |
@@ -165,6 +165,10 @@ | ||
165 | 165 | return Integer.parseInt(getAttribute(key)); |
166 | 166 | } |
167 | 167 | |
168 | + public long getAttributeLong(String key) { | |
169 | + return Long.parseLong(getAttribute(key)); | |
170 | + } | |
171 | + | |
168 | 172 | public double getAttributeDouble(String key) { |
169 | 173 | return Double.parseDouble(getAttribute(key)); |
170 | 174 | } |
@@ -316,6 +320,10 @@ | ||
316 | 320 | return Integer.parseInt(getAttribute(node, attrkey)); |
317 | 321 | } |
318 | 322 | |
323 | + protected static final long getAttributeLong(Node node, String attrkey) { | |
324 | + return Long.parseLong(getAttribute(node, attrkey)); | |
325 | + } | |
326 | + | |
319 | 327 | protected static final double getAttributeDouble(Node node, String attrkey) { |
320 | 328 | return Double.parseDouble(getAttribute(node, attrkey)); |
321 | 329 | } |
@@ -329,4 +337,4 @@ | ||
329 | 337 | // } |
330 | 338 | |
331 | 339 | |
332 | -} | |
\ No newline at end of file | ||
340 | +} |
@@ -30,7 +30,7 @@ | ||
30 | 30 | public interface HeaderElement extends Comparable<HeaderElement> { |
31 | 31 | String content(); |
32 | 32 | String name(); |
33 | - int time(); | |
33 | + long time(); | |
34 | 34 | } |
35 | 35 | |
36 | 36 | public interface Part { |
@@ -48,11 +48,12 @@ | ||
48 | 48 | } |
49 | 49 | |
50 | 50 | public interface Note { |
51 | - int onset(int ticksPerBeat); | |
52 | - int onsetInMilliSec(); | |
53 | - int offset(int ticksPerBeat); | |
54 | - int offsetInMilliSec(); | |
55 | - int duration(int ticksPerBeat); | |
51 | + long onset(int ticksPerBeat); | |
52 | + long onsetInMilliSec(); | |
53 | + long offset(int ticksPerBeat); | |
54 | + long offsetInMilliSec(); | |
55 | + long duration(int ticksPerBeat); | |
56 | + long durationInMilliSec(); | |
56 | 57 | int notenum(); |
57 | 58 | int velocity(); |
58 | 59 | int offVelocity(); |
@@ -67,8 +68,8 @@ | ||
67 | 68 | } |
68 | 69 | |
69 | 70 | public interface Annotation { |
70 | - int onset(int ticksPerBeat); | |
71 | - int offset(int ticksPerBeat); | |
71 | + long onset(int ticksPerBeat); | |
72 | + long offset(int ticksPerBeat); | |
72 | 73 | String type(); |
73 | 74 | String content(); |
74 | 75 | } |
@@ -16,8 +16,8 @@ | ||
16 | 16 | public class HeaderElement implements SCC.HeaderElement { |
17 | 17 | String content; |
18 | 18 | private String name; |
19 | - private int time; | |
20 | - private HeaderElement(int time, String name, String content) { | |
19 | + private long time; | |
20 | + private HeaderElement(long time, String name, String content) { | |
21 | 21 | this.time = time; |
22 | 22 | this.name = name; |
23 | 23 | this.content = content; |
@@ -28,7 +28,7 @@ | ||
28 | 28 | public String name() { |
29 | 29 | return name; |
30 | 30 | } |
31 | - public int time() { | |
31 | + public long time() { | |
32 | 32 | return time; |
33 | 33 | } |
34 | 34 | public boolean equals(SCC.HeaderElement e) { |
@@ -37,7 +37,7 @@ | ||
37 | 37 | } |
38 | 38 | public int compareTo(SCC.HeaderElement e) { |
39 | 39 | if (time != e.time()) |
40 | - return time - e.time(); | |
40 | + return (int)(time - e.time()); | |
41 | 41 | else if (!name.equals(e.name())) |
42 | 42 | return name.compareTo(e.name()); |
43 | 43 | else if (!content.equals(e.content())) |
@@ -52,7 +52,8 @@ | ||
52 | 52 | } |
53 | 53 | |
54 | 54 | public class Part implements SCC.Part { |
55 | - private List<MutableMusicEvent> notes; | |
55 | + // private List<MutableMusicEvent> notes; | |
56 | + private SortedSet<MutableMusicEvent> notes; | |
56 | 57 | //private List<MutableMusicEvent> notes = new ArrayList<MutableMusicEvent>(); |
57 | 58 | private Map<MutableMusicEvent,MyNumber> nOverlaps = |
58 | 59 | new HashMap<MutableMusicEvent,MyNumber>(); |
@@ -63,7 +64,9 @@ | ||
63 | 64 | |
64 | 65 | private Part(int serial, byte ch, int pn, int vol, String name, |
65 | 66 | int index) { |
66 | - notes = Collections.synchronizedList(new ArrayList<MutableMusicEvent>()); | |
67 | + // notes = Collections.synchronizedList(new ArrayList<MutableMusicEvent>()); | |
68 | + // notes = new ArrayList<MutableMusicEvent>(); | |
69 | + notes = new TreeSet<MutableMusicEvent>(); | |
67 | 70 | this.serial = serial; |
68 | 71 | channel = ch; |
69 | 72 | prognum = pn; |
@@ -79,7 +82,7 @@ | ||
79 | 82 | note.setAttribute("number", nOverlaps.get(note).value); |
80 | 83 | } |
81 | 84 | |
82 | - public void remove(MutableMusicEvent e) { | |
85 | + public synchronized void remove(MutableMusicEvent e) { | |
83 | 86 | boolean result = notes.remove(e); |
84 | 87 | if (tracks != null) { |
85 | 88 | if (e.getMidiEvent1() != null) { |
@@ -98,15 +101,16 @@ | ||
98 | 101 | remove(e); |
99 | 102 | } |
100 | 103 | |
101 | - void add(MutableMusicEvent e) { | |
104 | + synchronized void add(MutableMusicEvent e) { | |
102 | 105 | notes.add(e); |
103 | 106 | } |
104 | 107 | |
105 | 108 | |
106 | - MutableNote addNoteElement(int onset, int offset, int notenum, | |
107 | - int velocity, int offVelocity, | |
108 | - MusicXMLWrapper.MusicData md, | |
109 | - Map<String,String> attr) { | |
109 | + synchronized MutableNote | |
110 | + addNoteElement(long onset, long offset, int notenum, | |
111 | + int velocity, int offVelocity, | |
112 | + MusicXMLWrapper.MusicData md, | |
113 | + Map<String,String> attr) { | |
110 | 114 | MutableNote note = new MutableNote(onset, offset, notenum, velocity, |
111 | 115 | offVelocity, division, attr); |
112 | 116 | notes.add(note); |
@@ -125,7 +129,7 @@ | ||
125 | 129 | return note; |
126 | 130 | } |
127 | 131 | |
128 | - MutableNote addNoteElement(int onset, int offset, int notenum, | |
132 | + MutableNote addNoteElement(long onset, long offset, int notenum, | |
129 | 133 | int velocity, int offVelocity, |
130 | 134 | MusicXMLWrapper.MusicData md) { |
131 | 135 | return addNoteElement(onset, offset, notenum, velocity, offVelocity, |
@@ -133,13 +137,13 @@ | ||
133 | 137 | } |
134 | 138 | |
135 | 139 | |
136 | - public MutableNote addNoteElement(int onset, int offset, int notenum, | |
140 | + public MutableNote addNoteElement(long onset, long offset, int notenum, | |
137 | 141 | int velocity, int offVelocity) { |
138 | 142 | return addNoteElement(onset, offset, notenum, velocity, offVelocity, |
139 | 143 | null, null); |
140 | 144 | } |
141 | 145 | |
142 | - public MutableNote addNoteElement(int onset, int offset, int notenum, | |
146 | + public MutableNote addNoteElement(long onset, long offset, int notenum, | |
143 | 147 | int velocity, int offVelocity, |
144 | 148 | Map<String,String> attr) { |
145 | 149 | return addNoteElement(onset, offset, notenum, velocity, |
@@ -165,7 +169,7 @@ | ||
165 | 169 | } |
166 | 170 | */ |
167 | 171 | |
168 | - public MutableControlChange addControlChange(int time, int ctrl, int value) { | |
172 | + public synchronized MutableControlChange addControlChange(long time, int ctrl, int value) { | |
169 | 173 | MutableControlChange cc = new MutableControlChange(time, ctrl, value, division); |
170 | 174 | notes.add(cc); |
171 | 175 | checkOverlap(cc); |
@@ -177,7 +181,7 @@ | ||
177 | 181 | return cc; |
178 | 182 | } |
179 | 183 | |
180 | - public MutableProgramChange addProgramChange(int time, int value) { | |
184 | + public synchronized MutableProgramChange addProgramChange(long time, int value) { | |
181 | 185 | MutableProgramChange pc = new MutableProgramChange(time, value, division); |
182 | 186 | notes.add(pc); |
183 | 187 | checkOverlap(pc); |
@@ -189,7 +193,7 @@ | ||
189 | 193 | return pc; |
190 | 194 | } |
191 | 195 | |
192 | - public MutablePitchBend addPitchBend(int time, int value) { | |
196 | + public synchronized MutablePitchBend addPitchBend(long time, int value) { | |
193 | 197 | MutablePitchBend pb = new MutablePitchBend(time, value, division); |
194 | 198 | notes.add(pb); |
195 | 199 | checkOverlap(pb); |
@@ -198,7 +202,7 @@ | ||
198 | 202 | return pb; |
199 | 203 | } |
200 | 204 | |
201 | - BaseDynamicsEvent addBaseDynamics(int time, double value) { | |
205 | + synchronized BaseDynamicsEvent addBaseDynamics(long time, double value) { | |
202 | 206 | BaseDynamicsEvent e = new BaseDynamicsEvent(time, value, division); |
203 | 207 | notes.add(e); |
204 | 208 | return e; |
@@ -217,32 +221,35 @@ | ||
217 | 221 | } |
218 | 222 | */ |
219 | 223 | |
220 | - public MutableMusicEvent[] getNoteList() { | |
224 | + public synchronized MutableMusicEvent[] getNoteList() { | |
221 | 225 | return notes.toArray(new MutableMusicEvent[notes.size()]); |
222 | 226 | } |
223 | 227 | |
224 | - public MutableNote[] getNoteOnlyList() { | |
228 | + public synchronized MutableNote[] getNoteOnlyList() { | |
225 | 229 | List<MutableNote> l = new ArrayList<MutableNote>(); |
226 | 230 | for (MutableMusicEvent e : notes) { |
227 | 231 | if (e instanceof MutableNote) |
228 | 232 | l.add((MutableNote)e); |
229 | 233 | } |
230 | - return l.toArray(new MutableNote[l.size()]); | |
234 | + return l.toArray(new MutableNote[l.size()]); | |
231 | 235 | } |
232 | 236 | |
233 | 237 | public MutableMusicEvent[] getSortedNoteList() { |
234 | - MutableMusicEvent[] l = (MutableMusicEvent[])(getNoteList().clone()); | |
235 | - Arrays.sort(l); | |
236 | - return l; | |
238 | + return getNoteList(); | |
239 | + // MutableMusicEvent[] l = (MutableMusicEvent[])(getNoteList().clone()); | |
240 | + // Arrays.sort(l); | |
241 | + // return l; | |
237 | 242 | } |
238 | 243 | |
239 | 244 | public MutableNote[] getSortedNoteOnlyList() { |
240 | - MutableNote[] l = (MutableNote[])(getNoteOnlyList().clone()); | |
241 | - Arrays.sort(l); | |
242 | - return l; | |
245 | + return getNoteOnlyList(); | |
246 | + // MutableNote[] l = (MutableNote[])(getNoteOnlyList().clone()); | |
247 | + // Arrays.sort(l); | |
248 | + // return l; | |
243 | 249 | } |
244 | 250 | |
245 | - public List<MutableMusicEvent> getNotesBetween1(int from, int thru) { | |
251 | + /* | |
252 | + public synchronized List<MutableMusicEvent> getNotesBetween1(int from, int thru) { | |
246 | 253 | List<MutableMusicEvent> notes2 = new ArrayList<MutableMusicEvent>(); |
247 | 254 | for (MutableMusicEvent e : notes) { |
248 | 255 | if (e.onset() >= from && e.offset() <= thru) |
@@ -251,7 +258,7 @@ | ||
251 | 258 | return notes2; |
252 | 259 | } |
253 | 260 | |
254 | - public List<MutableMusicEvent> getNotesBetween2(int from, int thru) { | |
261 | + public synchronized List<MutableMusicEvent> getNotesBetween2(int from, int thru) { | |
255 | 262 | List<MutableMusicEvent> notes2 = new ArrayList<MutableMusicEvent>(); |
256 | 263 | for (MutableMusicEvent e : notes) { |
257 | 264 | if (e.onset() >= from && e.onset() < thru) |
@@ -259,7 +266,63 @@ | ||
259 | 266 | } |
260 | 267 | return notes2; |
261 | 268 | } |
269 | + */ | |
262 | 270 | |
271 | + public void calcMilliSec() { | |
272 | + double currentSec = 0.0; | |
273 | + int currentTick = 0; | |
274 | + TempoSearch ts = new TempoSearch(getHeaderElementList()); | |
275 | + for (MutableMusicEvent e : notes) { | |
276 | + if (e.onset() >= ts.nextTempoChangeInTick) | |
277 | + ts.nextTempo(); | |
278 | + e.setOnsetInMilliSec((long)(ts.calcSec(e.onset()) * 1000)); | |
279 | + if (e.offset() >= ts.nextTempoChangeInTick) | |
280 | + ts.nextTempo(); | |
281 | + e.setOffsetInMilliSec((int)(ts.calcSec(e.offset()) * 1000)); | |
282 | + } | |
283 | + } | |
284 | + | |
285 | + private class TempoSearch { | |
286 | + HeaderElement[] headers; | |
287 | + int nextIndex = 0; | |
288 | + long nextTempoChangeInTick = 0; | |
289 | + double nextTempoChangeInSec = 0.0; | |
290 | + long lastTempoChangeInTick = 0; | |
291 | + double lastTempoChangeInSec = 0.0; | |
292 | + double nextTempo = 120; | |
293 | + double lastTempo = 120; | |
294 | + boolean finished = false; | |
295 | + TempoSearch(HeaderElement[] headers) { | |
296 | + this.headers = headers; | |
297 | + } | |
298 | + void nextTempo() { | |
299 | + if (!finished) { | |
300 | + do { | |
301 | + if (headers[nextIndex].name().equals("TEMPO")) { | |
302 | + lastTempoChangeInTick = nextTempoChangeInTick; | |
303 | + nextTempoChangeInTick = headers[nextIndex].time(); | |
304 | + lastTempoChangeInSec = nextTempoChangeInSec; | |
305 | + nextTempoChangeInSec = calcSec(nextTempoChangeInTick); | |
306 | + lastTempo = nextTempo; | |
307 | + nextTempo = Double.parseDouble(headers[nextIndex].content()); | |
308 | + return; | |
309 | + } | |
310 | + nextIndex++; | |
311 | + } while (nextIndex < headers.length); | |
312 | + finished = true; | |
313 | + lastTempoChangeInTick = nextTempoChangeInTick; | |
314 | + lastTempoChangeInSec = nextTempoChangeInSec; | |
315 | + lastTempo = nextTempo; | |
316 | + } | |
317 | + } | |
318 | + double calcSec(long tick) { | |
319 | + long dur_tick = tick - lastTempoChangeInTick; | |
320 | + double dur_sec = (60.0 * dur_tick) / (division * lastTempo); | |
321 | + return lastTempoChangeInSec + dur_sec; | |
322 | + } | |
323 | + } | |
324 | + | |
325 | + | |
263 | 326 | public int serial() { |
264 | 327 | return serial; |
265 | 328 | } |
@@ -268,7 +331,7 @@ | ||
268 | 331 | return channel; |
269 | 332 | } |
270 | 333 | |
271 | - public int prognum() { | |
334 | + public synchronized int prognum() { | |
272 | 335 | Note[] notes = getNoteList(); |
273 | 336 | for (int i = 0; i < notes.length; i++) { |
274 | 337 | if (notes[i] instanceof MutableProgramChange) { |
@@ -278,7 +341,7 @@ | ||
278 | 341 | return prognum; |
279 | 342 | } |
280 | 343 | |
281 | - private int getFirstControlChange(int ctrlnum, int defaultvalue) { | |
344 | + private synchronized int getFirstControlChange(int ctrlnum, int defaultvalue) { | |
282 | 345 | Note[] notes = getNoteList(); |
283 | 346 | for (int i = 0; i < notes.length; i++) { |
284 | 347 | if (notes[i] instanceof MutableControlChange) { |
@@ -328,6 +391,10 @@ | ||
328 | 391 | public int getFirstMeasure() { |
329 | 392 | return fromMeasure; |
330 | 393 | } |
394 | + public void setFirstMeasure(int measure) { | |
395 | + thruMeasure = measure + (thruMeasure - fromMeasure); | |
396 | + fromMeasure = measure; | |
397 | + } | |
331 | 398 | public boolean isSelectable() { |
332 | 399 | return false; |
333 | 400 | } |
@@ -342,10 +409,10 @@ | ||
342 | 409 | public void drawData(PianoRoll pianoroll) { |
343 | 410 | MutableNote[] notes = getNoteOnlyList(); |
344 | 411 | for (MutableNote note : notes) { |
345 | - int onset = note.onset(); | |
412 | + long onset = note.onset(); | |
346 | 413 | if (onset >= fromMeasure * getBeatNum() * division && |
347 | 414 | onset < thruMeasure * getBeatNum() * division) { |
348 | - int measure = onset / division / getBeatNum(); | |
415 | + int measure = (int)(onset / division / getBeatNum()); | |
349 | 416 | double beat = (double)onset / division - measure * getBeatNum(); |
350 | 417 | double duration = (double)(note.offset() - onset) / division; |
351 | 418 | pianoroll.drawNote(measure - fromMeasure, beat, duration, |
@@ -380,41 +447,41 @@ | ||
380 | 447 | this.division = division; |
381 | 448 | } |
382 | 449 | |
383 | - public void addAnnotation(String type, int onset, int offset, String content) { | |
450 | + public void addAnnotation(String type, long onset, long offset, String content) { | |
384 | 451 | annotations.add(new MutableAnnotation(onset, offset, type, content, |
385 | 452 | division)); |
386 | 453 | } |
387 | 454 | |
388 | - public void addBarline(int time, String details) { | |
455 | + public void addBarline(long time, String details) { | |
389 | 456 | addAnnotation("barline", time, time, details); |
390 | 457 | } |
391 | 458 | |
392 | - public void addChord(int onset, int offset, String content) { | |
459 | + public void addChord(long onset, long offset, String content) { | |
393 | 460 | addAnnotation("chord", onset, offset, content); |
394 | 461 | } |
395 | 462 | |
396 | 463 | // Added: 2014/11/18, Author: tama |
397 | - public void addLyric(int onset, int offset, String content) { | |
464 | + public void addLyric(long onset, long offset, String content) { | |
398 | 465 | addAnnotation("lyric", onset, offset, content); |
399 | 466 | } |
400 | 467 | |
401 | - public void addCuePoint(int onset, int offset, String content) { | |
468 | + public void addCuePoint(long onset, long offset, String content) { | |
402 | 469 | addAnnotation("cue", onset, offset, content); |
403 | 470 | } |
404 | 471 | |
405 | - public void addMarker(int onset, int offset, String content) { | |
472 | + public void addMarker(long onset, long offset, String content) { | |
406 | 473 | addAnnotation("marker", onset, offset, content); |
407 | 474 | } |
408 | 475 | |
409 | - public void addHeaderElement(int time, java.lang.String name, java.lang.String content) { | |
476 | + public void addHeaderElement(long time, java.lang.String name, java.lang.String content) { | |
410 | 477 | headers.add(new HeaderElement(time, name, content)); |
411 | 478 | } |
412 | 479 | |
413 | - public void addHeaderElement(int time, String name, int content) { | |
480 | + public void addHeaderElement(long time, String name, int content) { | |
414 | 481 | addHeaderElement(time, name, String.valueOf(content)); |
415 | 482 | } |
416 | 483 | |
417 | - public void addHeaderElement(int time, String name, double content) { | |
484 | + public void addHeaderElement(long time, String name, double content) { | |
418 | 485 | addHeaderElement(time, name, String.valueOf(content)); |
419 | 486 | } |
420 | 487 |
@@ -589,8 +656,8 @@ | ||
589 | 656 | for (Part p : partlist) { |
590 | 657 | newscc.newPart(p.serial(), p.channel(), p.prognum(), |
591 | 658 | p.volume(), p.name()); |
592 | - MutableMusicEvent[] notelist = p.getSortedNoteList(); // modified on 2012.11.19 | |
593 | - ////// SCC.Note[] notelist = p.getNoteList(); | |
659 | + //MutableMusicEvent[] notelist = p.getNoteOnlyList(); // modified on 2012.11.19 | |
660 | + MutableMusicEvent[] notelist = p.getNoteList(); | |
594 | 661 | for (MutableMusicEvent n : notelist) { |
595 | 662 | if (n instanceof MutableControlChange) { |
596 | 663 | MutableControlChange cc = (MutableControlChange)n; |
@@ -686,8 +753,8 @@ | ||
686 | 753 | } |
687 | 754 | } |
688 | 755 | |
689 | - public void repeat(int from, int thru, int times) { | |
690 | - int len = thru - from; | |
756 | + public void repeat(long from, long thru, int times) { | |
757 | + long len = thru - from; | |
691 | 758 | for (Part part : getPartList()) { |
692 | 759 | for (MutableMusicEvent e : part.getNoteList()) { |
693 | 760 | for (int k = 1; k <= times; k++) { |
@@ -1,6 +1,7 @@ | ||
1 | 1 | package jp.crestmuse.cmx.filewrappers; |
2 | 2 | import jp.crestmuse.cmx.elements.*; |
3 | 3 | import jp.crestmuse.cmx.misc.*; |
4 | +import jp.crestmuse.cmx.math.*; | |
4 | 5 | import groovy.lang.*; |
5 | 6 | import javax.xml.transform.*; |
6 | 7 | import java.io.*; |
@@ -36,7 +37,7 @@ | ||
36 | 37 | } |
37 | 38 | |
38 | 39 | public static class KEY { |
39 | - int time; | |
40 | + long time; | |
40 | 41 | KeySymbol key; |
41 | 42 | public String toString() { |
42 | 43 | return "[time:" + time + " key:" + key.encode() + "]"; |
@@ -385,4 +386,36 @@ | ||
385 | 386 | return counts; |
386 | 387 | } |
387 | 388 | |
389 | + public static DoubleMatrix toMatrix(List<SCC.Note> notes, int channel) { | |
390 | + DoubleMatrix matrix = MathUtils.createDoubleMatrix(notes.size(), 7); | |
391 | + for (int i = 0; i < notes.size(); i++) { | |
392 | + matrix.set(i, 0, (double)notes.get(i).onset(10080) / 10080.0); | |
393 | + matrix.set(i, 1, (double)notes.get(i).duration(10080) / 10080.0); | |
394 | + matrix.set(i, 2, channel); | |
395 | + matrix.set(i, 3, notes.get(i).notenum()); | |
396 | + matrix.set(i, 4, notes.get(i).velocity()); | |
397 | + matrix.set(i, 5, (double)notes.get(i).onsetInMilliSec() / 1000.0); | |
398 | + matrix.set(i, 6, (double)notes.get(i).durationInMilliSec() / 1000.0); | |
399 | + } | |
400 | + return matrix; | |
401 | + } | |
402 | + | |
403 | + | |
404 | + public static List<SCC.Note> getNotesBetween | |
405 | + (SCC.Part part, int from, int thru, int ticksPerBeat, | |
406 | + boolean onsetBased, boolean noteonly) { | |
407 | + synchronized (part) { | |
408 | + SCC.Note[] notes = | |
409 | + noteonly ? part.getSortedNoteOnlyList() : part.getSortedNoteList(); | |
410 | + List<SCC.Note> notes2 = new ArrayList<SCC.Note>(); | |
411 | + for (SCC.Note e : notes) { | |
412 | + if (e.onset(ticksPerBeat) >= from && | |
413 | + (onsetBased ? e.onset(ticksPerBeat) : e.offset(ticksPerBeat)) | |
414 | + <= thru) | |
415 | + notes2.add(e); | |
416 | + } | |
417 | + return notes2; | |
418 | + } | |
419 | + | |
420 | + } | |
388 | 421 | } |
@@ -56,10 +56,10 @@ | ||
56 | 56 | final int div = getDivision(); |
57 | 57 | processNotes(new SCCHandlerAdapter() { |
58 | 58 | private double currentInSec; |
59 | - private int lastTempoChangeInTick; | |
59 | + private long lastTempoChangeInTick; | |
60 | 60 | private double lastTempoChangeInSec; |
61 | 61 | private double currentTempo; |
62 | - private int nextTempoChangeInTick; | |
62 | + private long nextTempoChangeInTick; | |
63 | 63 | private double nextTempoChangeInSec; |
64 | 64 | private double nextTempo; |
65 | 65 | private int nextHeader; |
@@ -80,7 +80,7 @@ | ||
80 | 80 | currentTempo = nextTempo; |
81 | 81 | searchNextTempo(); |
82 | 82 | } |
83 | - note.onsetInMSec = (int)(1000 * calcSec(note.onset())); | |
83 | + note.onsetInMSec = (long)(1000 * calcSec(note.onset())); | |
84 | 84 | if (nextTempoChangeInTick >= 0 |
85 | 85 | && nextTempoChangeInTick < note.offset()) { |
86 | 86 | lastTempoChangeInTick = nextTempoChangeInTick; |
@@ -88,7 +88,7 @@ | ||
88 | 88 | currentTempo = nextTempo; |
89 | 89 | searchNextTempo(); |
90 | 90 | } |
91 | - note.offsetInMSec = (int)(1000 * calcSec(note.offset())); | |
91 | + note.offsetInMSec = (long)(1000 * calcSec(note.offset())); | |
92 | 92 | } |
93 | 93 | private void searchNextTempo() { |
94 | 94 | int i; |
@@ -103,7 +103,7 @@ | ||
103 | 103 | } |
104 | 104 | nextHeader = i + 1; |
105 | 105 | } |
106 | - private double calcSec(int tick) { | |
106 | + private double calcSec(long tick) { | |
107 | 107 | return (tick - lastTempoChangeInTick) * 60 / (div * currentTempo) |
108 | 108 | + lastTempoChangeInSec; |
109 | 109 | } |
@@ -135,7 +135,7 @@ | ||
135 | 135 | } |
136 | 136 | |
137 | 137 | @Deprecated |
138 | - public void addHeaderElement(int time, String name, String content) { | |
138 | + public void addHeaderElement(long time, String name, String content) { | |
139 | 139 | checkElementAddition(headerStarted); |
140 | 140 | addChild("meta"); |
141 | 141 | setAttribute("name", name); |
@@ -145,12 +145,12 @@ | ||
145 | 145 | } |
146 | 146 | |
147 | 147 | @Deprecated |
148 | - public void addHeaderElement(int time, String name, double value) { | |
148 | + public void addHeaderElement(long time, String name, double value) { | |
149 | 149 | addHeaderElement(time, name, String.valueOf(value)); |
150 | 150 | } |
151 | 151 | |
152 | 152 | @Deprecated |
153 | - public void addHeaderElement(int time, String name, int value) { | |
153 | + public void addHeaderElement(long time, String name, int value) { | |
154 | 154 | addHeaderElement(time, name, String.valueOf(value)); |
155 | 155 | } |
156 | 156 |
@@ -245,7 +245,7 @@ | ||
245 | 245 | } |
246 | 246 | |
247 | 247 | @Deprecated |
248 | - public void addPitchBend(int time, int value) { | |
248 | + public void addPitchBend(long time, int value) { | |
249 | 249 | checkElementAddition(partStarted); |
250 | 250 | addChild("pitch-bend"); |
251 | 251 | addText(time + " " + time + " " + value); |
@@ -253,7 +253,7 @@ | ||
253 | 253 | } |
254 | 254 | |
255 | 255 | @Deprecated |
256 | - public void addPitchBend(int onset, int offset, int value) { | |
256 | + public void addPitchBend(long onset, long offset, int value) { | |
257 | 257 | checkElementAddition(partStarted); |
258 | 258 | addChild("pitch-bend"); |
259 | 259 | addText(onset + " " + offset + " " + value); |
@@ -260,7 +260,7 @@ | ||
260 | 260 | returnToParent(); |
261 | 261 | } |
262 | 262 | |
263 | - void addProgramChange(int time, int value) { | |
263 | + void addProgramChange(long time, int value) { | |
264 | 264 | checkElementAddition(partStarted); |
265 | 265 | addChild("program"); |
266 | 266 | addText(time + " " + time + " " + value); |
@@ -268,7 +268,7 @@ | ||
268 | 268 | } |
269 | 269 | |
270 | 270 | @Deprecated |
271 | - public void addControlChange(int time, int ctrlnum, int value) { | |
271 | + public void addControlChange(long time, int ctrlnum, int value) { | |
272 | 272 | checkElementAddition(partStarted); |
273 | 273 | addChild("control"); |
274 | 274 | addText(time + " " + time + " " + ctrlnum + " " + value); |
@@ -276,7 +276,7 @@ | ||
276 | 276 | } |
277 | 277 | |
278 | 278 | @Deprecated |
279 | - public void addControlChange(int onset, int offset, | |
279 | + public void addControlChange(long onset, long offset, | |
280 | 280 | int ctrlnum, int value) { |
281 | 281 | checkElementAddition(partStarted); |
282 | 282 | addChild("control"); |
@@ -285,12 +285,12 @@ | ||
285 | 285 | } |
286 | 286 | |
287 | 287 | @Deprecated |
288 | - public void addNoteElement(int onset, int offset, | |
288 | + public void addNoteElement(long onset, long offset, | |
289 | 289 | int notenum, int velocity) { |
290 | 290 | addNoteElement(onset, offset, notenum, velocity, velocity); |
291 | 291 | } |
292 | 292 | |
293 | - public void addNoteElement(int onset, int offset, | |
293 | + public void addNoteElement(long onset, long offset, | |
294 | 294 | int notenum, int velocity, |
295 | 295 | MusicXMLWrapper.Note note) { |
296 | 296 | checkElementAddition(partStarted); |
@@ -305,13 +305,13 @@ | ||
305 | 305 | } |
306 | 306 | |
307 | 307 | @Deprecated |
308 | - public void addNoteElement(int onset, int offset, int notenum, | |
308 | + public void addNoteElement(long onset, long offset, int notenum, | |
309 | 309 | int velocity, int offVelocity) { |
310 | 310 | addNoteElement(onset, offset, notenum, velocity, offVelocity, null); |
311 | 311 | } |
312 | 312 | |
313 | 313 | @Deprecated |
314 | - public void addNoteElement(int onset, int offset, int notenum, | |
314 | + public void addNoteElement(long onset, long offset, int notenum, | |
315 | 315 | int velocity, int offVelocity, |
316 | 316 | Map<String,String> attr) { |
317 | 317 | addNoteElement(onset, offset, notenum, velocity, offVelocity, attr, null); |
@@ -318,7 +318,7 @@ | ||
318 | 318 | } |
319 | 319 | |
320 | 320 | @Deprecated |
321 | - public void addNoteElement(int onset, int offset, int notenum, | |
321 | + public void addNoteElement(long onset, long offset, int notenum, | |
322 | 322 | int velocity, int offVelocity, |
323 | 323 | Map<String,String> attr, |
324 | 324 | MusicXMLWrapper.Note note) { |
@@ -342,7 +342,7 @@ | ||
342 | 342 | } |
343 | 343 | |
344 | 344 | @Deprecated |
345 | - public void addNoteElementWithWord(String word, int onset, int offset, | |
345 | + public void addNoteElementWithWord(String word, long onset, long offset, | |
346 | 346 | int notenum, int velocity, int offVelocity){ |
347 | 347 | checkElementAddition(partStarted); |
348 | 348 | addChild("note"); |
@@ -351,7 +351,7 @@ | ||
351 | 351 | returnToParent(); |
352 | 352 | } |
353 | 353 | |
354 | - private void putNoteMap(int onset, int offset, int notenum, int velocity, | |
354 | + private void putNoteMap(long onset, long offset, int notenum, int velocity, | |
355 | 355 | int offVelocity, int ticksPerBeat, int partid, |
356 | 356 | MusicXMLWrapper.Note note) { |
357 | 357 | NumberedNote note2 = new NumberedNote(onset, offset, notenum, velocity, |
@@ -382,37 +382,39 @@ | ||
382 | 382 | // } |
383 | 383 | |
384 | 384 | @Deprecated |
385 | - public void addAnnotation(String type, int onset, int offset, | |
385 | + public void addAnnotation(String type, long onset, long offset, | |
386 | 386 | String content) { |
387 | - checkElementAddition(annotationsStarted); | |
388 | - addChildAndText(type, onset + " " + offset + " " + | |
389 | - (content==null ? "" : content)); | |
387 | + if (content != null && content.trim().length() > 0) { | |
388 | + checkElementAddition(annotationsStarted); | |
389 | + addChildAndText(type, onset + " " + offset + " " + | |
390 | + (content==null ? "" : content)); | |
391 | + } | |
390 | 392 | } |
391 | 393 | |
392 | 394 | @Deprecated |
393 | - public void addChord(int onset, int offset, String content) { | |
395 | + public void addChord(long onset, long offset, String content) { | |
394 | 396 | addAnnotation("chord", onset, offset, content); |
395 | 397 | } |
396 | 398 | |
397 | 399 | // Added: 2014/11/18, Author: tama |
398 | 400 | @Deprecated |
399 | - public void addLyric(int onset, int offset, String content) { | |
401 | + public void addLyric(long onset, long offset, String content) { | |
400 | 402 | addAnnotation("lyric", onset, offset, content); |
401 | 403 | } |
402 | 404 | |
403 | 405 | // Added: 2014/11/18, Author: tama |
404 | 406 | @Deprecated |
405 | - public void addCuePoint(int onset, int offset, String content) { | |
407 | + public void addCuePoint(long onset, long offset, String content) { | |
406 | 408 | addAnnotation("cue", onset, offset, content); |
407 | 409 | } |
408 | 410 | |
409 | 411 | @Deprecated |
410 | - public void addMarker(int onset, int offset, String content) { | |
412 | + public void addMarker(long onset, long offset, String content) { | |
411 | 413 | addAnnotation("marker", onset, offset, content); |
412 | 414 | } |
413 | 415 | |
414 | 416 | @Deprecated |
415 | - public void addBarline(int time, String details) { | |
417 | + public void addBarline(long time, String details) { | |
416 | 418 | addAnnotation("barline", time, time, details); |
417 | 419 | } |
418 | 420 |
@@ -438,8 +440,8 @@ | ||
438 | 440 | |
439 | 441 | /** lyricイベントとcuePointに対応させるために、TextからContenを抜き出す処理を正規表現に変更 */ |
440 | 442 | public class Annotation extends NodeInterface implements SCC.Annotation { |
441 | - private int onset; | |
442 | - private int offset; | |
443 | + private long onset; | |
444 | + private long offset; | |
443 | 445 | private String content; |
444 | 446 | // Modified: 2014/11/18 by tama |
445 | 447 | private Annotation(Node node) { |
@@ -502,11 +504,11 @@ | ||
502 | 504 | protected String getSupportedNodeName() { |
503 | 505 | return "chord|barline|lyrics|cuePoint|marker"; |
504 | 506 | } |
505 | - public final int onset(){ return onset; } | |
506 | - public final int offset(){ return offset; } | |
507 | + public final long onset(){ return onset; } | |
508 | + public final long offset(){ return offset; } | |
507 | 509 | public final String content(){ return content; } |
508 | 510 | |
509 | - public final int onset(int ticksPerBeat) { | |
511 | + public final long onset(int ticksPerBeat) { | |
510 | 512 | if (ticksPerBeat == getDivision()) |
511 | 513 | return onset; |
512 | 514 | else |
@@ -513,7 +515,7 @@ | ||
513 | 515 | return onset * ticksPerBeat / getDivision(); |
514 | 516 | } |
515 | 517 | |
516 | - public final int offset(int ticksPerBeat) { | |
518 | + public final long offset(int ticksPerBeat) { | |
517 | 519 | if (ticksPerBeat == getDivision()) |
518 | 520 | return offset; |
519 | 521 | else |
@@ -664,12 +666,12 @@ | ||
664 | 666 | |
665 | 667 | public class HeaderElement extends NodeInterface |
666 | 668 | implements SCC.HeaderElement { |
667 | - private int timestamp; | |
669 | + private long timestamp; | |
668 | 670 | private String name; |
669 | 671 | private String content; |
670 | 672 | private HeaderElement(Node node) { |
671 | 673 | super(node); |
672 | - timestamp = getAttributeInt(node, "time"); | |
674 | + timestamp = getAttributeLong(node, "time"); | |
673 | 675 | name = getAttribute(node, "name"); |
674 | 676 | content = getAttribute(node, "content"); |
675 | 677 | } |
@@ -676,7 +678,7 @@ | ||
676 | 678 | protected String getSupportedNodeName() { |
677 | 679 | return "meta"; |
678 | 680 | } |
679 | - public int time() { | |
681 | + public long time() { | |
680 | 682 | return timestamp; |
681 | 683 | } |
682 | 684 | public String name() { |
@@ -691,7 +693,7 @@ | ||
691 | 693 | } |
692 | 694 | public int compareTo(SCC.HeaderElement e) { |
693 | 695 | if (timestamp != e.time()) |
694 | - return timestamp - e.time(); | |
696 | + return (int)(timestamp - e.time()); | |
695 | 697 | else if (!name.equals(e.name())) |
696 | 698 | return name.compareTo(e.name()); |
697 | 699 | else if (!content.equals(e.content())) |
@@ -771,7 +773,7 @@ | ||
771 | 773 | Node node = metalist.item(i); |
772 | 774 | String name = NodeInterface.getAttribute(node, "name"); |
773 | 775 | String content = NodeInterface.getAttribute(node, "content"); |
774 | - int timestamp = NodeInterface.getAttributeInt(node, "time"); | |
776 | + long timestamp = NodeInterface.getAttributeLong(node, "time"); | |
775 | 777 | h.processHeaderElement(timestamp, name, content, this); |
776 | 778 | } |
777 | 779 | h.endHeader(this); |
@@ -828,8 +830,36 @@ | ||
828 | 830 | return partlist; |
829 | 831 | } |
830 | 832 | |
833 | + public Part getPartWithSerial(int serial) throws TransformerException { | |
834 | + Part[] parts = getPartList(); | |
835 | + for (Part part : parts) { | |
836 | + if (part.serial() == serial) | |
837 | + return part; | |
838 | + } | |
839 | + return null; | |
840 | + } | |
831 | 841 | |
842 | + public Part[] getPartsWithChannel(int ch) throws TransformerException { | |
843 | + Part[] parts = getPartList(); | |
844 | + List<Part> l = new ArrayList<Part>(); | |
845 | + for (Part part : parts) { | |
846 | + if (part.channel() == ch) { | |
847 | + l.add(part); | |
848 | + } | |
849 | + } | |
850 | + return l.toArray(new Part[l.size()]); | |
851 | + } | |
852 | + | |
853 | + public Part getFirstPartWithChannel(int ch) throws TransformerException { | |
854 | + Part[] parts = getPartList(); | |
855 | + for (Part part : parts) { | |
856 | + if (part.channel() == ch) | |
857 | + return part; | |
858 | + } | |
859 | + return null; | |
860 | + } | |
832 | 861 | |
862 | + | |
833 | 863 | // public int getNumOfParts() throws TransformerException { |
834 | 864 | // return selectNodeList("/scc/part").getLength(); |
835 | 865 | // } |
@@ -895,7 +925,7 @@ | ||
895 | 925 | dest.addElementsFirstForFormat1(getPartList().length + 1, getDivision()); |
896 | 926 | processNotes(new SCCHandler() { |
897 | 927 | private int currentTrack = 1; |
898 | - private int currentTime = 0; | |
928 | + private long currentTime = 0; | |
899 | 929 | public final void beginHeader(SCCXMLWrapper w) { |
900 | 930 | dest.newTrack(currentTrack); |
901 | 931 | } |
@@ -903,15 +933,15 @@ | ||
903 | 933 | dest.endTrack(); |
904 | 934 | currentTrack++; |
905 | 935 | } |
906 | - public final void processHeaderElement(int timestamp, String name, | |
936 | + public final void processHeaderElement(long timestamp, String name, | |
907 | 937 | String content, SCCXMLWrapper w) { |
908 | 938 | if (name.equals("TEMPO")) |
909 | - dest.addMetaEvent("SetTempo", timestamp - currentTime, | |
939 | + dest.addMetaEvent("SetTempo", (int)(timestamp - currentTime), | |
910 | 940 | (int)(1000*1000*60/Double.parseDouble(content))); |
911 | 941 | else if (name.equals("KEY")) { |
912 | 942 | KeySymbol key = KeySymbol.parse(content); |
913 | 943 | int mode = key.mode().equals(KeySymbol.Mode.MIN) ? 1 : 0; |
914 | - dest.addMetaEvent("KeySignature", timestamp - currentTime, | |
944 | + dest.addMetaEvent("KeySignature", (int)(timestamp - currentTime), | |
915 | 945 | key.toInteger(), mode); |
916 | 946 | |
917 | 947 | // String[] data = content.trim().split(" "); |
@@ -977,7 +1007,7 @@ | ||
977 | 1007 | public final void endHeader(SCCXMLWrapper w) { |
978 | 1008 | newscc.endHeader(); |
979 | 1009 | } |
980 | - public final void processHeaderElement(int timestamp, String name, | |
1010 | + public final void processHeaderElement(long timestamp, String name, | |
981 | 1011 | String content, SCCXMLWrapper w) { |
982 | 1012 | newscc.addHeaderElement(timestamp, name, content); |
983 | 1013 | } |
@@ -1027,7 +1057,7 @@ | ||
1027 | 1057 | public final void endHeader(SCCXMLWrapper w) { |
1028 | 1058 | newscc.endHeader(); |
1029 | 1059 | } |
1030 | - public final void processHeaderElement(int timestamp, String name, | |
1060 | + public final void processHeaderElement(long timestamp, String name, | |
1031 | 1061 | String content, SCCXMLWrapper w) { |
1032 | 1062 | newscc.addHeaderElement(timestamp, name, content); |
1033 | 1063 | } |
@@ -1144,8 +1174,8 @@ | ||
1144 | 1174 | (n1.notenum() == n2.notenum() ? |
1145 | 1175 | n1.velocity() - n2.velocity() |
1146 | 1176 | : n1.notenum() - n2.notenum() |
1147 | - ) : n1.offset() - n2.offset() | |
1148 | - ) : n1.onset() - n2.onset(); | |
1177 | + ) : (int)(n1.offset() - n2.offset()) | |
1178 | + ) : (int)(n1.onset() - n2.onset()); | |
1149 | 1179 | } |
1150 | 1180 | }); |
1151 | 1181 | return l; |
@@ -1161,8 +1191,8 @@ | ||
1161 | 1191 | (n1.notenum() == n2.notenum() ? |
1162 | 1192 | n1.velocity() - n2.velocity() |
1163 | 1193 | : n1.notenum() - n2.notenum() |
1164 | - ) : n1.offset() - n2.offset() | |
1165 | - ) : n1.onset() - n2.onset(); | |
1194 | + ) : (int)(n1.offset() - n2.offset()) | |
1195 | + ) : (int)(n1.onset() - n2.onset()); | |
1166 | 1196 | } |
1167 | 1197 | }); |
1168 | 1198 | return l; |
@@ -1177,7 +1207,7 @@ | ||
1177 | 1207 | (n1.notenum() == n2.notenum() ? |
1178 | 1208 | n1.velocity() - n2.velocity() |
1179 | 1209 | : n1.notenum() - n2.notenum() |
1180 | - ) : n1.onset() - n2.onset(); | |
1210 | + ) : (int)(n1.onset() - n2.onset()); | |
1181 | 1211 | } |
1182 | 1212 | }); |
1183 | 1213 | return l; |
@@ -1192,7 +1222,7 @@ | ||
1192 | 1222 | (n1.notenum() == n2.notenum() ? |
1193 | 1223 | n1.velocity() - n2.velocity() |
1194 | 1224 | : n1.notenum() - n2.notenum() |
1195 | - ) : n1.onset() - n2.onset(); | |
1225 | + ) : (int)(n1.onset() - n2.onset()); | |
1196 | 1226 | } |
1197 | 1227 | }); |
1198 | 1228 | return l; |
@@ -1322,8 +1352,9 @@ | ||
1322 | 1352 | |
1323 | 1353 | public class Note extends NodeInterface implements SCC.Note { |
1324 | 1354 | private Part part; |
1325 | - private int onset, offset, notenum, velocity, offVelocity; | |
1326 | - private int onsetInMSec, offsetInMSec; | |
1355 | + private long onset, offset; | |
1356 | + private int notenum, velocity, offVelocity; | |
1357 | + private long onsetInMSec, offsetInMSec; | |
1327 | 1358 | private String xpath; |
1328 | 1359 | |
1329 | 1360 | private Note(Node node, Part part) { |
@@ -1350,11 +1381,11 @@ | ||
1350 | 1381 | return "note|control|program|pitch-bend"; |
1351 | 1382 | } |
1352 | 1383 | |
1353 | - public final int onset() { | |
1384 | + public final long onset() { | |
1354 | 1385 | return onset; |
1355 | 1386 | } |
1356 | 1387 | |
1357 | - public final int onset(int ticksPerBeat) { | |
1388 | + public final long onset(int ticksPerBeat) { | |
1358 | 1389 | if (ticksPerBeat == getDivision()) |
1359 | 1390 | return onset; |
1360 | 1391 | else |
@@ -1361,11 +1392,11 @@ | ||
1361 | 1392 | return onset * ticksPerBeat / getDivision(); |
1362 | 1393 | } |
1363 | 1394 | |
1364 | - public final int offset() { | |
1395 | + public final long offset() { | |
1365 | 1396 | return offset; |
1366 | 1397 | } |
1367 | 1398 | |
1368 | - public final int offset(int ticksPerBeat) { | |
1399 | + public final long offset(int ticksPerBeat) { | |
1369 | 1400 | if (ticksPerBeat == getDivision()) |
1370 | 1401 | return offset; |
1371 | 1402 | else |
@@ -1372,7 +1403,7 @@ | ||
1372 | 1403 | return offset * ticksPerBeat / getDivision(); |
1373 | 1404 | } |
1374 | 1405 | |
1375 | - public final int duration(int ticksPerBeat) { | |
1406 | + public final long duration(int ticksPerBeat) { | |
1376 | 1407 | return offset(ticksPerBeat) - onset(ticksPerBeat); |
1377 | 1408 | } |
1378 | 1409 |
@@ -1392,22 +1423,26 @@ | ||
1392 | 1423 | return part; |
1393 | 1424 | } |
1394 | 1425 | |
1395 | - /** Obsolete. use onsetInMilliSec() instead. */ | |
1396 | - public final int onsetInMSec() { | |
1397 | - return onsetInMSec; | |
1398 | - } | |
1426 | + // /** Obsolete. use onsetInMilliSec() instead. */ | |
1427 | + // public final int onsetInMSec() { | |
1428 | + // return onsetInMSec; | |
1429 | + // } | |
1399 | 1430 | |
1400 | - public final int onsetInMilliSec() { | |
1431 | + public final long onsetInMilliSec() { | |
1401 | 1432 | return onsetInMSec; |
1402 | 1433 | } |
1403 | 1434 | |
1404 | - /** Obsolete. use offsetInMilliSec() instead. */ | |
1405 | - public final int offsetInMSec() { | |
1435 | + // /** Obsolete. use offsetInMilliSec() instead. */ | |
1436 | + // public final int offsetInMSec() { | |
1437 | + // return offsetInMSec; | |
1438 | + //} | |
1439 | + | |
1440 | + public final long offsetInMilliSec() { | |
1406 | 1441 | return offsetInMSec; |
1407 | 1442 | } |
1408 | 1443 | |
1409 | - public final int offsetInMilliSec() { | |
1410 | - return offsetInMSec; | |
1444 | + public final long durationInMilliSec() { | |
1445 | + return offsetInMSec - onsetInMSec; | |
1411 | 1446 | } |
1412 | 1447 | |
1413 | 1448 | public MusicXMLWrapper.Note getMusicXMLWrapperNote() { |
@@ -1488,11 +1523,11 @@ | ||
1488 | 1523 | private class NumberedNote extends MutableNote { |
1489 | 1524 | private int partid; |
1490 | 1525 | private byte number = 1; |
1491 | - private NumberedNote(int onset, int offset, int notenum, int velocity, | |
1526 | + private NumberedNote(long onset, long offset, int notenum, int velocity, | |
1492 | 1527 | int ticksPerBeat, int partid) { |
1493 | 1528 | this(onset, offset, notenum, velocity, velocity, ticksPerBeat, partid); |
1494 | 1529 | } |
1495 | - private NumberedNote(int onset, int offset, int notenum, int velocity, | |
1530 | + private NumberedNote(long onset, long offset, int notenum, int velocity, | |
1496 | 1531 | int offVelocity, int ticksPerBeat, int partid) { |
1497 | 1532 | super(onset, offset, notenum, velocity, offVelocity, ticksPerBeat); |
1498 | 1533 | this.partid = partid; |
@@ -1515,11 +1550,11 @@ | ||
1515 | 1550 | } |
1516 | 1551 | |
1517 | 1552 | class EasyChord{ |
1518 | - public int onset; | |
1519 | - public int offset; | |
1553 | + public long onset; | |
1554 | + public long offset; | |
1520 | 1555 | public String chord; |
1521 | 1556 | |
1522 | - public EasyChord(int onset, int offset, String chord){ | |
1557 | + public EasyChord(long onset, long offset, String chord){ | |
1523 | 1558 | this.onset = onset; |
1524 | 1559 | this.offset = offset; |
1525 | 1560 | this.chord = chord; |
@@ -5,7 +5,7 @@ | ||
5 | 5 | public interface SCCHandler { |
6 | 6 | public void beginHeader(SCCXMLWrapper w); |
7 | 7 | public void endHeader(SCCXMLWrapper w); |
8 | - public void processHeaderElement(int timestamp, String name, | |
8 | + public void processHeaderElement(long timestamp, String name, | |
9 | 9 | String content, SCCXMLWrapper w); |
10 | 10 | public void beginPart(SCCXMLWrapper.Part part, SCCXMLWrapper w); |
11 | 11 | public void endPart(SCCXMLWrapper.Part part, SCCXMLWrapper w); |
@@ -12,4 +12,4 @@ | ||
12 | 12 | public void processNote(SCCXMLWrapper.Note note, SCCXMLWrapper w); |
13 | 13 | // public void processNote(SCCXMLWrapper.Note note, |
14 | 14 | // SCCXMLWrapper.Part part, SCCXMLWrapper w); |
15 | -} | |
\ No newline at end of file | ||
15 | +} |
@@ -9,7 +9,7 @@ | ||
9 | 9 | public void endHeader(SCCXMLWrapper w) { |
10 | 10 | // do nothing |
11 | 11 | } |
12 | - public void processHeaderElement(int timestamp, String name, | |
12 | + public void processHeaderElement(long timestamp, String name, | |
13 | 13 | String content, SCCXMLWrapper w) { |
14 | 14 | // do nothing |
15 | 15 | } |
@@ -0,0 +1,29 @@ | ||
1 | +package jp.crestmuse.cmx.math; | |
2 | + | |
3 | +class DoubleMatrixImplAsArray extends AbstractDoubleMatrixImpl { | |
4 | + private double[] values; | |
5 | + private int nrows, ncols; | |
6 | + | |
7 | + DoubleMatrixImplAsArray(int nrows, int ncols, double[] values) { | |
8 | + this.values = values; | |
9 | + this.nrows = nrows; | |
10 | + this.ncols = ncols; | |
11 | + } | |
12 | + | |
13 | + public int nrows() { | |
14 | + return nrows; | |
15 | + } | |
16 | + | |
17 | + public int ncols() { | |
18 | + return ncols; | |
19 | + } | |
20 | + | |
21 | + public double get(int i, int j) { | |
22 | + return values[i + j * nrows]; | |
23 | + } | |
24 | + | |
25 | + public void set(int i, int j, double value) { | |
26 | + values[i + j * nrows] = value; | |
27 | + } | |
28 | +} | |
29 | + |
@@ -3,6 +3,8 @@ | ||
3 | 3 | import java.math.*; |
4 | 4 | import org.apache.commons.math.linear.*; |
5 | 5 | import java.nio.*; |
6 | +import dk.ange.octave.*; | |
7 | +import dk.ange.octave.type.*; | |
6 | 8 | |
7 | 9 | public class MathUtils { |
8 | 10 | private static final DoubleArrayFactory factory = |
@@ -254,19 +256,27 @@ | ||
254 | 256 | return parseMatrix(text, " ", "\n"); |
255 | 257 | } |
256 | 258 | |
257 | - public static final DoubleArray createDoubleArray(int length) { | |
258 | - return factory.createArray(length); | |
259 | - } | |
259 | + public static final DoubleArray createDoubleArray(int length) { | |
260 | + return factory.createArray(length); | |
261 | + } | |
260 | 262 | |
261 | - public static final DoubleArray createDoubleArray(double[] x) { | |
262 | - return factory.createArray(x); | |
263 | - } | |
263 | + // public static final DoubleArray array(int length) { | |
264 | + // return createDoubleArray(length); | |
265 | + // } | |
266 | + | |
267 | + public static final DoubleArray createDoubleArray(double[] x) { | |
268 | + return factory.createArray(x); | |
269 | + } | |
264 | 270 | |
265 | - public static final DoubleArray createDoubleArray(List<? extends Number> x) { | |
266 | - int length = x.size(); | |
267 | - DoubleArray array = createDoubleArray(length); | |
268 | - for (int i = 0; i < length; i++) { | |
269 | - array.set(i, x.get(i).doubleValue()); | |
271 | + public static final DoubleArray array(double[] x) { | |
272 | + return createDoubleArray(x); | |
273 | + } | |
274 | + | |
275 | + public static final DoubleArray createDoubleArray(List<? extends Number> x) { | |
276 | + int length = x.size(); | |
277 | + DoubleArray array = createDoubleArray(length); | |
278 | + for (int i = 0; i < length; i++) { | |
279 | + array.set(i, x.get(i).doubleValue()); | |
270 | 280 | // Object x1 = x.get(i); |
271 | 281 | // if (x1 instanceof Double) |
272 | 282 | // array.set(i, ((Double)x1).doubleValue()); |
@@ -274,10 +284,14 @@ | ||
274 | 284 | // array.set(i, ((BigDecimal)x1).doubleValue()); |
275 | 285 | // else |
276 | 286 | // throw new IllegalArgumentException("Not double value: " + x1); |
277 | - } | |
278 | - return array; | |
279 | 287 | } |
288 | + return array; | |
289 | + } | |
280 | 290 | |
291 | + public static final DoubleArray array(List<? extends Number> x) { | |
292 | + return createDoubleArray(x); | |
293 | + } | |
294 | + | |
281 | 295 | public static final DoubleArray createDoubleArrayWithNegativeIndex(int length) { |
282 | 296 | return new DefaultDoubleArrayWithNegativeIndex(length); |
283 | 297 | } |
@@ -320,28 +334,41 @@ | ||
320 | 334 | return mfactory.createMatrix(nrows, ncols); |
321 | 335 | } |
322 | 336 | |
323 | - public static final DoubleMatrix createDoubleMatrix(List<List<BigDecimal>> x){ | |
324 | - int nrows = x.size(); | |
325 | - int ncols = x.get(0).size(); | |
326 | - DoubleMatrix matrix = createDoubleMatrix(nrows, ncols); | |
327 | - for (int i = 0; i < nrows; i++) { | |
328 | - List<BigDecimal> l = x.get(i); | |
329 | - for (int j = 0; j < ncols; j++) | |
330 | - matrix.set(i, j, l.get(j).doubleValue()); | |
331 | - } | |
332 | - return matrix; | |
337 | + // public static final DoubleMatrix mat(int nrows, int ncols) { | |
338 | + // return createDoubleMatrix(nrows, ncols); | |
339 | + // } | |
340 | + | |
341 | + public static final DoubleMatrix | |
342 | + createDoubleMatrix(List<List<? extends Number>> x){ | |
343 | + int nrows = x.size(); | |
344 | + int ncols = x.get(0).size(); | |
345 | + DoubleMatrix matrix = createDoubleMatrix(nrows, ncols); | |
346 | + for (int i = 0; i < nrows; i++) { | |
347 | + List<? extends Number> l = x.get(i); | |
348 | + for (int j = 0; j < ncols; j++) | |
349 | + matrix.set(i, j, l.get(j).doubleValue()); | |
333 | 350 | } |
351 | + return matrix; | |
352 | + } | |
334 | 353 | |
354 | + public static final DoubleMatrix mat(List<List<? extends Number>> x) { | |
355 | + return createDoubleMatrix(x); | |
356 | + } | |
357 | + | |
335 | 358 | public static final ComplexMatrix createComplexMatrix(int nrows, int ncols) { |
336 | 359 | return cmfactory.createMatrix(nrows, ncols); |
337 | 360 | } |
338 | 361 | |
339 | - public static final DoubleArray create1dimDoubleArray(double x) { | |
340 | - DoubleArray array = factory.createArray(1); | |
341 | - array.set(0, x); | |
342 | - return array; | |
343 | - } | |
362 | + public static final DoubleArray create1dimDoubleArray(double x) { | |
363 | + DoubleArray array = factory.createArray(1); | |
364 | + array.set(0, x); | |
365 | + return array; | |
366 | + } | |
344 | 367 | |
368 | + // public static final DoubleArray arrayOf(double x) { | |
369 | + // return create1dimDoubleArray(x); | |
370 | + // } | |
371 | + | |
345 | 372 | public static final RealMatrix toRealMatrix(DoubleMatrix x) { |
346 | 373 | return new MyRealMatrix(x); |
347 | 374 | } |
@@ -422,6 +449,73 @@ | ||
422 | 449 | } |
423 | 450 | } |
424 | 451 | } |
452 | + | |
453 | + public static DoubleMatrix createDoubleMatrixFromArrays(List<DoubleArray> list) { | |
454 | + return createDoubleMatrixFromArrays(list.toArray(new DoubleArray[0])); | |
455 | + } | |
456 | + | |
457 | + public static DoubleMatrix array2mat(List<DoubleArray> list) { | |
458 | + return createDoubleMatrixFromArrays(list); | |
459 | + } | |
460 | + | |
461 | + public static DoubleMatrix createDoubleMatrixFromArrays(DoubleArray[] list) { | |
462 | + int dim = list[0].length(); | |
463 | + for (int i = 1; i < list.length; i++) { | |
464 | + if (list[i].length() != dim) | |
465 | + throw new MathException("Dimension doesn't match"); | |
466 | + } | |
467 | + return new MyDoubleMatrix2(list); | |
468 | + } | |
469 | + | |
470 | + public static DoubleMatrix array2mat(DoubleArray[] list) { | |
471 | + return createDoubleMatrixFromArrays(list); | |
472 | + } | |
473 | + | |
474 | + private static class MyDoubleMatrix2 extends AbstractDoubleMatrixImpl { | |
475 | + private DoubleArray[] list; | |
476 | + private MyDoubleMatrix2(DoubleArray[] list) { | |
477 | + this.list = list; | |
478 | + } | |
479 | + public int nrows() { | |
480 | + return list[0].length(); | |
481 | + } | |
482 | + public int ncols() { | |
483 | + return list.length; | |
484 | + } | |
485 | + public double get(int i, int j) { | |
486 | + return list[j].get(i); | |
487 | + } | |
488 | + public void set(int i, int j, double value) { | |
489 | + list[j].set(i, value); | |
490 | + } | |
491 | + } | |
492 | + | |
493 | + public static OctaveDouble toOctave(DoubleMatrix x) { | |
494 | + int nrows = x.nrows(); | |
495 | + int ncols = x.ncols(); | |
496 | + double[] array = new double[nrows * ncols]; | |
497 | + for (int i = 0; i < nrows; i++) { | |
498 | + for (int j = 0; j < ncols; j++) { | |
499 | + array[i + nrows * j] = x.get(i, j); | |
500 | + } | |
501 | + } | |
502 | + return new OctaveDouble(array, nrows, ncols); | |
503 | + } | |
504 | + | |
505 | + /* | |
506 | + public static void toOctave(OctaveEngine octave, String name, DoubleMatrix x) { | |
507 | + octave.put(name, toOctave(x)); | |
508 | + } | |
509 | + */ | |
510 | + | |
511 | + public static DoubleMatrix fromOctave(OctaveDouble x) { | |
512 | + return new DoubleMatrixImplAsArray(x.getSize()[0], x.getSize()[1], x.getData()); | |
513 | + } | |
514 | + | |
515 | + public static DoubleMatrix fromOctave(OctaveEngine octave, String name) { | |
516 | + return fromOctave(octave.get(OctaveDouble.class, name)); | |
517 | + } | |
518 | + | |
425 | 519 | } |
426 | 520 | |
427 | - | |
\ No newline at end of file | ||
521 | + |
@@ -540,7 +540,7 @@ | ||
540 | 540 | } |
541 | 541 | |
542 | 542 | public static final int Hz2nn(double x) { |
543 | - return 57 + (int)(12 * log(x / 220.0) / log(2)); | |
543 | + return 57 + (int)(12 * Math.log(x / 220.0) / Math.log(2)); | |
544 | 544 | } |
545 | 545 | |
546 | 546 | public static final double nn2Hz(double nn) { |
@@ -548,13 +548,36 @@ | ||
548 | 548 | } |
549 | 549 | |
550 | 550 | |
551 | - public static void logX(DoubleArray x, int a) { | |
551 | + public static void logX(DoubleArray x) { | |
552 | 552 | int length = x.length(); |
553 | - double logA = log(a); | |
554 | 553 | for (int i = 0; i < length; i++) |
555 | - x.set(i, log(x.get(i)) / logA); | |
554 | + x.set(i, Math.log(x.get(i))); | |
556 | 555 | } |
556 | + | |
557 | + public static void logX(DoubleArray x, double a) { | |
558 | + int length = x.length(); | |
559 | + double logA = Math.log(a); | |
560 | + for (int i = 0; i < length; i++) | |
561 | + x.set(i, Math.log(x.get(i)) / logA); | |
562 | + } | |
557 | 563 | |
564 | + public static DoubleArray log(DoubleArray x) { | |
565 | + int length = x.length(); | |
566 | + DoubleArray y = factory.createArray(length); | |
567 | + for (int i = 0; i < length; i++) | |
568 | + y.set(i, Math.log(x.get(i))); | |
569 | + return y; | |
570 | + } | |
571 | + | |
572 | + public static DoubleArray log(DoubleArray x, double a) { | |
573 | + int length = x.length(); | |
574 | + double logA = Math.log(a); | |
575 | + DoubleArray y = factory.createArray(length); | |
576 | + for (int i = 0; i < length; i++) | |
577 | + y.set(i, Math.log(x.get(i)) / logA); | |
578 | + return y; | |
579 | + } | |
580 | + | |
558 | 581 | public static double ratioTrue(BooleanArray x) { |
559 | 582 | int nTrues = 0; |
560 | 583 | int length = x.length(); |
@@ -786,15 +809,45 @@ | ||
786 | 809 | return z; |
787 | 810 | } |
788 | 811 | |
812 | + public static double get(DoubleMatrix x, int i) { | |
813 | + if (x.nrows() == 1) | |
814 | + return x.get(0, i); | |
815 | + else if (x.ncols() == 1) | |
816 | + return x.get(i, 0); | |
817 | + else | |
818 | + throw new IllegalArgumentException("For get(DoubleMatrix m, int i), the number of rows or columns should be 1 (nrows: " + x.nrows() + ", ncols: " + x.ncols() + ")" ); | |
819 | + } | |
789 | 820 | |
821 | + public static double getAt(DoubleMatrix x, int i) { | |
822 | + return get(x, i); | |
823 | + } | |
824 | + | |
790 | 825 | public static double getAt(DoubleMatrix x, int[] indices) { |
791 | 826 | return x.get(indices[0], indices[1]); |
792 | 827 | } |
793 | 828 | |
829 | + public static void set(DoubleMatrix x, int i, double value) { | |
830 | + if (x.nrows() == 1) | |
831 | + x.set(0, i, value); | |
832 | + else if (x.ncols() == 1) | |
833 | + x.set(i, 0, value); | |
834 | + else | |
835 | + throw new IllegalArgumentException(); | |
836 | + } | |
837 | + | |
838 | + public static void putAt(DoubleMatrix x, int i, double value) { | |
839 | + set(x, i, value); | |
840 | + } | |
841 | + | |
842 | + | |
794 | 843 | public static void putAt(DoubleMatrix x, int[] indices, double value) { |
795 | 844 | x.set(indices[0], indices[1], value); |
796 | 845 | } |
797 | 846 | |
847 | + // public static void putAt(DoubleMatrix x, int i, int j, double value) { | |
848 | + // x.set(i, j, value); | |
849 | + // } | |
850 | + | |
798 | 851 | public static DoubleMatrix add(DoubleMatrix x, DoubleMatrix y) { |
799 | 852 | int nrows = x.nrows(); |
800 | 853 | int ncols = x.ncols(); |
@@ -823,6 +876,32 @@ | ||
823 | 876 | return add(x, y); |
824 | 877 | } |
825 | 878 | |
879 | + public static DoubleMatrix add(DoubleMatrix x, double value) { | |
880 | + int nrows = x.nrows(); | |
881 | + int ncols = x.ncols(); | |
882 | + DoubleMatrix z = mfactory.createMatrix(nrows, ncols); | |
883 | + for (int i = 0; i < nrows; i++) | |
884 | + for (int j = 0; j < ncols; j++) | |
885 | + z.set(i, j, x.get(i, j) + value); | |
886 | + return z; | |
887 | + } | |
888 | + | |
889 | + public static DoubleMatrix plus(DoubleMatrix x, double value) { | |
890 | + return add(x, value); | |
891 | + } | |
892 | + | |
893 | + public static void addX(DoubleMatrix x, int i, int j, double value) { | |
894 | + x.set(i, j, value + x.get(i, j)); | |
895 | + } | |
896 | + | |
897 | + public static void addX(DoubleMatrix x, double value) { | |
898 | + int nrows = x.nrows(); | |
899 | + int ncols = x.ncols(); | |
900 | + for (int i = 0; i < nrows; i++) | |
901 | + for (int j = 0; j < ncols; j++) | |
902 | + x.set(i, j, x.get(i, j) + value); | |
903 | + } | |
904 | + | |
826 | 905 | public static DoubleMatrix sub(DoubleMatrix x, DoubleMatrix y) { |
827 | 906 | int nrows = x.nrows(); |
828 | 907 | int ncols = x.ncols(); |
@@ -850,7 +929,21 @@ | ||
850 | 929 | public static DoubleMatrix minus(DoubleMatrix x, DoubleArray y) { |
851 | 930 | return sub(x, y); |
852 | 931 | } |
853 | - | |
932 | + | |
933 | + public static DoubleMatrix sub(DoubleMatrix x, double y) { | |
934 | + int nrows = x.nrows(); | |
935 | + int ncols = x.ncols(); | |
936 | + DoubleMatrix z = mfactory.createMatrix(nrows, ncols); | |
937 | + for (int i = 0; i < nrows; i++) | |
938 | + for (int j = 0; j < ncols; j++) | |
939 | + z.set(i, j, x.get(i, j) - y); | |
940 | + return z; | |
941 | + } | |
942 | + | |
943 | + public static DoubleMatrix minus(DoubleMatrix x, double y) { | |
944 | + return sub(x, y); | |
945 | + } | |
946 | + | |
854 | 947 | public static DoubleMatrix mul(DoubleMatrix x, double y) { |
855 | 948 | int nrows = x.nrows(); |
856 | 949 | int ncols = x.ncols(); |
@@ -881,6 +974,17 @@ | ||
881 | 974 | return z; |
882 | 975 | } |
883 | 976 | |
977 | + public static DoubleMatrix mulE(DoubleMatrix x, DoubleMatrix y) { | |
978 | + int nrows = x.nrows(); | |
979 | + int ncols = x.ncols(); | |
980 | + DoubleMatrix z = mfactory.createMatrix(nrows, ncols); | |
981 | + for (int i = 0; i < nrows; i++) | |
982 | + for (int j = 0; j < ncols; j++) | |
983 | + z.set(i, j, x.get(i, j) * y.get(i, j)); | |
984 | + return z; | |
985 | + } | |
986 | + | |
987 | + | |
884 | 988 | public static DoubleMatrix multiply(DoubleMatrix x, DoubleMatrix y) { |
885 | 989 | return mul(x, y); |
886 | 990 | } |
@@ -1251,8 +1355,33 @@ | ||
1251 | 1355 | } |
1252 | 1356 | return factory.createArray(z); |
1253 | 1357 | } |
1358 | + | |
1359 | + public static int sign(int x) { | |
1360 | + if (x > 0) | |
1361 | + return 1; | |
1362 | + else if (x < 0) | |
1363 | + return -1; | |
1364 | + else | |
1365 | + return 0; | |
1366 | + } | |
1367 | + | |
1368 | + public static double sign(double x) { | |
1369 | + if (x > 0.0) | |
1370 | + return 1.0; | |
1371 | + else if (x < 0.0) | |
1372 | + return -1.0; | |
1373 | + else | |
1374 | + return 0.0; | |
1375 | + } | |
1254 | 1376 | |
1377 | + public static double abs(double x) { | |
1378 | + return Math.abs(x); | |
1379 | + } | |
1255 | 1380 | |
1381 | + public static int abs(int x) { | |
1382 | + return Math.abs(x); | |
1383 | + } | |
1384 | + | |
1256 | 1385 | public static DoubleArray abs(DoubleArray x) { |
1257 | 1386 | int length = x.length(); |
1258 | 1387 | double[] z = new double[length]; |
@@ -1308,6 +1437,41 @@ | ||
1308 | 1437 | } |
1309 | 1438 | return factory.createArray(z); |
1310 | 1439 | } |
1440 | + | |
1441 | + public static DoubleArray insertAtFirst(DoubleArray x, double value, int n) { | |
1442 | + return new MyDoubleArray1(x, value, n); | |
1443 | + } | |
1444 | + | |
1445 | + private static class MyDoubleArray1 extends AbstractDoubleArrayImpl { | |
1446 | + private DoubleArray array; | |
1447 | + private double value; | |
1448 | + private int n; | |
1449 | + MyDoubleArray1(DoubleArray x, double value, int n) { | |
1450 | + array = x; | |
1451 | + this.value = value; | |
1452 | + this.n = n; | |
1453 | + } | |
1454 | + public int length() { | |
1455 | + return array.length() + n; | |
1456 | + } | |
1457 | + public double get(int index) { | |
1458 | + if (index < n) { | |
1459 | + return value; | |
1460 | + } else { | |
1461 | + return array.get(index - n); | |
1462 | + } | |
1463 | + } | |
1464 | + public void set(int index, double value) { | |
1465 | + if (index < n) { | |
1466 | + array = MathUtils.cloneArray(this); | |
1467 | + n = 0; | |
1468 | + array.set(index, value); | |
1469 | + } else { | |
1470 | + array.set(index - n, value); | |
1471 | + } | |
1472 | + } | |
1473 | + } | |
1474 | + | |
1311 | 1475 | } |
1312 | 1476 | |
1313 | 1477 |
@@ -6,7 +6,7 @@ | ||
6 | 6 | |
7 | 7 | public class ChordSymbol2 extends ChordSymbol implements Cloneable { |
8 | 8 | |
9 | - public static final ChordSymbol2 NONE_CHORD = | |
9 | + public static final ChordSymbol2 NON_CHORD = | |
10 | 10 | new ChordSymbol2(null, Mode.MAJ, Seventh.NONE); |
11 | 11 | |
12 | 12 | public static final ChordSymbol2 C = |
@@ -328,7 +328,7 @@ | ||
328 | 328 | public static ChordSymbol2 parse(String s, ParseRule r) { |
329 | 329 | String[] ss = s.trim().split("/"); |
330 | 330 | if (ss.length < 1) |
331 | - return NONE_CHORD; | |
331 | + return NON_CHORD; | |
332 | 332 | Matcher m1 = p1.matcher(ss[0]); |
333 | 333 | if (m1.matches()) { |
334 | 334 | NoteSymbol bass = null; |
@@ -18,17 +18,17 @@ | ||
18 | 18 | : e1.value1 - e2.value1 |
19 | 19 | ) : e1.ch - e2.ch |
20 | 20 | ) : e1.status - e2.status |
21 | - ) : e1.time - e2.time; | |
21 | + ) : (int)(e1.time - e2.time); | |
22 | 22 | } |
23 | 23 | }); |
24 | 24 | } |
25 | 25 | |
26 | - public void addEvent(int time, String msgname, byte ch, | |
26 | + public void addEvent(long time, String msgname, byte ch, | |
27 | 27 | int value1, int value2) { |
28 | 28 | s.add(new MIDIEvent(time, msgname, ch, value1, value2)); |
29 | 29 | } |
30 | 30 | |
31 | - public void addEvent(int time, short status, byte ch, | |
31 | + public void addEvent(long time, short status, byte ch, | |
32 | 32 | int value1, int value2) { |
33 | 33 | s.add(new MIDIEvent(time, status, ch, value1, value2)); |
34 | 34 | } |
@@ -38,11 +38,12 @@ | ||
38 | 38 | } |
39 | 39 | |
40 | 40 | public final class MIDIEvent { |
41 | - private int time, value1 = 0, value2 = 0; | |
41 | + private long time; | |
42 | + private int value1 = 0, value2 = 0; | |
42 | 43 | private short status; |
43 | 44 | private String msgname; |
44 | 45 | private byte ch; |
45 | - MIDIEvent(int time, short status, byte ch, int value1, int value2) { | |
46 | + MIDIEvent(long time, short status, byte ch, int value1, int value2) { | |
46 | 47 | this.time = time; |
47 | 48 | this.status = status; |
48 | 49 | this.value1 = value1; |
@@ -50,7 +51,7 @@ | ||
50 | 51 | this.msgname = statusNoToMsgName(status); |
51 | 52 | this.ch = ch; |
52 | 53 | } |
53 | - MIDIEvent(int time, String msgname, byte ch, int value1, int value2) { | |
54 | + MIDIEvent(long time, String msgname, byte ch, int value1, int value2) { | |
54 | 55 | this.time = time; |
55 | 56 | this.msgname = msgname; |
56 | 57 | this.value1 = value1; |
@@ -58,7 +59,7 @@ | ||
58 | 59 | this.status = msgNameToStatusNo(msgname); |
59 | 60 | this.ch = ch; |
60 | 61 | } |
61 | - public final int time() { | |
62 | + public final long time() { | |
62 | 63 | return time; |
63 | 64 | } |
64 | 65 | public final short status() { |
@@ -285,8 +285,8 @@ | ||
285 | 285 | // } |
286 | 286 | int I = compressedScore.size(); |
287 | 287 | int J = pfmNotes.length; |
288 | - int scoreTicks = compressedScore.get(I - 1).notes.get(0).offset(); | |
289 | - int pfmTicks = pfmNotes[J - 1].offset(); | |
288 | + long scoreTicks = compressedScore.get(I - 1).notes.get(0).offset(); | |
289 | + long pfmTicks = pfmNotes[J - 1].offset(); | |
290 | 290 | // r = Math.max(0, Math.max(J-I, r)); |
291 | 291 | r = J; |
292 | 292 | DTWMatrix matrix = new DTWMatrix(I, J); |
@@ -306,9 +306,9 @@ | ||
306 | 306 | // else ioi = 1.0 / diff; |
307 | 307 | // } |
308 | 308 | if (i > 0 && j > 0) { |
309 | - int scoreDiff = e1.notes.get(0).onset() | |
309 | + long scoreDiff = e1.notes.get(0).onset() | |
310 | 310 | - compressedScore.get(i - 1).notes.get(0).onset(); |
311 | - int pfmDiff = e2.onset() - pfmNotes[j - 1].onset(); | |
311 | + long pfmDiff = e2.onset() - pfmNotes[j-1].onset(); | |
312 | 312 | if (pfmDiff == 0) |
313 | 313 | ioi = Double.POSITIVE_INFINITY; |
314 | 314 | else |
@@ -337,7 +337,7 @@ | ||
337 | 337 | return matrix; |
338 | 338 | } |
339 | 339 | |
340 | - private double dist(NoteInSameTime e1, Note e2, int scoreTicks, int pfmTicks) { | |
340 | + private double dist(NoteInSameTime e1, Note e2, long scoreTicks, long pfmTicks) { | |
341 | 341 | double position = Math.abs((e1.notes.get(0).onset() / (double) scoreTicks - e2.onset() |
342 | 342 | / (double) pfmTicks)); |
343 | 343 | for (Note n : e1.notes) { |
@@ -450,13 +450,13 @@ | ||
450 | 450 | |
451 | 451 | private class TempoAndTime { |
452 | 452 | private double tempo = Double.NaN; |
453 | - private int tickInScore; | |
453 | + private long tickInScore; | |
454 | 454 | private double tickInPfm = Double.NaN; |
455 | 455 | private double timeInSec = Double.NaN; |
456 | 456 | private int measure = -1; |
457 | 457 | private int beat = -1; |
458 | 458 | |
459 | - private TempoAndTime(int tickInScore) { | |
459 | + private TempoAndTime(long tickInScore) { | |
460 | 460 | this.tickInScore = tickInScore; |
461 | 461 | } |
462 | 462 |
@@ -604,7 +604,7 @@ | ||
604 | 604 | } |
605 | 605 | |
606 | 606 | // kari; redundant calculation |
607 | - private double getSecFromScoreTick(int tick, List<TempoAndTime> tempolist) { | |
607 | + private double getSecFromScoreTick(long tick, List<TempoAndTime> tempolist) { | |
608 | 608 | TempoAndTime last = tempolist.get(0); |
609 | 609 | for (TempoAndTime tnt : tempolist) { |
610 | 610 | if (tick < tnt.tickInScore) |
@@ -616,7 +616,7 @@ | ||
616 | 616 | } |
617 | 617 | |
618 | 618 | // kari; redundant calculation |
619 | - private double getSecFromPfmTick(int tick, List<TempoAndTime> tempolist) { | |
619 | + private double getSecFromPfmTick(long tick, List<TempoAndTime> tempolist) { | |
620 | 620 | TempoAndTime last = tempolist.get(0); |
621 | 621 | for (TempoAndTime tnt : tempolist) { |
622 | 622 | if (tick < tnt.tickInPfm) |
@@ -705,7 +705,7 @@ | ||
705 | 705 | note.velocity() / BASE_DYNAMICS); |
706 | 706 | } |
707 | 707 | |
708 | - private boolean tickcmp(int tick1, int tick2, int threshold) { | |
708 | + private boolean tickcmp(long tick1, long tick2, int threshold) { | |
709 | 709 | return (tick1 >= tick2 - threshold && tick1 <= tick2 + threshold); |
710 | 710 | } |
711 | 711 |
@@ -723,7 +723,8 @@ | ||
723 | 723 | ArrayList<TempoAndTime> tempolist = new ArrayList<TempoAndTime>(); |
724 | 724 | tempolist.add(getZerothTempoAndTime()); |
725 | 725 | int i = 0; |
726 | - int measure = 0, beat = 1, currentTick = 0; | |
726 | + int measure = 0, beat = 1; | |
727 | + long currentTick = 0; | |
727 | 728 | for (int k = 0; k < barlines.length - 2; k++) { |
728 | 729 | Measure m = getMeasure(((Annotation)barlines[k]).onset()); |
729 | 730 | measure = m.number(); |
@@ -743,7 +744,7 @@ | ||
743 | 744 | // beat = 1; |
744 | 745 | i = addTempoAndTime(currentTick, measure, beat, i, tempolist); |
745 | 746 | |
746 | - int lastOffset = currentTick; | |
747 | + long lastOffset = currentTick; | |
747 | 748 | for (int ii = 0; ii < scoreNotes.length; ii++) |
748 | 749 | if (scoreNotes[ii].offset() > lastOffset) |
749 | 750 | lastOffset = scoreNotes[ii].offset(); |
@@ -770,7 +771,7 @@ | ||
770 | 771 | return a >= b ? a : b; |
771 | 772 | } |
772 | 773 | |
773 | - private int addTempoAndTime(int currentTick, int measure, int beat, int i, | |
774 | + private int addTempoAndTime(long currentTick, int measure, int beat, int i, | |
774 | 775 | ArrayList<TempoAndTime> tempolist) { |
775 | 776 | while (i < scoreNotes.length) { |
776 | 777 | if (score2pfm[i] == -1) { |
@@ -819,8 +820,8 @@ | ||
819 | 820 | |
820 | 821 | private int lastMeasureIndex = 0; |
821 | 822 | |
822 | - private Measure getMeasure(int tick) { | |
823 | - int tick0 = measurelist[lastMeasureIndex].cumulativeTicks(scoreTicksPerBeat); | |
823 | + private Measure getMeasure(long tick) { | |
824 | + long tick0 = measurelist[lastMeasureIndex].cumulativeTicks(scoreTicksPerBeat); | |
824 | 825 | if (tick0 == tick) { |
825 | 826 | return measurelist[lastMeasureIndex]; |
826 | 827 | } else if (tick0 > tick) { |
@@ -945,13 +946,13 @@ | ||
945 | 946 | TempoAndTime tnt = tempolist.get(i); |
946 | 947 | if (Double.isNaN(tnt.timeInSec)) { |
947 | 948 | prevtnt.tempo = prevTempo; |
948 | - int interval = tnt.tickInScore - prevtnt.tickInScore; | |
949 | + long interval = tnt.tickInScore - prevtnt.tickInScore; | |
949 | 950 | double pfmInterval = (double) (interval * 60 / scoreTicksPerBeat) |
950 | 951 | / prevTempo; |
951 | 952 | tnt.setTimeInSec(prevtnt.timeInSec + pfmInterval); |
952 | 953 | // tnt.setTimeInSec(prevtnt.timeInSec + 60.0 / prevTempo); |
953 | 954 | } else { |
954 | - int interval = tnt.tickInScore - prevtnt.tickInScore; | |
955 | + long interval = tnt.tickInScore - prevtnt.tickInScore; | |
955 | 956 | double pfmInterval = tnt.timeInSec - prevtnt.timeInSec; |
956 | 957 | // zantei |
957 | 958 | if (pfmInterval < 0.0000000001) { |
@@ -6,6 +6,7 @@ | ||
6 | 6 | public int getMeasureNum(); |
7 | 7 | public int getBeatNum(); |
8 | 8 | public int getFirstMeasure(); |
9 | + public void setFirstMeasure(int measure); | |
9 | 10 | public boolean isSelectable(); |
10 | 11 | public boolean isEditable(); |
11 | 12 | public void selectNote(int measure, double beat, int notenum); |
@@ -164,10 +164,10 @@ | ||
164 | 164 | for (SCC.Part p : parts) { |
165 | 165 | SCC.Note[] notes = p.getNoteOnlyList(); |
166 | 166 | for (SCC.Note note : notes) { |
167 | - int onsetIndex = note.onset(ticksPerBeat) * divisionPerMeasure / 4 | |
168 | - / ticksPerBeat; | |
169 | - int offsetIndex = note.offset(ticksPerBeat) * divisionPerMeasure / 4 | |
170 | - / ticksPerBeat; | |
167 | + int onsetIndex = (int)(note.onset(ticksPerBeat) * divisionPerMeasure / 4 | |
168 | + / ticksPerBeat); | |
169 | + int offsetIndex = (int)(note.offset(ticksPerBeat) * divisionPerMeasure / 4 | |
170 | + / ticksPerBeat); | |
171 | 171 | int notenum = note.notenum(); |
172 | 172 | ///// onsetがoffsetより長いなぞのパターン /////// |
173 | 173 | ///// とりあえず入れ替えておく /////// |
@@ -246,4 +246,4 @@ | ||
246 | 246 | * (byte)(127 * (offset - n) / (offset - onset))); } }); return tfr; } |
247 | 247 | */ |
248 | 248 | |
249 | -} | |
\ No newline at end of file | ||
249 | +} |
@@ -193,6 +193,10 @@ | ||
193 | 193 | ctrl.setMicrosecondPosition(t); |
194 | 194 | } |
195 | 195 | |
196 | + public void setTickPosition(long tick) { | |
197 | + ctrl.setTickPosition(tick); | |
198 | + } | |
199 | + | |
196 | 200 | /** 現在の再生中の音楽データにおける現在の再生箇所をティック単位で |
197 | 201 | 返します. |
198 | 202 | ただし,このメソッドは読み込み済みのデータがMIDIデータのときしか |
@@ -441,7 +445,8 @@ | ||
441 | 445 | } |
442 | 446 | |
443 | 447 | private void autostart() { |
444 | - if (autostart) { | |
448 | + if (autostart) { | |
449 | + // setupExternalMessages(); | |
445 | 450 | println("SPExector automatically started."); |
446 | 451 | ctrl.startSP(); |
447 | 452 | } |
@@ -451,6 +456,19 @@ | ||
451 | 456 | // ctrl.stopSP(); |
452 | 457 | // } |
453 | 458 | |
459 | + public void setup() { | |
460 | + setupExternalMessages(); | |
461 | + } | |
462 | + | |
463 | + public void draw() { | |
464 | + // do nothing | |
465 | + } | |
466 | + | |
467 | + public void exit() { | |
468 | + stop(); | |
469 | + super.exit(); | |
470 | + } | |
471 | + | |
454 | 472 | public void stop() { |
455 | 473 | super.stop(); |
456 | 474 | println("SPExecutor automatically stopped."); |
@@ -23,29 +23,8 @@ | ||
23 | 23 | |
24 | 24 | import javazoom.jl.decoder.BitstreamException; |
25 | 25 | import javazoom.jl.decoder.DecoderException; |
26 | -import jp.crestmuse.cmx.amusaj.sp.AmusaParameterSet; | |
27 | -import jp.crestmuse.cmx.amusaj.sp.MidiEventSender; | |
28 | -import jp.crestmuse.cmx.amusaj.sp.MidiEventWithTicktime; | |
29 | -import jp.crestmuse.cmx.amusaj.sp.MidiInputModule; | |
30 | -import jp.crestmuse.cmx.amusaj.sp.MidiOutputModule; | |
31 | -import jp.crestmuse.cmx.amusaj.sp.ProducerConsumerCompatible; | |
32 | -import jp.crestmuse.cmx.amusaj.sp.SPExecutor; | |
33 | -import jp.crestmuse.cmx.amusaj.sp.SPModule; | |
34 | -import jp.crestmuse.cmx.amusaj.sp.STFT; | |
35 | -import jp.crestmuse.cmx.amusaj.sp.SynchronizedWindowSlider; | |
36 | -import jp.crestmuse.cmx.amusaj.sp.TappingModule; | |
37 | -import jp.crestmuse.cmx.amusaj.sp.TimeSeriesCompatible; | |
38 | -import jp.crestmuse.cmx.amusaj.sp.TrashOutModule; | |
39 | -import jp.crestmuse.cmx.amusaj.sp.WindowSlider; | |
40 | -import jp.crestmuse.cmx.filewrappers.CMXFileWrapper; | |
41 | -import jp.crestmuse.cmx.filewrappers.ConfigXMLWrapper; | |
42 | -import jp.crestmuse.cmx.filewrappers.InvalidFileTypeException; | |
43 | -import jp.crestmuse.cmx.filewrappers.MIDIXMLWrapper; | |
44 | -import jp.crestmuse.cmx.filewrappers.MP3Wrapper; | |
45 | -import jp.crestmuse.cmx.filewrappers.SCCXMLWrapper; | |
46 | -import jp.crestmuse.cmx.filewrappers.WAVWrapper; | |
26 | +import jp.crestmuse.cmx.amusaj.sp.*; | |
47 | 27 | import jp.crestmuse.cmx.filewrappers.*; |
48 | -import jp.crestmuse.cmx.filewrappers.XMLException; | |
49 | 28 | import jp.crestmuse.cmx.inference.MusicRepresentation; |
50 | 29 | import jp.crestmuse.cmx.inference.MusicRepresentationFactory; |
51 | 30 | import jp.crestmuse.cmx.math.ComplexArray; |
@@ -91,6 +70,8 @@ | ||
91 | 70 | private MidiDevice.Info[] midiouts = new MidiDevice.Info[256]; |
92 | 71 | private Mixer.Info mixer = null; |
93 | 72 | |
73 | + private long startTime; | |
74 | + | |
94 | 75 | private CMXController() { |
95 | 76 | |
96 | 77 | } |
@@ -427,6 +408,7 @@ | ||
427 | 408 | mic.getLine().start(); |
428 | 409 | if (spexec != null) |
429 | 410 | spexec.start(); |
411 | + startTime = System.nanoTime() / 1000; | |
430 | 412 | } |
431 | 413 | |
432 | 414 | public void stopSP() { |
@@ -861,10 +843,10 @@ | ||
861 | 843 | * 現在の再生中の音楽データにおける現在の再生箇所をマイクロ秒単位で 返します. |
862 | 844 | */ |
863 | 845 | public long getMicrosecondPosition(int i) { |
864 | - if (musicPlayer[i] == null) | |
865 | - return 0; | |
866 | - else | |
867 | - return musicPlayer[i].getMicrosecondPosition(); | |
846 | + if (musicPlayer[i] == null) | |
847 | + return System.nanoTime() / 1000 - startTime; | |
848 | + else | |
849 | + return musicPlayer[i].getMicrosecondPosition(); | |
868 | 850 | } |
869 | 851 | |
870 | 852 | public long getMicrosecondLength() { |
@@ -900,10 +882,10 @@ | ||
900 | 882 | * 使用できません. |
901 | 883 | */ |
902 | 884 | public long getTickPosition(int i) { |
903 | - if (musicPlayer[i] == null) | |
904 | - return 0; | |
905 | - else | |
906 | - return musicPlayer[i].getTickPosition(); | |
885 | + if (musicPlayer[i] == null) | |
886 | + return getMicrosecondPosition(i) * getTicksPerBeat(i) / 1000 / 500; | |
887 | + else | |
888 | + return musicPlayer[i].getTickPosition(); | |
907 | 889 | } |
908 | 890 | |
909 | 891 | public int getTicksPerBeat() { |
@@ -916,7 +898,7 @@ | ||
916 | 898 | */ |
917 | 899 | public int getTicksPerBeat(int i) { |
918 | 900 | if (musicPlayer[i] == null) |
919 | - return 0; | |
901 | + return 480; | |
920 | 902 | else |
921 | 903 | return musicPlayer[i].getTicksPerBeat(); |
922 | 904 | } |
@@ -1374,6 +1356,13 @@ | ||
1374 | 1356 | return evtsender; |
1375 | 1357 | } |
1376 | 1358 | |
1359 | + public MidiRecorder2 createMidiRecorder() { | |
1360 | + MidiRecorder2 rec = new MidiRecorder2(this); | |
1361 | + rec.setTempo(120.0); // kari | |
1362 | + addSPModule(rec); | |
1363 | + return rec; | |
1364 | + } | |
1365 | + | |
1377 | 1366 | /** |
1378 | 1367 | * 音響信号処理に関する各種パラメータや設定を記述してConfigXMLファイルを読み込みます. <tt>createMic</tt> |
1379 | 1368 | * などを使用する際には必須です. |
@@ -3,4 +3,5 @@ | ||
3 | 3 | public interface TickTimer { |
4 | 4 | public int getTicksPerBeat(); |
5 | 5 | public long getTickPosition(); |
6 | + /* public double getTempo(); */ | |
6 | 7 | } |