• R/O
  • SSH
  • HTTPS

cmx: コミット


コミットメタ情報

リビジョン843 (tree)
日時2016-12-19 18:28:30
作者kitahara

ログメッセージ

changed the type of onset and offset times to long, and so on

変更サマリ

差分

--- trunk/build.sh (revision 842)
+++ trunk/build.sh (revision 843)
@@ -41,6 +41,6 @@
4141 else
4242 mkdir doc
4343 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
4545
4646 ( cd ../ ; if [ -e ${release}.zip ] ; then rm ${release}.zip ; fi ; zip -r ${release}.zip $release )
--- trunk/src/jp/crestmuse/cmx/amusaj/commands/SCC2WAV.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/amusaj/commands/SCC2WAV.java (revision 843)
@@ -168,8 +168,8 @@
168168 scc.processNotes(new SCCHandlerAdapter() {
169169 public void processNote(SCCXMLWrapper.Note note,
170170 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);
173173 AudioDataCompatible w = readWaveform(note.part().prognum(),
174174 note.notenum(), sty, var);
175175 if (w == null && sty2 != null)
@@ -362,4 +362,4 @@
362362 return S;
363363 }
364364
365-}
\ No newline at end of file
365+}
--- trunk/src/jp/crestmuse/cmx/amusaj/sp/WindowSlider.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/amusaj/sp/WindowSlider.java (revision 843)
@@ -57,11 +57,11 @@
5757
5858 /** "from" and "thru" in milli sec. */
5959 public void setInputData(AudioDataCompatible audiodata,
60- int from, int thru) {
60+ long from, long thru) {
6161 long fs = audiodata.sampleRate();
6262 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)));
6565 }
6666
6767 public AudioDataCompatible getTargetWaveform() {
--- trunk/src/jp/crestmuse/cmx/commands/SMFConcat.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/commands/SMFConcat.java (revision 843)
@@ -36,7 +36,7 @@
3636 public void endPart(SCCXMLWrapper.Part part, SCCXMLWrapper w) {
3737 outdata.endPart();
3838 }
39- public void processHeaderElement(int timestamp, java.lang.String name,
39+ public void processHeaderElement(long timestamp, java.lang.String name,
4040 java.lang.String content, SCCXMLWrapper w){
4141 outdata2.addHeaderElement(timestamp - t0 + t1,
4242 name, content);
@@ -61,7 +61,7 @@
6161 public void endPart(SCCXMLWrapper.Part part, SCCXMLWrapper w) {
6262 outdata2.endPart();
6363 }
64- public void processHeaderElement(int timestamp, String name,
64+ public void processHeaderElement(long timestamp, String name,
6565 String content, SCCXMLWrapper w){}
6666 public void processNote(SCCXMLWrapper.Note note, SCCXMLWrapper w) {
6767 outdata2.addNoteElement(note.onset(), note.offset(),
@@ -81,4 +81,4 @@
8181 System.exit(1);
8282 }
8383 }
84-}
\ No newline at end of file
84+}
--- trunk/src/jp/crestmuse/cmx/elements/BaseDynamicsEvent.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/elements/BaseDynamicsEvent.java (revision 843)
@@ -4,7 +4,7 @@
44
55 private double value;
66
7- public BaseDynamicsEvent(int timeStamp, double value, int ticksPerBeat){
7+ public BaseDynamicsEvent(long timeStamp, double value, int ticksPerBeat){
88 // public BaseDynamicsEvent(int timeStamp, int ticksPerBeat, double value){
99 super(Type.CONTROL_CHANGE, timeStamp, timeStamp, ticksPerBeat);
1010 this.value = value;
--- trunk/src/jp/crestmuse/cmx/elements/MutableAnnotation.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/elements/MutableAnnotation.java (revision 843)
@@ -6,7 +6,7 @@
66 private String content;
77 private String name;
88
9- public MutableAnnotation(int onset, int offset, String type, String content,
9+ public MutableAnnotation(long onset, long offset, String type, String content,
1010 int ticksPerBeat) {
1111 super(Type.ANNOTATION, onset, offset, ticksPerBeat);
1212 this.content = content;
--- trunk/src/jp/crestmuse/cmx/elements/MutableControlChange.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/elements/MutableControlChange.java (revision 843)
@@ -1,7 +1,7 @@
11 package jp.crestmuse.cmx.elements;
22
33 public class MutableControlChange extends MutableMusicEvent {
4- public MutableControlChange(int timestamp, int ctrlnum, int value,
4+ public MutableControlChange(long timestamp, int ctrlnum, int value,
55 int ticksPerBeat) {
66 super(Type.CONTROL_CHANGE, timestamp, timestamp, ticksPerBeat);
77 value1 = ctrlnum;
@@ -19,4 +19,4 @@
1919 public int value() {
2020 return value2;
2121 }
22-}
\ No newline at end of file
22+}
--- trunk/src/jp/crestmuse/cmx/elements/MutableMusicEvent.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/elements/MutableMusicEvent.java (revision 843)
@@ -4,9 +4,11 @@
44 import javax.sound.midi.*;
55
66 public abstract class MutableMusicEvent
7- implements Comparable<MutableMusicEvent>, NoteCompatible {
7+ implements Comparable<MutableMusicEvent>, SCC.Note {
88
9- int onset, offset, value1, value2, value3;
9+ long onset, offset;
10+ int value1, value2, value3;
11+ long onsetInMSec = -1, offsetInMSec = -1;
1012 int ticksPerBeat;
1113 Type type;
1214 enum Type {NOTE, CONTROL_CHANGE, PROGRAM_CHANGE, PITCH_BEND, ANNOTATION};
@@ -16,7 +18,7 @@
1618 Map<String,String> attr = new TreeMap<String,String>();
1719
1820
19- MutableMusicEvent(Type type, int onset, int offset, int ticksPerBeat) {
21+ MutableMusicEvent(Type type, long onset, long offset, int ticksPerBeat) {
2022 this.type = type;
2123 this.onset = onset;
2224 this.offset = offset;
@@ -24,19 +26,33 @@
2426 this.ticksPerBeat = ticksPerBeat;
2527 }
2628
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+ }
2836 this.onset = onset;
37+ onsetInMSec = -1;
2938 }
3039
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+ }
3247 this.offset = offset;
48+ offsetInMSec = -1;
3349 }
3450
35- public int onset() {
51+ public long onset() {
3652 return onset;
3753 }
3854
39- public int onset(int ticksPerBeat) {
55+ public long onset(int ticksPerBeat) {
4056 if (ticksPerBeat == this.ticksPerBeat)
4157 return onset;
4258 else
@@ -43,30 +59,40 @@
4359 return onset * ticksPerBeat / this.ticksPerBeat;
4460 }
4561
46- /**@deprecated*/
47- public int onsetInMSec() {
48- throw new UnsupportedOperationException();
49- }
62+ // /**@deprecated*/
63+ // public int onsetInMSec() {
64+ // throw new UnsupportedOperationException();
65+ // }
5066
5167
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;
5473 }
5574
56- public int offset() {
75+ public long offset() {
5776 return offset;
5877 }
5978
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;
6284 }
6385
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();
6793 }
68-
69- public int offset(int ticksPerBeat) {
94+
95+ public long offset(int ticksPerBeat) {
7096 if (ticksPerBeat == this.ticksPerBeat)
7197 return offset;
7298 else
@@ -73,7 +99,7 @@
7399 return offset * ticksPerBeat / this.ticksPerBeat;
74100 }
75101
76- public int duration(int ticksPerBeat) {
102+ public long duration(int ticksPerBeat) {
77103 return offset(ticksPerBeat) - onset(ticksPerBeat);
78104 }
79105
@@ -90,7 +116,7 @@
90116 }
91117
92118 public int hashCode() {
93- return onset + offset + value1 + value2 + value3;
119+ return (int)(onset + offset + value1 + value2 + value3);
94120 }
95121
96122 public int compareTo(MutableMusicEvent another) {
@@ -102,8 +128,8 @@
102128 value3 - another.value3 : value2 - another.value2)
103129 : value1 - another.value1)
104130 : type.ordinal() - another.type.ordinal())
105- : offset - another.offset)
106- : onset - another.onset;
131+ : (int)(offset - another.offset))
132+ : (int)(onset - another.onset);
107133 }
108134
109135 public int velocity() {
@@ -189,6 +215,17 @@
189215 public MidiEvent getMidiEvent2() {
190216 return midievt2;
191217 }
192-
193218
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+
194231 }
--- trunk/src/jp/crestmuse/cmx/elements/MutableNote.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/elements/MutableNote.java (revision 843)
@@ -1,16 +1,17 @@
11 package jp.crestmuse.cmx.elements;
22 import java.util.*;
3+import javax.sound.midi.*;
34
4-public class MutableNote extends MutableMusicEvent
5- implements NoteCompatible {
5+public class MutableNote extends MutableMusicEvent {
66
7+
78 // private String word = null;
89
9- public MutableNote(int onset, int offset, int notenum, int velocity,
10+ public MutableNote(long onset, long offset, int notenum, int velocity,
1011 int ticksPerBeat) {
1112 this(onset, offset, notenum, velocity, velocity, ticksPerBeat);
1213 }
13- public MutableNote(int onset, int offset, int notenum, int velocity,
14+ public MutableNote(long onset, long offset, int notenum, int velocity,
1415 int offVelocity, int ticksPerBeat) {
1516 super(Type.NOTE, onset, offset, ticksPerBeat);
1617 value1 = notenum;
@@ -17,7 +18,7 @@
1718 value2 = velocity;
1819 value3 = offVelocity;
1920 }
20- public MutableNote(int onset, int offset, int notenum, int velocity,
21+ public MutableNote(long onset, long offset, int notenum, int velocity,
2122 int offVelocity, int ticksPerBeat,
2223 Map<String,String> attr) {
2324 this(onset, offset, notenum, velocity, offVelocity, ticksPerBeat);
@@ -34,25 +35,60 @@
3435 setAttribute("word", word);
3536 }*/
3637
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+ }
3755
3856 public void setNoteNum(int notenum) {
3957 value1 = notenum;
58+ if (midievt1 != null) {
59+ changeData(notenum, -1, midievt1);
60+ }
61+ if (midievt2 != null) {
62+ changeData(notenum, -1, midievt2);
63+ }
4064 }
65+
4166 public int notenum() {
4267 return value1;
4368 }
69+
4470 public void setVelocity(int vel) {
4571 value2 = vel;
72+ if (midievt1 != null) {
73+ changeData(-1, vel, midievt1);
74+ }
4675 }
76+
4777 public int velocity() {
4878 return value2;
4979 }
80+
5081 public void setOffVelocity(int offvel) {
5182 value3 = offvel;
83+ if (midievt2 != null) {
84+ changeData(-1, offvel, midievt2);
85+ }
5286 }
87+
5388 public int offVelocity() {
5489 return value3;
5590 }
91+
5692 // /** @deprecated */
5793 // public String word() {
5894 // return getAttribute("word");
@@ -61,6 +97,7 @@
6197 // public void setWord(String w) {
6298 // setAttribute("word", w);
6399 // }
100+
64101 public String toString() {
65102 return "[onset: " + onset() + ", offset: " + offset() +
66103 ", notenum: " + notenum() + ", velocity: " + velocity() +
--- trunk/src/jp/crestmuse/cmx/elements/MutablePitchBend.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/elements/MutablePitchBend.java (revision 843)
@@ -1,7 +1,7 @@
11 package jp.crestmuse.cmx.elements;
22
33 public class MutablePitchBend extends MutableMusicEvent {
4- public MutablePitchBend(int timestamp, int value, int ticksPerBeat) {
4+ public MutablePitchBend(long timestamp, int value, int ticksPerBeat) {
55 super(Type.PITCH_BEND, timestamp, timestamp, ticksPerBeat);
66 value1 = value;
77 }
@@ -11,4 +11,4 @@
1111 public int value() {
1212 return value1;
1313 }
14-}
\ No newline at end of file
14+}
--- trunk/src/jp/crestmuse/cmx/elements/MutableProgramChange.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/elements/MutableProgramChange.java (revision 843)
@@ -1,7 +1,7 @@
11 package jp.crestmuse.cmx.elements;
22
33 public class MutableProgramChange extends MutableMusicEvent {
4- public MutableProgramChange(int timestamp, int value,
4+ public MutableProgramChange(long timestamp, int value,
55 int ticksPerBeat) {
66 super(Type.PROGRAM_CHANGE, timestamp, timestamp, ticksPerBeat);
77 value1 = value;
@@ -12,4 +12,4 @@
1212 public int value() {
1313 return value1;
1414 }
15-}
\ No newline at end of file
15+}
--- trunk/src/jp/crestmuse/cmx/elements/NoteCompatible.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/elements/NoteCompatible.java (revision 843)
@@ -1,6 +1,8 @@
11 package jp.crestmuse.cmx.elements;
22 import jp.crestmuse.cmx.filewrappers.*;
33
4+/*
45 @Deprecated
56 public interface NoteCompatible extends SCC.Note {
67 }
8+*/
--- trunk/src/jp/crestmuse/cmx/filewrappers/CMXFileWrapper.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/filewrappers/CMXFileWrapper.java (revision 843)
@@ -896,6 +896,10 @@
896896 setAttribute(name, String.valueOf(value));
897897 }
898898
899+ public final void setAttribute(String name, long value) {
900+ setAttribute(name, String.valueOf(value));
901+ }
902+
899903 /**********************************************************************
900904 *<p>Adds an attribute to the current node.
901905 *The current node should be an element node.</p>
--- trunk/src/jp/crestmuse/cmx/filewrappers/DeviationInstanceWrapper.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/filewrappers/DeviationInstanceWrapper.java (revision 843)
@@ -1151,10 +1151,10 @@
11511151 HeaderElement[] headers = scc.getHeaderElementList();
11521152 for (int i = 0; i < headers.length; i++) {
11531153 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);
11551155 int to;
11561156 if (i < headers.length - 1) {
1157- to = headers[i + 1].time() * divisionPerMeasure / 4 / ticksPerBeat;
1157+ to = (int)(headers[i + 1].time() * divisionPerMeasure / 4 / ticksPerBeat);
11581158 } else {
11591159 to = tempos.length - 1;
11601160 }
--- trunk/src/jp/crestmuse/cmx/filewrappers/MIDIXMLWrapper.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/filewrappers/MIDIXMLWrapper.java (revision 843)
@@ -97,10 +97,10 @@
9797 }
9898
9999 public void addMIDIChannelMessages(MIDIEventList el) {
100- int currentTime = 0;
100+ long currentTime = 0;
101101 for (MIDIEventList.MIDIEvent e : el) {
102102 addMIDIChannelMessage(e.msgname(),
103- e.time() - currentTime,
103+ (int)(e.time() - currentTime),
104104 e.channel(),
105105 e.value1(),
106106 e.value2());
@@ -592,7 +592,7 @@
592592 final SCCDataSet scc = new SCCDataSet(ticksPerBeat);
593593 final SCCDataSet.Part[] parts = new SCCDataSet.Part[17]; // 要検討
594594 processMIDIEvent(new MIDIHandler() {
595- private int totalTime;
595+ private long totalTime;
596596 int partSerial = 0;
597597 private MutableNote[] onNotes;
598598 public void beginTrack(Track track, MIDIXMLWrapper w) {
@@ -693,11 +693,14 @@
693693 // return dest;
694694 }
695695
696+ /*
696697 @Deprecated
697698 public void toSCCXML(final SCCXMLWrapper dest) throws TransformerException, IOException, ParserConfigurationException, SAXException{
698699 toSCCXML(dest, null);
699700 }
701+ */
700702
703+ /*
701704 @Deprecated
702705 public void toSCCXML(final SCCXMLWrapper dest, SCCXMLWrapper.EasyChord[] chords)
703706 throws TransformerException, IOException,
@@ -704,6 +707,7 @@
704707 ParserConfigurationException, SAXException {
705708 toSCCXML(dest, chords, null);
706709 }
710+ */
707711
708712 private class Header {
709713 int time;
@@ -716,6 +720,7 @@
716720 }
717721 }
718722
723+ /*
719724 @Deprecated
720725 public void toSCCXML(final SCCXMLWrapper dest,
721726 SCCXMLWrapper.EasyChord[] chords, String key)
@@ -777,6 +782,11 @@
777782 new MutableControlChange(totalTime, midiEvent.value(0),
778783 midiEvent.value(1), ticksPerBeat());
779784 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);
780790 } else if (statusNo == PITCH_BEND_CHANGE) {
781791 MutablePitchBend c =
782792 new MutablePitchBend(totalTime,
@@ -784,7 +794,7 @@
784794 // midiEvent.value(0)+128*midiEvent.value(1),
785795 ticksPerBeat());
786796 addControlChange(c, midiEvent, channelToNotes);
787- }
797+ }
788798 }
789799 private void addControlChange(MutableMusicEvent c,
790800 MIDIEvent e,
@@ -904,7 +914,8 @@
904914
905915 dest.finalizeDocument();
906916 }
907-
917+ */
918+
908919 /*
909920 private class MyControlChange extends MutableNote {
910921 private MyControlChange(int time, int ctrlnum, int value) {
--- trunk/src/jp/crestmuse/cmx/filewrappers/NodeInterface.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/filewrappers/NodeInterface.java (revision 843)
@@ -165,6 +165,10 @@
165165 return Integer.parseInt(getAttribute(key));
166166 }
167167
168+ public long getAttributeLong(String key) {
169+ return Long.parseLong(getAttribute(key));
170+ }
171+
168172 public double getAttributeDouble(String key) {
169173 return Double.parseDouble(getAttribute(key));
170174 }
@@ -316,6 +320,10 @@
316320 return Integer.parseInt(getAttribute(node, attrkey));
317321 }
318322
323+ protected static final long getAttributeLong(Node node, String attrkey) {
324+ return Long.parseLong(getAttribute(node, attrkey));
325+ }
326+
319327 protected static final double getAttributeDouble(Node node, String attrkey) {
320328 return Double.parseDouble(getAttribute(node, attrkey));
321329 }
@@ -329,4 +337,4 @@
329337 // }
330338
331339
332-}
\ No newline at end of file
340+}
--- trunk/src/jp/crestmuse/cmx/filewrappers/SCC.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/filewrappers/SCC.java (revision 843)
@@ -30,7 +30,7 @@
3030 public interface HeaderElement extends Comparable<HeaderElement> {
3131 String content();
3232 String name();
33- int time();
33+ long time();
3434 }
3535
3636 public interface Part {
@@ -48,11 +48,12 @@
4848 }
4949
5050 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();
5657 int notenum();
5758 int velocity();
5859 int offVelocity();
@@ -67,8 +68,8 @@
6768 }
6869
6970 public interface Annotation {
70- int onset(int ticksPerBeat);
71- int offset(int ticksPerBeat);
71+ long onset(int ticksPerBeat);
72+ long offset(int ticksPerBeat);
7273 String type();
7374 String content();
7475 }
--- trunk/src/jp/crestmuse/cmx/filewrappers/SCCDataSet.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/filewrappers/SCCDataSet.java (revision 843)
@@ -16,8 +16,8 @@
1616 public class HeaderElement implements SCC.HeaderElement {
1717 String content;
1818 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) {
2121 this.time = time;
2222 this.name = name;
2323 this.content = content;
@@ -28,7 +28,7 @@
2828 public String name() {
2929 return name;
3030 }
31- public int time() {
31+ public long time() {
3232 return time;
3333 }
3434 public boolean equals(SCC.HeaderElement e) {
@@ -37,7 +37,7 @@
3737 }
3838 public int compareTo(SCC.HeaderElement e) {
3939 if (time != e.time())
40- return time - e.time();
40+ return (int)(time - e.time());
4141 else if (!name.equals(e.name()))
4242 return name.compareTo(e.name());
4343 else if (!content.equals(e.content()))
@@ -52,7 +52,8 @@
5252 }
5353
5454 public class Part implements SCC.Part {
55- private List<MutableMusicEvent> notes;
55+ // private List<MutableMusicEvent> notes;
56+ private SortedSet<MutableMusicEvent> notes;
5657 //private List<MutableMusicEvent> notes = new ArrayList<MutableMusicEvent>();
5758 private Map<MutableMusicEvent,MyNumber> nOverlaps =
5859 new HashMap<MutableMusicEvent,MyNumber>();
@@ -63,7 +64,9 @@
6364
6465 private Part(int serial, byte ch, int pn, int vol, String name,
6566 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>();
6770 this.serial = serial;
6871 channel = ch;
6972 prognum = pn;
@@ -79,7 +82,7 @@
7982 note.setAttribute("number", nOverlaps.get(note).value);
8083 }
8184
82- public void remove(MutableMusicEvent e) {
85+ public synchronized void remove(MutableMusicEvent e) {
8386 boolean result = notes.remove(e);
8487 if (tracks != null) {
8588 if (e.getMidiEvent1() != null) {
@@ -98,15 +101,16 @@
98101 remove(e);
99102 }
100103
101- void add(MutableMusicEvent e) {
104+ synchronized void add(MutableMusicEvent e) {
102105 notes.add(e);
103106 }
104107
105108
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) {
110114 MutableNote note = new MutableNote(onset, offset, notenum, velocity,
111115 offVelocity, division, attr);
112116 notes.add(note);
@@ -125,7 +129,7 @@
125129 return note;
126130 }
127131
128- MutableNote addNoteElement(int onset, int offset, int notenum,
132+ MutableNote addNoteElement(long onset, long offset, int notenum,
129133 int velocity, int offVelocity,
130134 MusicXMLWrapper.MusicData md) {
131135 return addNoteElement(onset, offset, notenum, velocity, offVelocity,
@@ -133,13 +137,13 @@
133137 }
134138
135139
136- public MutableNote addNoteElement(int onset, int offset, int notenum,
140+ public MutableNote addNoteElement(long onset, long offset, int notenum,
137141 int velocity, int offVelocity) {
138142 return addNoteElement(onset, offset, notenum, velocity, offVelocity,
139143 null, null);
140144 }
141145
142- public MutableNote addNoteElement(int onset, int offset, int notenum,
146+ public MutableNote addNoteElement(long onset, long offset, int notenum,
143147 int velocity, int offVelocity,
144148 Map<String,String> attr) {
145149 return addNoteElement(onset, offset, notenum, velocity,
@@ -165,7 +169,7 @@
165169 }
166170 */
167171
168- public MutableControlChange addControlChange(int time, int ctrl, int value) {
172+ public synchronized MutableControlChange addControlChange(long time, int ctrl, int value) {
169173 MutableControlChange cc = new MutableControlChange(time, ctrl, value, division);
170174 notes.add(cc);
171175 checkOverlap(cc);
@@ -177,7 +181,7 @@
177181 return cc;
178182 }
179183
180- public MutableProgramChange addProgramChange(int time, int value) {
184+ public synchronized MutableProgramChange addProgramChange(long time, int value) {
181185 MutableProgramChange pc = new MutableProgramChange(time, value, division);
182186 notes.add(pc);
183187 checkOverlap(pc);
@@ -189,7 +193,7 @@
189193 return pc;
190194 }
191195
192- public MutablePitchBend addPitchBend(int time, int value) {
196+ public synchronized MutablePitchBend addPitchBend(long time, int value) {
193197 MutablePitchBend pb = new MutablePitchBend(time, value, division);
194198 notes.add(pb);
195199 checkOverlap(pb);
@@ -198,7 +202,7 @@
198202 return pb;
199203 }
200204
201- BaseDynamicsEvent addBaseDynamics(int time, double value) {
205+ synchronized BaseDynamicsEvent addBaseDynamics(long time, double value) {
202206 BaseDynamicsEvent e = new BaseDynamicsEvent(time, value, division);
203207 notes.add(e);
204208 return e;
@@ -217,32 +221,35 @@
217221 }
218222 */
219223
220- public MutableMusicEvent[] getNoteList() {
224+ public synchronized MutableMusicEvent[] getNoteList() {
221225 return notes.toArray(new MutableMusicEvent[notes.size()]);
222226 }
223227
224- public MutableNote[] getNoteOnlyList() {
228+ public synchronized MutableNote[] getNoteOnlyList() {
225229 List<MutableNote> l = new ArrayList<MutableNote>();
226230 for (MutableMusicEvent e : notes) {
227231 if (e instanceof MutableNote)
228232 l.add((MutableNote)e);
229233 }
230- return l.toArray(new MutableNote[l.size()]);
234+ return l.toArray(new MutableNote[l.size()]);
231235 }
232236
233237 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;
237242 }
238243
239244 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;
243249 }
244250
245- public List<MutableMusicEvent> getNotesBetween1(int from, int thru) {
251+ /*
252+ public synchronized List<MutableMusicEvent> getNotesBetween1(int from, int thru) {
246253 List<MutableMusicEvent> notes2 = new ArrayList<MutableMusicEvent>();
247254 for (MutableMusicEvent e : notes) {
248255 if (e.onset() >= from && e.offset() <= thru)
@@ -251,7 +258,7 @@
251258 return notes2;
252259 }
253260
254- public List<MutableMusicEvent> getNotesBetween2(int from, int thru) {
261+ public synchronized List<MutableMusicEvent> getNotesBetween2(int from, int thru) {
255262 List<MutableMusicEvent> notes2 = new ArrayList<MutableMusicEvent>();
256263 for (MutableMusicEvent e : notes) {
257264 if (e.onset() >= from && e.onset() < thru)
@@ -259,7 +266,63 @@
259266 }
260267 return notes2;
261268 }
269+ */
262270
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+
263326 public int serial() {
264327 return serial;
265328 }
@@ -268,7 +331,7 @@
268331 return channel;
269332 }
270333
271- public int prognum() {
334+ public synchronized int prognum() {
272335 Note[] notes = getNoteList();
273336 for (int i = 0; i < notes.length; i++) {
274337 if (notes[i] instanceof MutableProgramChange) {
@@ -278,7 +341,7 @@
278341 return prognum;
279342 }
280343
281- private int getFirstControlChange(int ctrlnum, int defaultvalue) {
344+ private synchronized int getFirstControlChange(int ctrlnum, int defaultvalue) {
282345 Note[] notes = getNoteList();
283346 for (int i = 0; i < notes.length; i++) {
284347 if (notes[i] instanceof MutableControlChange) {
@@ -328,6 +391,10 @@
328391 public int getFirstMeasure() {
329392 return fromMeasure;
330393 }
394+ public void setFirstMeasure(int measure) {
395+ thruMeasure = measure + (thruMeasure - fromMeasure);
396+ fromMeasure = measure;
397+ }
331398 public boolean isSelectable() {
332399 return false;
333400 }
@@ -342,10 +409,10 @@
342409 public void drawData(PianoRoll pianoroll) {
343410 MutableNote[] notes = getNoteOnlyList();
344411 for (MutableNote note : notes) {
345- int onset = note.onset();
412+ long onset = note.onset();
346413 if (onset >= fromMeasure * getBeatNum() * division &&
347414 onset < thruMeasure * getBeatNum() * division) {
348- int measure = onset / division / getBeatNum();
415+ int measure = (int)(onset / division / getBeatNum());
349416 double beat = (double)onset / division - measure * getBeatNum();
350417 double duration = (double)(note.offset() - onset) / division;
351418 pianoroll.drawNote(measure - fromMeasure, beat, duration,
@@ -380,41 +447,41 @@
380447 this.division = division;
381448 }
382449
383- public void addAnnotation(String type, int onset, int offset, String content) {
450+ public void addAnnotation(String type, long onset, long offset, String content) {
384451 annotations.add(new MutableAnnotation(onset, offset, type, content,
385452 division));
386453 }
387454
388- public void addBarline(int time, String details) {
455+ public void addBarline(long time, String details) {
389456 addAnnotation("barline", time, time, details);
390457 }
391458
392- public void addChord(int onset, int offset, String content) {
459+ public void addChord(long onset, long offset, String content) {
393460 addAnnotation("chord", onset, offset, content);
394461 }
395462
396463 // 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) {
398465 addAnnotation("lyric", onset, offset, content);
399466 }
400467
401- public void addCuePoint(int onset, int offset, String content) {
468+ public void addCuePoint(long onset, long offset, String content) {
402469 addAnnotation("cue", onset, offset, content);
403470 }
404471
405- public void addMarker(int onset, int offset, String content) {
472+ public void addMarker(long onset, long offset, String content) {
406473 addAnnotation("marker", onset, offset, content);
407474 }
408475
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) {
410477 headers.add(new HeaderElement(time, name, content));
411478 }
412479
413- public void addHeaderElement(int time, String name, int content) {
480+ public void addHeaderElement(long time, String name, int content) {
414481 addHeaderElement(time, name, String.valueOf(content));
415482 }
416483
417- public void addHeaderElement(int time, String name, double content) {
484+ public void addHeaderElement(long time, String name, double content) {
418485 addHeaderElement(time, name, String.valueOf(content));
419486 }
420487
@@ -589,8 +656,8 @@
589656 for (Part p : partlist) {
590657 newscc.newPart(p.serial(), p.channel(), p.prognum(),
591658 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();
594661 for (MutableMusicEvent n : notelist) {
595662 if (n instanceof MutableControlChange) {
596663 MutableControlChange cc = (MutableControlChange)n;
@@ -686,8 +753,8 @@
686753 }
687754 }
688755
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;
691758 for (Part part : getPartList()) {
692759 for (MutableMusicEvent e : part.getNoteList()) {
693760 for (int k = 1; k <= times; k++) {
--- trunk/src/jp/crestmuse/cmx/filewrappers/SCCUtils.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/filewrappers/SCCUtils.java (revision 843)
@@ -1,6 +1,7 @@
11 package jp.crestmuse.cmx.filewrappers;
22 import jp.crestmuse.cmx.elements.*;
33 import jp.crestmuse.cmx.misc.*;
4+import jp.crestmuse.cmx.math.*;
45 import groovy.lang.*;
56 import javax.xml.transform.*;
67 import java.io.*;
@@ -36,7 +37,7 @@
3637 }
3738
3839 public static class KEY {
39- int time;
40+ long time;
4041 KeySymbol key;
4142 public String toString() {
4243 return "[time:" + time + " key:" + key.encode() + "]";
@@ -385,4 +386,36 @@
385386 return counts;
386387 }
387388
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+ }
388421 }
--- trunk/src/jp/crestmuse/cmx/filewrappers/SCCXMLWrapper.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/filewrappers/SCCXMLWrapper.java (revision 843)
@@ -56,10 +56,10 @@
5656 final int div = getDivision();
5757 processNotes(new SCCHandlerAdapter() {
5858 private double currentInSec;
59- private int lastTempoChangeInTick;
59+ private long lastTempoChangeInTick;
6060 private double lastTempoChangeInSec;
6161 private double currentTempo;
62- private int nextTempoChangeInTick;
62+ private long nextTempoChangeInTick;
6363 private double nextTempoChangeInSec;
6464 private double nextTempo;
6565 private int nextHeader;
@@ -80,7 +80,7 @@
8080 currentTempo = nextTempo;
8181 searchNextTempo();
8282 }
83- note.onsetInMSec = (int)(1000 * calcSec(note.onset()));
83+ note.onsetInMSec = (long)(1000 * calcSec(note.onset()));
8484 if (nextTempoChangeInTick >= 0
8585 && nextTempoChangeInTick < note.offset()) {
8686 lastTempoChangeInTick = nextTempoChangeInTick;
@@ -88,7 +88,7 @@
8888 currentTempo = nextTempo;
8989 searchNextTempo();
9090 }
91- note.offsetInMSec = (int)(1000 * calcSec(note.offset()));
91+ note.offsetInMSec = (long)(1000 * calcSec(note.offset()));
9292 }
9393 private void searchNextTempo() {
9494 int i;
@@ -103,7 +103,7 @@
103103 }
104104 nextHeader = i + 1;
105105 }
106- private double calcSec(int tick) {
106+ private double calcSec(long tick) {
107107 return (tick - lastTempoChangeInTick) * 60 / (div * currentTempo)
108108 + lastTempoChangeInSec;
109109 }
@@ -135,7 +135,7 @@
135135 }
136136
137137 @Deprecated
138- public void addHeaderElement(int time, String name, String content) {
138+ public void addHeaderElement(long time, String name, String content) {
139139 checkElementAddition(headerStarted);
140140 addChild("meta");
141141 setAttribute("name", name);
@@ -145,12 +145,12 @@
145145 }
146146
147147 @Deprecated
148- public void addHeaderElement(int time, String name, double value) {
148+ public void addHeaderElement(long time, String name, double value) {
149149 addHeaderElement(time, name, String.valueOf(value));
150150 }
151151
152152 @Deprecated
153- public void addHeaderElement(int time, String name, int value) {
153+ public void addHeaderElement(long time, String name, int value) {
154154 addHeaderElement(time, name, String.valueOf(value));
155155 }
156156
@@ -245,7 +245,7 @@
245245 }
246246
247247 @Deprecated
248- public void addPitchBend(int time, int value) {
248+ public void addPitchBend(long time, int value) {
249249 checkElementAddition(partStarted);
250250 addChild("pitch-bend");
251251 addText(time + " " + time + " " + value);
@@ -253,7 +253,7 @@
253253 }
254254
255255 @Deprecated
256- public void addPitchBend(int onset, int offset, int value) {
256+ public void addPitchBend(long onset, long offset, int value) {
257257 checkElementAddition(partStarted);
258258 addChild("pitch-bend");
259259 addText(onset + " " + offset + " " + value);
@@ -260,7 +260,7 @@
260260 returnToParent();
261261 }
262262
263- void addProgramChange(int time, int value) {
263+ void addProgramChange(long time, int value) {
264264 checkElementAddition(partStarted);
265265 addChild("program");
266266 addText(time + " " + time + " " + value);
@@ -268,7 +268,7 @@
268268 }
269269
270270 @Deprecated
271- public void addControlChange(int time, int ctrlnum, int value) {
271+ public void addControlChange(long time, int ctrlnum, int value) {
272272 checkElementAddition(partStarted);
273273 addChild("control");
274274 addText(time + " " + time + " " + ctrlnum + " " + value);
@@ -276,7 +276,7 @@
276276 }
277277
278278 @Deprecated
279- public void addControlChange(int onset, int offset,
279+ public void addControlChange(long onset, long offset,
280280 int ctrlnum, int value) {
281281 checkElementAddition(partStarted);
282282 addChild("control");
@@ -285,12 +285,12 @@
285285 }
286286
287287 @Deprecated
288- public void addNoteElement(int onset, int offset,
288+ public void addNoteElement(long onset, long offset,
289289 int notenum, int velocity) {
290290 addNoteElement(onset, offset, notenum, velocity, velocity);
291291 }
292292
293- public void addNoteElement(int onset, int offset,
293+ public void addNoteElement(long onset, long offset,
294294 int notenum, int velocity,
295295 MusicXMLWrapper.Note note) {
296296 checkElementAddition(partStarted);
@@ -305,13 +305,13 @@
305305 }
306306
307307 @Deprecated
308- public void addNoteElement(int onset, int offset, int notenum,
308+ public void addNoteElement(long onset, long offset, int notenum,
309309 int velocity, int offVelocity) {
310310 addNoteElement(onset, offset, notenum, velocity, offVelocity, null);
311311 }
312312
313313 @Deprecated
314- public void addNoteElement(int onset, int offset, int notenum,
314+ public void addNoteElement(long onset, long offset, int notenum,
315315 int velocity, int offVelocity,
316316 Map<String,String> attr) {
317317 addNoteElement(onset, offset, notenum, velocity, offVelocity, attr, null);
@@ -318,7 +318,7 @@
318318 }
319319
320320 @Deprecated
321- public void addNoteElement(int onset, int offset, int notenum,
321+ public void addNoteElement(long onset, long offset, int notenum,
322322 int velocity, int offVelocity,
323323 Map<String,String> attr,
324324 MusicXMLWrapper.Note note) {
@@ -342,7 +342,7 @@
342342 }
343343
344344 @Deprecated
345- public void addNoteElementWithWord(String word, int onset, int offset,
345+ public void addNoteElementWithWord(String word, long onset, long offset,
346346 int notenum, int velocity, int offVelocity){
347347 checkElementAddition(partStarted);
348348 addChild("note");
@@ -351,7 +351,7 @@
351351 returnToParent();
352352 }
353353
354- private void putNoteMap(int onset, int offset, int notenum, int velocity,
354+ private void putNoteMap(long onset, long offset, int notenum, int velocity,
355355 int offVelocity, int ticksPerBeat, int partid,
356356 MusicXMLWrapper.Note note) {
357357 NumberedNote note2 = new NumberedNote(onset, offset, notenum, velocity,
@@ -382,37 +382,39 @@
382382 // }
383383
384384 @Deprecated
385- public void addAnnotation(String type, int onset, int offset,
385+ public void addAnnotation(String type, long onset, long offset,
386386 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+ }
390392 }
391393
392394 @Deprecated
393- public void addChord(int onset, int offset, String content) {
395+ public void addChord(long onset, long offset, String content) {
394396 addAnnotation("chord", onset, offset, content);
395397 }
396398
397399 // Added: 2014/11/18, Author: tama
398400 @Deprecated
399- public void addLyric(int onset, int offset, String content) {
401+ public void addLyric(long onset, long offset, String content) {
400402 addAnnotation("lyric", onset, offset, content);
401403 }
402404
403405 // Added: 2014/11/18, Author: tama
404406 @Deprecated
405- public void addCuePoint(int onset, int offset, String content) {
407+ public void addCuePoint(long onset, long offset, String content) {
406408 addAnnotation("cue", onset, offset, content);
407409 }
408410
409411 @Deprecated
410- public void addMarker(int onset, int offset, String content) {
412+ public void addMarker(long onset, long offset, String content) {
411413 addAnnotation("marker", onset, offset, content);
412414 }
413415
414416 @Deprecated
415- public void addBarline(int time, String details) {
417+ public void addBarline(long time, String details) {
416418 addAnnotation("barline", time, time, details);
417419 }
418420
@@ -438,8 +440,8 @@
438440
439441 /** lyricイベントとcuePointに対応させるために、TextからContenを抜き出す処理を正規表現に変更 */
440442 public class Annotation extends NodeInterface implements SCC.Annotation {
441- private int onset;
442- private int offset;
443+ private long onset;
444+ private long offset;
443445 private String content;
444446 // Modified: 2014/11/18 by tama
445447 private Annotation(Node node) {
@@ -502,11 +504,11 @@
502504 protected String getSupportedNodeName() {
503505 return "chord|barline|lyrics|cuePoint|marker";
504506 }
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; }
507509 public final String content(){ return content; }
508510
509- public final int onset(int ticksPerBeat) {
511+ public final long onset(int ticksPerBeat) {
510512 if (ticksPerBeat == getDivision())
511513 return onset;
512514 else
@@ -513,7 +515,7 @@
513515 return onset * ticksPerBeat / getDivision();
514516 }
515517
516- public final int offset(int ticksPerBeat) {
518+ public final long offset(int ticksPerBeat) {
517519 if (ticksPerBeat == getDivision())
518520 return offset;
519521 else
@@ -664,12 +666,12 @@
664666
665667 public class HeaderElement extends NodeInterface
666668 implements SCC.HeaderElement {
667- private int timestamp;
669+ private long timestamp;
668670 private String name;
669671 private String content;
670672 private HeaderElement(Node node) {
671673 super(node);
672- timestamp = getAttributeInt(node, "time");
674+ timestamp = getAttributeLong(node, "time");
673675 name = getAttribute(node, "name");
674676 content = getAttribute(node, "content");
675677 }
@@ -676,7 +678,7 @@
676678 protected String getSupportedNodeName() {
677679 return "meta";
678680 }
679- public int time() {
681+ public long time() {
680682 return timestamp;
681683 }
682684 public String name() {
@@ -691,7 +693,7 @@
691693 }
692694 public int compareTo(SCC.HeaderElement e) {
693695 if (timestamp != e.time())
694- return timestamp - e.time();
696+ return (int)(timestamp - e.time());
695697 else if (!name.equals(e.name()))
696698 return name.compareTo(e.name());
697699 else if (!content.equals(e.content()))
@@ -771,7 +773,7 @@
771773 Node node = metalist.item(i);
772774 String name = NodeInterface.getAttribute(node, "name");
773775 String content = NodeInterface.getAttribute(node, "content");
774- int timestamp = NodeInterface.getAttributeInt(node, "time");
776+ long timestamp = NodeInterface.getAttributeLong(node, "time");
775777 h.processHeaderElement(timestamp, name, content, this);
776778 }
777779 h.endHeader(this);
@@ -828,8 +830,36 @@
828830 return partlist;
829831 }
830832
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+ }
831841
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+ }
832861
862+
833863 // public int getNumOfParts() throws TransformerException {
834864 // return selectNodeList("/scc/part").getLength();
835865 // }
@@ -895,7 +925,7 @@
895925 dest.addElementsFirstForFormat1(getPartList().length + 1, getDivision());
896926 processNotes(new SCCHandler() {
897927 private int currentTrack = 1;
898- private int currentTime = 0;
928+ private long currentTime = 0;
899929 public final void beginHeader(SCCXMLWrapper w) {
900930 dest.newTrack(currentTrack);
901931 }
@@ -903,15 +933,15 @@
903933 dest.endTrack();
904934 currentTrack++;
905935 }
906- public final void processHeaderElement(int timestamp, String name,
936+ public final void processHeaderElement(long timestamp, String name,
907937 String content, SCCXMLWrapper w) {
908938 if (name.equals("TEMPO"))
909- dest.addMetaEvent("SetTempo", timestamp - currentTime,
939+ dest.addMetaEvent("SetTempo", (int)(timestamp - currentTime),
910940 (int)(1000*1000*60/Double.parseDouble(content)));
911941 else if (name.equals("KEY")) {
912942 KeySymbol key = KeySymbol.parse(content);
913943 int mode = key.mode().equals(KeySymbol.Mode.MIN) ? 1 : 0;
914- dest.addMetaEvent("KeySignature", timestamp - currentTime,
944+ dest.addMetaEvent("KeySignature", (int)(timestamp - currentTime),
915945 key.toInteger(), mode);
916946
917947 // String[] data = content.trim().split(" ");
@@ -977,7 +1007,7 @@
9771007 public final void endHeader(SCCXMLWrapper w) {
9781008 newscc.endHeader();
9791009 }
980- public final void processHeaderElement(int timestamp, String name,
1010+ public final void processHeaderElement(long timestamp, String name,
9811011 String content, SCCXMLWrapper w) {
9821012 newscc.addHeaderElement(timestamp, name, content);
9831013 }
@@ -1027,7 +1057,7 @@
10271057 public final void endHeader(SCCXMLWrapper w) {
10281058 newscc.endHeader();
10291059 }
1030- public final void processHeaderElement(int timestamp, String name,
1060+ public final void processHeaderElement(long timestamp, String name,
10311061 String content, SCCXMLWrapper w) {
10321062 newscc.addHeaderElement(timestamp, name, content);
10331063 }
@@ -1144,8 +1174,8 @@
11441174 (n1.notenum() == n2.notenum() ?
11451175 n1.velocity() - n2.velocity()
11461176 : 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());
11491179 }
11501180 });
11511181 return l;
@@ -1161,8 +1191,8 @@
11611191 (n1.notenum() == n2.notenum() ?
11621192 n1.velocity() - n2.velocity()
11631193 : 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());
11661196 }
11671197 });
11681198 return l;
@@ -1177,7 +1207,7 @@
11771207 (n1.notenum() == n2.notenum() ?
11781208 n1.velocity() - n2.velocity()
11791209 : n1.notenum() - n2.notenum()
1180- ) : n1.onset() - n2.onset();
1210+ ) : (int)(n1.onset() - n2.onset());
11811211 }
11821212 });
11831213 return l;
@@ -1192,7 +1222,7 @@
11921222 (n1.notenum() == n2.notenum() ?
11931223 n1.velocity() - n2.velocity()
11941224 : n1.notenum() - n2.notenum()
1195- ) : n1.onset() - n2.onset();
1225+ ) : (int)(n1.onset() - n2.onset());
11961226 }
11971227 });
11981228 return l;
@@ -1322,8 +1352,9 @@
13221352
13231353 public class Note extends NodeInterface implements SCC.Note {
13241354 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;
13271358 private String xpath;
13281359
13291360 private Note(Node node, Part part) {
@@ -1350,11 +1381,11 @@
13501381 return "note|control|program|pitch-bend";
13511382 }
13521383
1353- public final int onset() {
1384+ public final long onset() {
13541385 return onset;
13551386 }
13561387
1357- public final int onset(int ticksPerBeat) {
1388+ public final long onset(int ticksPerBeat) {
13581389 if (ticksPerBeat == getDivision())
13591390 return onset;
13601391 else
@@ -1361,11 +1392,11 @@
13611392 return onset * ticksPerBeat / getDivision();
13621393 }
13631394
1364- public final int offset() {
1395+ public final long offset() {
13651396 return offset;
13661397 }
13671398
1368- public final int offset(int ticksPerBeat) {
1399+ public final long offset(int ticksPerBeat) {
13691400 if (ticksPerBeat == getDivision())
13701401 return offset;
13711402 else
@@ -1372,7 +1403,7 @@
13721403 return offset * ticksPerBeat / getDivision();
13731404 }
13741405
1375- public final int duration(int ticksPerBeat) {
1406+ public final long duration(int ticksPerBeat) {
13761407 return offset(ticksPerBeat) - onset(ticksPerBeat);
13771408 }
13781409
@@ -1392,22 +1423,26 @@
13921423 return part;
13931424 }
13941425
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+ // }
13991430
1400- public final int onsetInMilliSec() {
1431+ public final long onsetInMilliSec() {
14011432 return onsetInMSec;
14021433 }
14031434
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() {
14061441 return offsetInMSec;
14071442 }
14081443
1409- public final int offsetInMilliSec() {
1410- return offsetInMSec;
1444+ public final long durationInMilliSec() {
1445+ return offsetInMSec - onsetInMSec;
14111446 }
14121447
14131448 public MusicXMLWrapper.Note getMusicXMLWrapperNote() {
@@ -1488,11 +1523,11 @@
14881523 private class NumberedNote extends MutableNote {
14891524 private int partid;
14901525 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,
14921527 int ticksPerBeat, int partid) {
14931528 this(onset, offset, notenum, velocity, velocity, ticksPerBeat, partid);
14941529 }
1495- private NumberedNote(int onset, int offset, int notenum, int velocity,
1530+ private NumberedNote(long onset, long offset, int notenum, int velocity,
14961531 int offVelocity, int ticksPerBeat, int partid) {
14971532 super(onset, offset, notenum, velocity, offVelocity, ticksPerBeat);
14981533 this.partid = partid;
@@ -1515,11 +1550,11 @@
15151550 }
15161551
15171552 class EasyChord{
1518- public int onset;
1519- public int offset;
1553+ public long onset;
1554+ public long offset;
15201555 public String chord;
15211556
1522- public EasyChord(int onset, int offset, String chord){
1557+ public EasyChord(long onset, long offset, String chord){
15231558 this.onset = onset;
15241559 this.offset = offset;
15251560 this.chord = chord;
--- trunk/src/jp/crestmuse/cmx/handlers/SCCHandler.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/handlers/SCCHandler.java (revision 843)
@@ -5,7 +5,7 @@
55 public interface SCCHandler {
66 public void beginHeader(SCCXMLWrapper w);
77 public void endHeader(SCCXMLWrapper w);
8- public void processHeaderElement(int timestamp, String name,
8+ public void processHeaderElement(long timestamp, String name,
99 String content, SCCXMLWrapper w);
1010 public void beginPart(SCCXMLWrapper.Part part, SCCXMLWrapper w);
1111 public void endPart(SCCXMLWrapper.Part part, SCCXMLWrapper w);
@@ -12,4 +12,4 @@
1212 public void processNote(SCCXMLWrapper.Note note, SCCXMLWrapper w);
1313 // public void processNote(SCCXMLWrapper.Note note,
1414 // SCCXMLWrapper.Part part, SCCXMLWrapper w);
15-}
\ No newline at end of file
15+}
--- trunk/src/jp/crestmuse/cmx/handlers/SCCHandlerAdapter.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/handlers/SCCHandlerAdapter.java (revision 843)
@@ -9,7 +9,7 @@
99 public void endHeader(SCCXMLWrapper w) {
1010 // do nothing
1111 }
12- public void processHeaderElement(int timestamp, String name,
12+ public void processHeaderElement(long timestamp, String name,
1313 String content, SCCXMLWrapper w) {
1414 // do nothing
1515 }
--- trunk/src/jp/crestmuse/cmx/math/DoubleMatrixImplAsArray.java (nonexistent)
+++ trunk/src/jp/crestmuse/cmx/math/DoubleMatrixImplAsArray.java (revision 843)
@@ -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+
--- trunk/src/jp/crestmuse/cmx/math/MathUtils.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/math/MathUtils.java (revision 843)
@@ -3,6 +3,8 @@
33 import java.math.*;
44 import org.apache.commons.math.linear.*;
55 import java.nio.*;
6+import dk.ange.octave.*;
7+import dk.ange.octave.type.*;
68
79 public class MathUtils {
810 private static final DoubleArrayFactory factory =
@@ -254,19 +256,27 @@
254256 return parseMatrix(text, " ", "\n");
255257 }
256258
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+ }
260262
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+ }
264270
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());
270280 // Object x1 = x.get(i);
271281 // if (x1 instanceof Double)
272282 // array.set(i, ((Double)x1).doubleValue());
@@ -274,10 +284,14 @@
274284 // array.set(i, ((BigDecimal)x1).doubleValue());
275285 // else
276286 // throw new IllegalArgumentException("Not double value: " + x1);
277- }
278- return array;
279287 }
288+ return array;
289+ }
280290
291+ public static final DoubleArray array(List<? extends Number> x) {
292+ return createDoubleArray(x);
293+ }
294+
281295 public static final DoubleArray createDoubleArrayWithNegativeIndex(int length) {
282296 return new DefaultDoubleArrayWithNegativeIndex(length);
283297 }
@@ -320,28 +334,41 @@
320334 return mfactory.createMatrix(nrows, ncols);
321335 }
322336
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());
333350 }
351+ return matrix;
352+ }
334353
354+ public static final DoubleMatrix mat(List<List<? extends Number>> x) {
355+ return createDoubleMatrix(x);
356+ }
357+
335358 public static final ComplexMatrix createComplexMatrix(int nrows, int ncols) {
336359 return cmfactory.createMatrix(nrows, ncols);
337360 }
338361
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+ }
344367
368+ // public static final DoubleArray arrayOf(double x) {
369+ // return create1dimDoubleArray(x);
370+ // }
371+
345372 public static final RealMatrix toRealMatrix(DoubleMatrix x) {
346373 return new MyRealMatrix(x);
347374 }
@@ -422,6 +449,73 @@
422449 }
423450 }
424451 }
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+
425519 }
426520
427-
\ No newline at end of file
521+
--- trunk/src/jp/crestmuse/cmx/math/Operations.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/math/Operations.java (revision 843)
@@ -540,7 +540,7 @@
540540 }
541541
542542 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));
544544 }
545545
546546 public static final double nn2Hz(double nn) {
@@ -548,13 +548,36 @@
548548 }
549549
550550
551- public static void logX(DoubleArray x, int a) {
551+ public static void logX(DoubleArray x) {
552552 int length = x.length();
553- double logA = log(a);
554553 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)));
556555 }
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+ }
557563
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+
558581 public static double ratioTrue(BooleanArray x) {
559582 int nTrues = 0;
560583 int length = x.length();
@@ -786,15 +809,45 @@
786809 return z;
787810 }
788811
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+ }
789820
821+ public static double getAt(DoubleMatrix x, int i) {
822+ return get(x, i);
823+ }
824+
790825 public static double getAt(DoubleMatrix x, int[] indices) {
791826 return x.get(indices[0], indices[1]);
792827 }
793828
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+
794843 public static void putAt(DoubleMatrix x, int[] indices, double value) {
795844 x.set(indices[0], indices[1], value);
796845 }
797846
847+ // public static void putAt(DoubleMatrix x, int i, int j, double value) {
848+ // x.set(i, j, value);
849+ // }
850+
798851 public static DoubleMatrix add(DoubleMatrix x, DoubleMatrix y) {
799852 int nrows = x.nrows();
800853 int ncols = x.ncols();
@@ -823,6 +876,32 @@
823876 return add(x, y);
824877 }
825878
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+
826905 public static DoubleMatrix sub(DoubleMatrix x, DoubleMatrix y) {
827906 int nrows = x.nrows();
828907 int ncols = x.ncols();
@@ -850,7 +929,21 @@
850929 public static DoubleMatrix minus(DoubleMatrix x, DoubleArray y) {
851930 return sub(x, y);
852931 }
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+
854947 public static DoubleMatrix mul(DoubleMatrix x, double y) {
855948 int nrows = x.nrows();
856949 int ncols = x.ncols();
@@ -881,6 +974,17 @@
881974 return z;
882975 }
883976
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+
884988 public static DoubleMatrix multiply(DoubleMatrix x, DoubleMatrix y) {
885989 return mul(x, y);
886990 }
@@ -1251,8 +1355,33 @@
12511355 }
12521356 return factory.createArray(z);
12531357 }
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+ }
12541376
1377+ public static double abs(double x) {
1378+ return Math.abs(x);
1379+ }
12551380
1381+ public static int abs(int x) {
1382+ return Math.abs(x);
1383+ }
1384+
12561385 public static DoubleArray abs(DoubleArray x) {
12571386 int length = x.length();
12581387 double[] z = new double[length];
@@ -1308,6 +1437,41 @@
13081437 }
13091438 return factory.createArray(z);
13101439 }
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+
13111475 }
13121476
13131477
--- trunk/src/jp/crestmuse/cmx/misc/ChordSymbol2.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/misc/ChordSymbol2.java (revision 843)
@@ -6,7 +6,7 @@
66
77 public class ChordSymbol2 extends ChordSymbol implements Cloneable {
88
9- public static final ChordSymbol2 NONE_CHORD =
9+ public static final ChordSymbol2 NON_CHORD =
1010 new ChordSymbol2(null, Mode.MAJ, Seventh.NONE);
1111
1212 public static final ChordSymbol2 C =
@@ -328,7 +328,7 @@
328328 public static ChordSymbol2 parse(String s, ParseRule r) {
329329 String[] ss = s.trim().split("/");
330330 if (ss.length < 1)
331- return NONE_CHORD;
331+ return NON_CHORD;
332332 Matcher m1 = p1.matcher(ss[0]);
333333 if (m1.matches()) {
334334 NoteSymbol bass = null;
--- trunk/src/jp/crestmuse/cmx/misc/MIDIEventList.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/misc/MIDIEventList.java (revision 843)
@@ -18,17 +18,17 @@
1818 : e1.value1 - e2.value1
1919 ) : e1.ch - e2.ch
2020 ) : e1.status - e2.status
21- ) : e1.time - e2.time;
21+ ) : (int)(e1.time - e2.time);
2222 }
2323 });
2424 }
2525
26- public void addEvent(int time, String msgname, byte ch,
26+ public void addEvent(long time, String msgname, byte ch,
2727 int value1, int value2) {
2828 s.add(new MIDIEvent(time, msgname, ch, value1, value2));
2929 }
3030
31- public void addEvent(int time, short status, byte ch,
31+ public void addEvent(long time, short status, byte ch,
3232 int value1, int value2) {
3333 s.add(new MIDIEvent(time, status, ch, value1, value2));
3434 }
@@ -38,11 +38,12 @@
3838 }
3939
4040 public final class MIDIEvent {
41- private int time, value1 = 0, value2 = 0;
41+ private long time;
42+ private int value1 = 0, value2 = 0;
4243 private short status;
4344 private String msgname;
4445 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) {
4647 this.time = time;
4748 this.status = status;
4849 this.value1 = value1;
@@ -50,7 +51,7 @@
5051 this.msgname = statusNoToMsgName(status);
5152 this.ch = ch;
5253 }
53- MIDIEvent(int time, String msgname, byte ch, int value1, int value2) {
54+ MIDIEvent(long time, String msgname, byte ch, int value1, int value2) {
5455 this.time = time;
5556 this.msgname = msgname;
5657 this.value1 = value1;
@@ -58,7 +59,7 @@
5859 this.status = msgNameToStatusNo(msgname);
5960 this.ch = ch;
6061 }
61- public final int time() {
62+ public final long time() {
6263 return time;
6364 }
6465 public final short status() {
--- trunk/src/jp/crestmuse/cmx/misc/PerformanceMatcher3.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/misc/PerformanceMatcher3.java (revision 843)
@@ -285,8 +285,8 @@
285285 // }
286286 int I = compressedScore.size();
287287 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();
290290 // r = Math.max(0, Math.max(J-I, r));
291291 r = J;
292292 DTWMatrix matrix = new DTWMatrix(I, J);
@@ -306,9 +306,9 @@
306306 // else ioi = 1.0 / diff;
307307 // }
308308 if (i > 0 && j > 0) {
309- int scoreDiff = e1.notes.get(0).onset()
309+ long scoreDiff = e1.notes.get(0).onset()
310310 - 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();
312312 if (pfmDiff == 0)
313313 ioi = Double.POSITIVE_INFINITY;
314314 else
@@ -337,7 +337,7 @@
337337 return matrix;
338338 }
339339
340- private double dist(NoteInSameTime e1, Note e2, int scoreTicks, int pfmTicks) {
340+ private double dist(NoteInSameTime e1, Note e2, long scoreTicks, long pfmTicks) {
341341 double position = Math.abs((e1.notes.get(0).onset() / (double) scoreTicks - e2.onset()
342342 / (double) pfmTicks));
343343 for (Note n : e1.notes) {
@@ -450,13 +450,13 @@
450450
451451 private class TempoAndTime {
452452 private double tempo = Double.NaN;
453- private int tickInScore;
453+ private long tickInScore;
454454 private double tickInPfm = Double.NaN;
455455 private double timeInSec = Double.NaN;
456456 private int measure = -1;
457457 private int beat = -1;
458458
459- private TempoAndTime(int tickInScore) {
459+ private TempoAndTime(long tickInScore) {
460460 this.tickInScore = tickInScore;
461461 }
462462
@@ -604,7 +604,7 @@
604604 }
605605
606606 // kari; redundant calculation
607- private double getSecFromScoreTick(int tick, List<TempoAndTime> tempolist) {
607+ private double getSecFromScoreTick(long tick, List<TempoAndTime> tempolist) {
608608 TempoAndTime last = tempolist.get(0);
609609 for (TempoAndTime tnt : tempolist) {
610610 if (tick < tnt.tickInScore)
@@ -616,7 +616,7 @@
616616 }
617617
618618 // kari; redundant calculation
619- private double getSecFromPfmTick(int tick, List<TempoAndTime> tempolist) {
619+ private double getSecFromPfmTick(long tick, List<TempoAndTime> tempolist) {
620620 TempoAndTime last = tempolist.get(0);
621621 for (TempoAndTime tnt : tempolist) {
622622 if (tick < tnt.tickInPfm)
@@ -705,7 +705,7 @@
705705 note.velocity() / BASE_DYNAMICS);
706706 }
707707
708- private boolean tickcmp(int tick1, int tick2, int threshold) {
708+ private boolean tickcmp(long tick1, long tick2, int threshold) {
709709 return (tick1 >= tick2 - threshold && tick1 <= tick2 + threshold);
710710 }
711711
@@ -723,7 +723,8 @@
723723 ArrayList<TempoAndTime> tempolist = new ArrayList<TempoAndTime>();
724724 tempolist.add(getZerothTempoAndTime());
725725 int i = 0;
726- int measure = 0, beat = 1, currentTick = 0;
726+ int measure = 0, beat = 1;
727+ long currentTick = 0;
727728 for (int k = 0; k < barlines.length - 2; k++) {
728729 Measure m = getMeasure(((Annotation)barlines[k]).onset());
729730 measure = m.number();
@@ -743,7 +744,7 @@
743744 // beat = 1;
744745 i = addTempoAndTime(currentTick, measure, beat, i, tempolist);
745746
746- int lastOffset = currentTick;
747+ long lastOffset = currentTick;
747748 for (int ii = 0; ii < scoreNotes.length; ii++)
748749 if (scoreNotes[ii].offset() > lastOffset)
749750 lastOffset = scoreNotes[ii].offset();
@@ -770,7 +771,7 @@
770771 return a >= b ? a : b;
771772 }
772773
773- private int addTempoAndTime(int currentTick, int measure, int beat, int i,
774+ private int addTempoAndTime(long currentTick, int measure, int beat, int i,
774775 ArrayList<TempoAndTime> tempolist) {
775776 while (i < scoreNotes.length) {
776777 if (score2pfm[i] == -1) {
@@ -819,8 +820,8 @@
819820
820821 private int lastMeasureIndex = 0;
821822
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);
824825 if (tick0 == tick) {
825826 return measurelist[lastMeasureIndex];
826827 } else if (tick0 > tick) {
@@ -945,13 +946,13 @@
945946 TempoAndTime tnt = tempolist.get(i);
946947 if (Double.isNaN(tnt.timeInSec)) {
947948 prevtnt.tempo = prevTempo;
948- int interval = tnt.tickInScore - prevtnt.tickInScore;
949+ long interval = tnt.tickInScore - prevtnt.tickInScore;
949950 double pfmInterval = (double) (interval * 60 / scoreTicksPerBeat)
950951 / prevTempo;
951952 tnt.setTimeInSec(prevtnt.timeInSec + pfmInterval);
952953 // tnt.setTimeInSec(prevtnt.timeInSec + 60.0 / prevTempo);
953954 } else {
954- int interval = tnt.tickInScore - prevtnt.tickInScore;
955+ long interval = tnt.tickInScore - prevtnt.tickInScore;
955956 double pfmInterval = tnt.timeInSec - prevtnt.timeInSec;
956957 // zantei
957958 if (pfmInterval < 0.0000000001) {
--- trunk/src/jp/crestmuse/cmx/misc/PianoRoll.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/misc/PianoRoll.java (revision 843)
@@ -6,6 +6,7 @@
66 public int getMeasureNum();
77 public int getBeatNum();
88 public int getFirstMeasure();
9+ public void setFirstMeasure(int measure);
910 public boolean isSelectable();
1011 public boolean isEditable();
1112 public void selectNote(int measure, double beat, int notenum);
--- trunk/src/jp/crestmuse/cmx/misc/TimeFreqRepresentation.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/misc/TimeFreqRepresentation.java (revision 843)
@@ -164,10 +164,10 @@
164164 for (SCC.Part p : parts) {
165165 SCC.Note[] notes = p.getNoteOnlyList();
166166 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);
171171 int notenum = note.notenum();
172172 ///// onsetがoffsetより長いなぞのパターン ///////
173173 ///// とりあえず入れ替えておく ///////
@@ -246,4 +246,4 @@
246246 * (byte)(127 * (offset - n) / (offset - onset))); } }); return tfr; }
247247 */
248248
249-}
\ No newline at end of file
249+}
--- trunk/src/jp/crestmuse/cmx/processing/CMXApplet.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/processing/CMXApplet.java (revision 843)
@@ -193,6 +193,10 @@
193193 ctrl.setMicrosecondPosition(t);
194194 }
195195
196+ public void setTickPosition(long tick) {
197+ ctrl.setTickPosition(tick);
198+ }
199+
196200 /** 現在の再生中の音楽データにおける現在の再生箇所をティック単位で
197201 返します.
198202 ただし,このメソッドは読み込み済みのデータがMIDIデータのときしか
@@ -441,7 +445,8 @@
441445 }
442446
443447 private void autostart() {
444- if (autostart) {
448+ if (autostart) {
449+ // setupExternalMessages();
445450 println("SPExector automatically started.");
446451 ctrl.startSP();
447452 }
@@ -451,6 +456,19 @@
451456 // ctrl.stopSP();
452457 // }
453458
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+
454472 public void stop() {
455473 super.stop();
456474 println("SPExecutor automatically stopped.");
--- trunk/src/jp/crestmuse/cmx/processing/CMXController.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/processing/CMXController.java (revision 843)
@@ -23,29 +23,8 @@
2323
2424 import javazoom.jl.decoder.BitstreamException;
2525 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.*;
4727 import jp.crestmuse.cmx.filewrappers.*;
48-import jp.crestmuse.cmx.filewrappers.XMLException;
4928 import jp.crestmuse.cmx.inference.MusicRepresentation;
5029 import jp.crestmuse.cmx.inference.MusicRepresentationFactory;
5130 import jp.crestmuse.cmx.math.ComplexArray;
@@ -91,6 +70,8 @@
9170 private MidiDevice.Info[] midiouts = new MidiDevice.Info[256];
9271 private Mixer.Info mixer = null;
9372
73+ private long startTime;
74+
9475 private CMXController() {
9576
9677 }
@@ -427,6 +408,7 @@
427408 mic.getLine().start();
428409 if (spexec != null)
429410 spexec.start();
411+ startTime = System.nanoTime() / 1000;
430412 }
431413
432414 public void stopSP() {
@@ -861,10 +843,10 @@
861843 * 現在の再生中の音楽データにおける現在の再生箇所をマイクロ秒単位で 返します.
862844 */
863845 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();
868850 }
869851
870852 public long getMicrosecondLength() {
@@ -900,10 +882,10 @@
900882 * 使用できません.
901883 */
902884 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();
907889 }
908890
909891 public int getTicksPerBeat() {
@@ -916,7 +898,7 @@
916898 */
917899 public int getTicksPerBeat(int i) {
918900 if (musicPlayer[i] == null)
919- return 0;
901+ return 480;
920902 else
921903 return musicPlayer[i].getTicksPerBeat();
922904 }
@@ -1374,6 +1356,13 @@
13741356 return evtsender;
13751357 }
13761358
1359+ public MidiRecorder2 createMidiRecorder() {
1360+ MidiRecorder2 rec = new MidiRecorder2(this);
1361+ rec.setTempo(120.0); // kari
1362+ addSPModule(rec);
1363+ return rec;
1364+ }
1365+
13771366 /**
13781367 * 音響信号処理に関する各種パラメータや設定を記述してConfigXMLファイルを読み込みます. <tt>createMic</tt>
13791368 * などを使用する際には必須です.
--- trunk/src/jp/crestmuse/cmx/sound/TickTimer.java (revision 842)
+++ trunk/src/jp/crestmuse/cmx/sound/TickTimer.java (revision 843)
@@ -3,4 +3,5 @@
33 public interface TickTimer {
44 public int getTicksPerBeat();
55 public long getTickPosition();
6+ /* public double getTempo(); */
67 }
旧リポジトリブラウザで表示