• R/O
  • SSH
  • HTTPS

asom: Commit


Commit MetaInfo

Revision4 (tree)
Zeit2007-11-01 18:35:49
Autoryaggy

Log Message

experimentのものをtrunkにのせた

Ändern Zusammenfassung

Diff

--- trunk/asom/exec/asom.bat (nonexistent)
+++ trunk/asom/exec/asom.bat (revision 4)
@@ -0,0 +1,6 @@
1+set JAVA_HOME="C:\Program Files\Java\jre1.5.0_07"
2+set PATH=%JAVA_HOME%\bin:%PATH%
3+
4+java -cp lib/asom.jar com.momiage.app.asom.main.ASOMLauncher %1
5+
6+pause
--- trunk/asom/exec/asom.sh (nonexistent)
+++ trunk/asom/exec/asom.sh (revision 4)
@@ -0,0 +1,10 @@
1+#!/bin/sh
2+
3+JAVA_HOME=/usr/local/java
4+export JAVA_HOME
5+
6+PATH=${JAVA_HOME}/bin;${PATH}
7+export PATH
8+
9+java -cp lib/asom.jar com.momiage.app.asom.main.ASOMLauncher ${1}
10+
--- trunk/asom/doc/todo.txt (nonexistent)
+++ trunk/asom/doc/todo.txt (revision 4)
@@ -0,0 +1,39 @@
1+
2+
3+
4+設定するやつ。
5+
6+テンポ
7+@@ASOM_Tempo=120
8+
9+キー
10+@@ASOM_Key=Am
11+
12+出だしの音
13+@@ASOM_StartNote=C
14+
15+音程変化最大幅(半音で1)
16+@@ASOM_MaxNoteRange=11
17+
18+スケール外の音確率?
19+@@ASOM_ScaleOutNoteRate=30
20+
21+音色番号
22+@@ASOM_InstrumentNo=12
23+
24+付点音符を使うか?
25+@@ASOM_EnableDottedNote=false
26+@@ASOM_EnableDottedNote=true
27+
28+三連符を使うか?
29+@@ASOM_EnableTripletNote=false
30+@@ASOM_EnableTripletNote=true
31+@@ASOM_EnableTripletNote=every
32+
33+休符文字
34+@@ASOM_RestChar=. ();{}
35+
36+記号
37+@@@ASOM_START_POINT
38+@@@ASOM_END_POINT
39+
--- trunk/asom/src/com/momiage/app/asom/source/HelloAsomWorld.sh (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/source/HelloAsomWorld.sh (revision 4)
@@ -0,0 +1,2 @@
1+#!/bin/sh
2+echo 'hello a source of music world!'
--- trunk/asom/src/com/momiage/app/asom/source/HelloAsomWorld.java (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/source/HelloAsomWorld.java (revision 4)
@@ -0,0 +1,11 @@
1+package com.momiage.app.asom.source;
2+
3+public class HelloAsomWorld {
4+
5+ public static void main(String[] args) {
6+ System.out.println("hello a source of music world!");
7+ System.out.println("こんにちは。ソース音楽の世界。");
8+ System.out.println("this source is music");
9+ }
10+
11+}
--- trunk/asom/src/com/momiage/app/asom/source/HelloAsomWorld.c (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/source/HelloAsomWorld.c (revision 4)
@@ -0,0 +1,6 @@
1+#include <stdio.h>
2+
3+int main() {
4+ fprintf(stdout, "hello a source of music world!\n");
5+ return 0;
6+}
--- trunk/asom/src/com/momiage/app/asom/source/HelloAsomWorld.cpp (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/source/HelloAsomWorld.cpp (revision 4)
@@ -0,0 +1,7 @@
1+#include <iostream>
2+using namespace std;
3+
4+int main() {
5+ cout << "hello a source of music world!" << endl;
6+ return 0;
7+}
--- trunk/asom/src/com/momiage/app/asom/gui/SourceChaserFrame.java (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/gui/SourceChaserFrame.java (revision 4)
@@ -0,0 +1,114 @@
1+package com.momiage.app.asom.gui;
2+
3+import java.awt.BorderLayout;
4+import java.awt.event.ActionEvent;
5+import java.awt.event.ActionListener;
6+import java.util.Iterator;
7+import java.util.List;
8+
9+import javax.swing.JButton;
10+import javax.swing.JFrame;
11+import javax.swing.JPanel;
12+import javax.swing.JScrollPane;
13+import javax.swing.JTextPane;
14+
15+import com.momiage.app.asom.logic.SourceInfo;
16+import com.momiage.app.asom.logic.SourceTrackInfo;
17+
18+public class SourceChaserFrame extends JFrame implements ActionListener,
19+ Runnable {
20+
21+ private static final long serialVersionUID = 8944411566890622937L;
22+
23+ private JPanel jContentPane = null;
24+ private JTextPane jTextPane = null;
25+ private JScrollPane jScrollPane = null;
26+ private JButton jButton = null;
27+
28+ protected SourceInfo si = null;
29+ protected List<SourceTrackInfo> lsti = null;
30+
31+ public SourceChaserFrame(SourceInfo sourceInfo, List<SourceTrackInfo> lsts) {
32+ si = sourceInfo;
33+ lsti = lsts;
34+
35+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
36+ setSize(500, 400);
37+ setContentPane(getJContentPane());
38+ setTitle("a source of music");
39+ }
40+
41+ private JPanel getJContentPane() {
42+ if (jContentPane == null) {
43+ jContentPane = new JPanel();
44+ jContentPane.setLayout(new BorderLayout());
45+ jContentPane.add(getJScrollPane(), BorderLayout.CENTER);
46+ jContentPane.add(getJButton(), BorderLayout.NORTH);
47+ }
48+ return jContentPane;
49+ }
50+
51+ private JScrollPane getJScrollPane() {
52+ if (jScrollPane == null) {
53+ jScrollPane = new JScrollPane(getJTextPane());
54+ jScrollPane.setName("jScrollPane");
55+ jScrollPane.setVerticalScrollBarPolicy(
56+ JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
57+ jScrollPane.setHorizontalScrollBarPolicy(
58+ JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
59+ }
60+ return jScrollPane;
61+ }
62+
63+ private JTextPane getJTextPane() {
64+ if (jTextPane == null) {
65+ jTextPane = new JTextPane();
66+ jTextPane.setName("jTextPane");
67+
68+ StringBuffer sb = new StringBuffer();
69+ Iterator<String> it = si.getSourceBody().iterator();
70+ while (it.hasNext()) {
71+ sb.append(it.next());
72+ sb.append("\r\n");
73+ }
74+ jTextPane.setText(sb.toString());
75+ jTextPane.setSelectionStart(0);
76+ jTextPane.setSelectionEnd(0);
77+ }
78+ return jTextPane;
79+ }
80+
81+ private JButton getJButton() {
82+ if (jButton == null) {
83+ jButton = new JButton();
84+ jButton.setName("jButton");
85+ jButton.setText("PLAY A SOURCE OF MUSIC!");
86+ jButton.addActionListener(this);
87+ }
88+ return jButton;
89+ }
90+
91+ public void actionPerformed(ActionEvent arg0) {
92+ SequencerThread th = new SequencerThread(si, lsti, jTextPane);
93+ th.start();
94+
95+ /*
96+ * Thread th = new Thread(this); th.start();
97+ */
98+ }
99+
100+ public void run() {
101+ int i = 0;
102+ while (i < jTextPane.getText().length()) {
103+ jTextPane.requestFocus();
104+ jTextPane.setSelectionStart(0);
105+ jTextPane.setSelectionEnd(i++);
106+ try {
107+ Thread.sleep(500);
108+ } catch (InterruptedException e) {
109+ e.printStackTrace();
110+ }
111+ }
112+ }
113+
114+}
--- trunk/asom/src/com/momiage/app/asom/gui/SequencerThread.java (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/gui/SequencerThread.java (revision 4)
@@ -0,0 +1,114 @@
1+package com.momiage.app.asom.gui;
2+
3+import java.util.Iterator;
4+import java.util.List;
5+
6+import javax.sound.midi.Instrument;
7+import javax.sound.midi.MidiChannel;
8+import javax.sound.midi.MidiSystem;
9+import javax.sound.midi.ShortMessage;
10+import javax.sound.midi.Soundbank;
11+import javax.sound.midi.Synthesizer;
12+import javax.swing.JTextPane;
13+
14+import com.momiage.app.asom.common.DebugCommon;
15+import com.momiage.app.asom.logic.SourceInfo;
16+import com.momiage.app.asom.logic.SourceTrackInfo;
17+import com.momiage.app.asom.logic.MusicCreator;
18+
19+public class SequencerThread extends Thread {
20+
21+ protected MidiChannel channel = null;
22+ protected Synthesizer synthesizer = null;
23+
24+ protected int msecPerTick = -1;
25+
26+ protected SourceInfo si = null;
27+ protected List<SourceTrackInfo> lsti = null;
28+ protected JTextPane spane = null;
29+
30+ protected boolean initialized = false;
31+
32+ public SequencerThread(SourceInfo sourceInfo, List<SourceTrackInfo> lsts,
33+ JTextPane sourcePane) {
34+ si = sourceInfo;
35+ lsti = lsts;
36+ spane = sourcePane;
37+ }
38+
39+ public void init() {
40+ int tempo = si.getTempo();
41+ int l = 60 * 1000000 / tempo;
42+ msecPerTick = l / MusicCreator.NOTE_LEN_4 / 1000;
43+
44+ initialized = true;
45+ }
46+
47+ public void run() {
48+ if (!initialized) {
49+ init();
50+ }
51+
52+ Soundbank soundbank = null;
53+ Instrument[] instruments = null;
54+
55+ try {
56+
57+ synthesizer = MidiSystem.getSynthesizer();
58+ synthesizer.open();
59+
60+ soundbank = synthesizer.getDefaultSoundbank();
61+
62+ instruments = soundbank.getInstruments();
63+ synthesizer.loadInstrument(instruments[0]);
64+
65+ channel = synthesizer.getChannels()[0];
66+
67+ channel.programChange(si.getInstNo() - 1);
68+
69+ Iterator<SourceTrackInfo> it = lsti.iterator();
70+ SourceTrackInfo sti = null;
71+ if (it.hasNext()) {
72+ sti = it.next();
73+ }
74+
75+ while (it.hasNext()) {
76+ DebugCommon.print(sti.toString());
77+
78+ SourceTrackInfo nsti = it.next();
79+
80+ int pos = sti.getCharpos();
81+ spane.requestFocus();
82+ spane.setSelectionStart(0);
83+ spane.setSelectionEnd(pos);
84+
85+ if (sti.getMes() == ShortMessage.NOTE_OFF) {
86+ channel.allNotesOff();
87+
88+ } else {
89+ channel.noteOn(sti.getPitch(), 127);
90+ }
91+ int sleepTick = nsti.getTick() - sti.getTick();
92+ if (0 < sleepTick) {
93+ sleep(sleepTick * msecPerTick);
94+ }
95+ sti = nsti;
96+ }
97+
98+ spane.requestFocus();
99+ spane.setSelectionStart(0);
100+ spane.setSelectionEnd(spane.getText().length());
101+
102+ channel.allNotesOff();
103+
104+ synthesizer.close();
105+
106+ } catch (Exception e) {
107+ if (channel != null) {
108+ channel.allNotesOff();
109+ }
110+ }
111+
112+ }
113+
114+}
--- trunk/asom/src/com/momiage/app/asom/main/ASOMTest.java (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/main/ASOMTest.java (revision 4)
@@ -0,0 +1,89 @@
1+package com.momiage.app.asom.main;
2+
3+import java.io.File;
4+import java.util.List;
5+
6+import javax.swing.SwingUtilities;
7+
8+import com.momiage.app.asom.gui.SourceChaserFrame;
9+import com.momiage.app.asom.logic.SourceInfo;
10+import com.momiage.app.asom.logic.SourceInfoReader;
11+import com.momiage.app.asom.logic.SourceTrackInfo;
12+import com.momiage.app.asom.logic.MusicCreator;
13+
14+public class ASOMTest {
15+
16+ /**
17+ * @param args
18+ */
19+ public static void main(String[] args) throws Exception {
20+
21+ SwingUtilities.invokeLater(new Runnable() {
22+ public void run() {
23+ SourceInfo si1;
24+ List<SourceTrackInfo> lsti1;
25+ String baseDir = "C:/sf_svn/asom.local/experiment/src/com/momiage/app/asom/";
26+ try {
27+ si1 = SourceInfoReader.readSource(new File(baseDir
28+ + "source/HelloAsomWorld.java"));
29+ lsti1 = MusicCreator.create(si1, new File(
30+ "C:/HelloAsomWorld.java.mid"));
31+ SourceChaserFrame application1 = new SourceChaserFrame(si1,
32+ lsti1);
33+ application1.setVisible(true);
34+
35+ si1 = SourceInfoReader.readSource(new File(baseDir
36+ + "source/HelloAsomWorld.c"));
37+ lsti1 = MusicCreator.create(si1, new File(
38+ "C:/HelloAsomWorld.c.mid"));
39+ application1 = new SourceChaserFrame(si1, lsti1);
40+ application1.setVisible(true);
41+
42+ si1 = SourceInfoReader.readSource(new File(baseDir
43+ + "source/HelloAsomWorld.cpp"));
44+ lsti1 = MusicCreator.create(si1, new File(
45+ "C:/HelloAsomWorld.cpp.mid"));
46+ application1 = new SourceChaserFrame(si1, lsti1);
47+ application1.setVisible(true);
48+
49+ si1 = SourceInfoReader.readSource(new File(baseDir
50+ + "source/HelloAsomWorld.n88basic"));
51+ lsti1 = MusicCreator.create(si1, new File(
52+ "C:/HelloAsomWorld.n88basic.mid"));
53+ application1 = new SourceChaserFrame(si1, lsti1);
54+ application1.setVisible(true);
55+
56+ si1 = SourceInfoReader.readSource(new File(baseDir
57+ + "source/HelloAsomWorld.cobol"));
58+ lsti1 = MusicCreator.create(si1, new File(
59+ "C:/HelloAsomWorld.cobol.mid"));
60+ application1 = new SourceChaserFrame(si1, lsti1);
61+ application1.setVisible(true);
62+
63+ si1 = SourceInfoReader.readSource(new File(baseDir
64+ + "source/HelloAsomWorld.sh"));
65+ lsti1 = MusicCreator.create(si1, new File(
66+ "C:/HelloAsomWorld.sh.mid"));
67+ application1 = new SourceChaserFrame(si1, lsti1);
68+ application1.setVisible(true);
69+
70+ si1 = SourceInfoReader.readSource(new File(baseDir
71+ + "main/ASOMTest.java"));
72+ lsti1 = MusicCreator.create(si1, new File(
73+ "C:/ASOMTest.java.mid"));
74+ application1 = new SourceChaserFrame(si1, lsti1);
75+ application1.setVisible(true);
76+
77+ } catch (Exception e) {
78+ e.printStackTrace();
79+ }
80+ }
81+ });
82+
83+ }
84+
85+ public void debugPrint() {
86+
87+ }
88+
89+}
--- trunk/asom/src/com/momiage/app/asom/main/ASOMLauncher.java (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/main/ASOMLauncher.java (revision 4)
@@ -0,0 +1,55 @@
1+package com.momiage.app.asom.main;
2+
3+import java.io.File;
4+import java.util.List;
5+
6+import javax.swing.SwingUtilities;
7+
8+import com.momiage.app.asom.gui.SourceChaserFrame;
9+import com.momiage.app.asom.logic.MusicCreator;
10+import com.momiage.app.asom.logic.SourceInfo;
11+import com.momiage.app.asom.logic.SourceInfoReader;
12+import com.momiage.app.asom.logic.SourceTrackInfo;
13+
14+public class ASOMLauncher {
15+
16+ public static String source = "";
17+ public static String midifile = "";
18+
19+ private static final String asomVersion = "a source of music Version 0.0.1";
20+
21+ public static void main(String[] args) throws Exception {
22+
23+ if (1 != args.length) {
24+ System.err.println("usage: java -cp lib/asom.jar com.momiage.app.asom.main.ASOMLauncher SOURCEFILE");
25+ System.exit(-1);
26+ }
27+
28+ if ("-version".equals(args[0])) {
29+ System.out.println(asomVersion);
30+ System.exit(0);
31+ }
32+
33+ source = args[0];
34+ midifile = source + ".mid";
35+
36+ SwingUtilities.invokeLater(new Runnable() {
37+ public void run() {
38+ SourceInfo si;
39+ List<SourceTrackInfo> lsti;
40+ try {
41+ si = SourceInfoReader.readSource(new File(source));
42+ lsti = MusicCreator.create(si, new File(
43+ midifile));
44+ SourceChaserFrame scf = new SourceChaserFrame(si,
45+ lsti);
46+ scf.setVisible(true);
47+ }
48+ catch (Exception e) {
49+ e.printStackTrace();
50+ }
51+ }
52+ });
53+
54+ }
55+}
--- trunk/asom/src/com/momiage/app/asom/common/DebugCommon.java (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/common/DebugCommon.java (revision 4)
@@ -0,0 +1,13 @@
1+package com.momiage.app.asom.common;
2+
3+public class DebugCommon {
4+
5+ public static void print(char c) {
6+ System.err.print(c);
7+ }
8+
9+ public static void print(String s) {
10+ System.err.println(s);
11+ }
12+
13+}
--- trunk/asom/src/com/momiage/app/asom/logic/SourceInfoReader.java (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/logic/SourceInfoReader.java (revision 4)
@@ -0,0 +1,49 @@
1+package com.momiage.app.asom.logic;
2+
3+import java.io.BufferedReader;
4+import java.io.File;
5+import java.io.FileReader;
6+import java.io.IOException;
7+import java.util.List;
8+import java.util.Vector;
9+
10+public class SourceInfoReader extends SourceInfo {
11+
12+ public static SourceInfo readSource(File f) throws IOException {
13+
14+ SourceInfo si = new SourceInfo();
15+
16+ List<String> all = new Vector<String>();
17+ List<String> body = new Vector<String>();
18+ boolean isBody = false;
19+
20+ BufferedReader br = new BufferedReader(new FileReader(f));
21+
22+ String line;
23+ while ((line = br.readLine()) != null) {
24+ all.add(line);
25+ if (!isBody) {
26+ if (line.indexOf(startPointSig) > 0) {
27+ isBody = true;
28+ }
29+ } else {
30+ if (line.indexOf(endPointSig) > 0) {
31+ break;
32+ }
33+ body.add(line);
34+ }
35+ }
36+
37+ br.close();
38+
39+ if (isBody) {
40+ si.sourceBody = body;
41+ } else {
42+ si.sourceBody = all;
43+ }
44+
45+ return si;
46+
47+ }
48+
49+}
--- trunk/asom/src/com/momiage/app/asom/logic/MusicCreator.java (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/logic/MusicCreator.java (revision 4)
@@ -0,0 +1,227 @@
1+package com.momiage.app.asom.logic;
2+
3+import java.io.File;
4+import java.io.IOException;
5+import java.util.Iterator;
6+import java.util.List;
7+import java.util.Set;
8+import java.util.Vector;
9+
10+import javax.sound.midi.InvalidMidiDataException;
11+import javax.sound.midi.MetaMessage;
12+import javax.sound.midi.MidiEvent;
13+import javax.sound.midi.MidiSystem;
14+import javax.sound.midi.Sequence;
15+import javax.sound.midi.ShortMessage;
16+import javax.sound.midi.Track;
17+
18+import com.momiage.app.asom.common.DebugCommon;
19+
20+public class MusicCreator {
21+
22+ // 四分音符を24tickとする
23+ public static final int BASE_TICK = 24;
24+
25+ // 各音符をtickであらわす
26+ public static final int NOTE_LEN_1 = BASE_TICK * 4;
27+ public static final int NOTE_LEN_2 = BASE_TICK * 2;
28+ public static final int NOTE_LEN_4 = BASE_TICK;
29+ public static final int NOTE_LEN_8 = BASE_TICK / 2;
30+ public static final int NOTE_LEN_16 = BASE_TICK / 4;
31+ public static final int NOTE_LEN_32 = BASE_TICK / 8;
32+
33+ public static final int NOTE_LEN_2_DOT = NOTE_LEN_2 + NOTE_LEN_4;
34+ public static final int NOTE_LEN_4_DOT = NOTE_LEN_4 + NOTE_LEN_8;
35+ public static final int NOTE_LEN_8_DOT = NOTE_LEN_8 + NOTE_LEN_16;
36+ public static final int NOTE_LEN_16_DOT = NOTE_LEN_16 + NOTE_LEN_32;
37+
38+ public static final int NOTE_LEN_4_TRI = NOTE_LEN_2 / 3;
39+ public static final int NOTE_LEN_8_TRI = NOTE_LEN_4 / 3;
40+
41+ public static List<SourceTrackInfo> create(SourceInfo si, File f)
42+ throws InvalidMidiDataException, IOException {
43+
44+ List<SourceTrackInfo> sti = new Vector<SourceTrackInfo>();
45+
46+ // 音符の長さの種類
47+ // とりあえず、付点音符や3連符などは使わない
48+ int[] notelenKind = { NOTE_LEN_1, NOTE_LEN_2, NOTE_LEN_4, NOTE_LEN_8,
49+ NOTE_LEN_16, NOTE_LEN_32,
50+
51+ };
52+
53+ int channel = 0;
54+ int firstPitch = 48;
55+ int nowPitch = 48;
56+ int velocity = 127;
57+ int instrument = si.getInstNo();
58+ int tickPos = 0;
59+
60+ // MIDIの初期設定
61+ Sequence seq = new Sequence(Sequence.PPQ, BASE_TICK);
62+ Track trk = seq.createTrack();
63+
64+ MetaMessage mmessage = new MetaMessage();
65+ int tempo = si.getTempo();
66+ int l = 60 * 1000000 / tempo;
67+ mmessage.setMessage(0x51, new byte[] { (byte) (l / 65536),
68+ (byte) (l % 65536 / 256), (byte) (l % 256) }, 3);
69+ trk.add(new MidiEvent(mmessage, 0));
70+
71+ ShortMessage message = new ShortMessage();
72+ debugSetMessage(message, ShortMessage.PROGRAM_CHANGE, channel,
73+ instrument, 0, 0);
74+ trk.add(new MidiEvent(message, 0));
75+
76+ // 休符記号の取得
77+ String restChar = si.getRestChar();
78+
79+ boolean isRest = false;
80+ char oldc = 0;
81+ char c = 0;
82+ int oldlenIndex = -1;
83+ int lenIndex = -1;
84+ int allcharpos = 0;
85+ int charpos = 0;
86+ int linepos = 0;
87+
88+ Set<Integer> scale = MusicTheory.getMajorScaleNotes(si.getKey());
89+
90+ // ソースの取得
91+ Iterator<String> it = si.getSourceBody().iterator();
92+ while (it.hasNext()) {
93+ allcharpos += charpos;
94+ linepos++;
95+ charpos = 0;
96+ String line = it.next();
97+
98+ // トラック作成ループ
99+ while (charpos < line.length()) {
100+
101+ try {
102+
103+ while (restChar.indexOf(c) > 0) {
104+ c = debugCharAt(line, charpos++);
105+ }
106+
107+ isRest = false;
108+
109+ c = debugCharAt(line, charpos++);
110+
111+ if (restChar.indexOf(c) > 0) {
112+ // is rest.
113+ DebugCommon.print("");
114+ DebugCommon.print("isRest");
115+ isRest = true;
116+
117+ while (restChar.indexOf(c) > 0) {
118+ c = debugCharAt(line, charpos++);
119+ }
120+
121+ } else {
122+ int diff = oldc - c;
123+ // is note.
124+ if (0 == oldc) {
125+ nowPitch = firstPitch;
126+ } else {
127+ diff = diff % si.getMaxNoteRange();
128+ nowPitch = nowPitch + diff;
129+ }
130+
131+ if (nowPitch > 127) {
132+ nowPitch = 127;
133+ } else if (nowPitch < 1) {
134+ nowPitch = 1;
135+ }
136+
137+ // スケールの中に入れる
138+ int lowNote = (Integer)scale.toArray()[0];
139+ if (diff >= si.getScaleOutNoteRate()) {
140+ while (!scale.contains(nowPitch)) {
141+ nowPitch--;
142+ DebugCommon.print("Scale In Key " + si.getKey() + " = " + nowPitch);
143+ if (lowNote > nowPitch) {
144+ nowPitch = lowNote;
145+ }
146+ }
147+ }
148+
149+ message = new ShortMessage();
150+ debugSetMessage(message, ShortMessage.NOTE_ON, channel,
151+ nowPitch, velocity, tickPos);
152+ trk.add(new MidiEvent(message, tickPos));
153+
154+ sti.add(new SourceTrackInfo(ShortMessage.NOTE_ON,
155+ tickPos, nowPitch, linepos, allcharpos
156+ + charpos));
157+
158+ c = debugCharAt(line, charpos++);
159+
160+ while (restChar.indexOf(c) > 0) {
161+ c = debugCharAt(line, charpos++);
162+ }
163+
164+ }
165+ } catch (java.lang.StringIndexOutOfBoundsException e) {
166+
167+ }
168+
169+ // length
170+ lenIndex = c % notelenKind.length;
171+ if (-1 != oldlenIndex) {
172+ int diff = oldlenIndex - lenIndex;
173+ diff = diff % si.maxLengthRange;
174+ lenIndex = oldlenIndex + diff;
175+ DebugCommon.print("lenIndex = " + lenIndex);
176+ if (lenIndex < 0) {
177+ lenIndex = 2;
178+ } else if (lenIndex >= notelenKind.length) {
179+ lenIndex = notelenKind.length - 2;
180+ }
181+ }
182+ tickPos += notelenKind[lenIndex];
183+ oldlenIndex = lenIndex;
184+
185+ if (!isRest) {
186+ message = new ShortMessage();
187+ debugSetMessage(message, ShortMessage.NOTE_OFF, channel,
188+ nowPitch, velocity, tickPos);
189+ trk.add(new MidiEvent(message, tickPos));
190+
191+ sti.add(new SourceTrackInfo(ShortMessage.NOTE_OFF, tickPos,
192+ nowPitch, linepos, allcharpos + charpos));
193+ }
194+
195+ oldc = c;
196+
197+ }
198+
199+ }
200+
201+ // write to file
202+ if (null != f) {
203+ MidiSystem.write(seq, 0, f);
204+ }
205+
206+ MusicTheory.getMajorScaleNotes(si.getKey());
207+
208+ return sti;
209+
210+ }
211+
212+ private static char debugCharAt(String s, int pos) {
213+ char c = s.charAt(pos);
214+ DebugCommon.print(c);
215+ return c;
216+ }
217+
218+ private static void debugSetMessage(ShortMessage mes, int onoff,
219+ int channel, int pitch, int velocity, int tick)
220+ throws InvalidMidiDataException {
221+ DebugCommon.print("");
222+ DebugCommon.print("data = " + onoff + ", " + channel + ", " + pitch
223+ + ", " + velocity + ", " + tick);
224+ mes.setMessage(onoff, channel, pitch, velocity);
225+ }
226+
227+}
--- trunk/asom/src/com/momiage/app/asom/logic/SourceTrackInfo.java (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/logic/SourceTrackInfo.java (revision 4)
@@ -0,0 +1,75 @@
1+package com.momiage.app.asom.logic;
2+
3+public class SourceTrackInfo {
4+
5+ protected int mes = -1;
6+ protected int tick = -1;
7+ protected int pitch = -1;
8+ protected int line = -1;
9+ protected int charpos = -1;
10+
11+ public SourceTrackInfo(int mes, int tick, int pitch, int line, int charpos) {
12+ this.mes = mes;
13+ this.tick = tick;
14+ this.pitch = pitch;
15+ this.line = line;
16+ this.charpos = charpos;
17+ }
18+
19+ @Override
20+ public String toString() {
21+ StringBuffer sb = new StringBuffer();
22+ sb.append("mes = ");
23+ sb.append(mes);
24+ sb.append(", tick = ");
25+ sb.append(tick);
26+ sb.append(", pitch = ");
27+ sb.append(pitch);
28+ sb.append(", line = ");
29+ sb.append(line);
30+ sb.append(", charpos = ");
31+ sb.append(charpos);
32+ return sb.toString();
33+ }
34+
35+ public int getMes() {
36+ return mes;
37+ }
38+
39+ public void setMes(int mes) {
40+ this.mes = mes;
41+ }
42+
43+ public int getTick() {
44+ return tick;
45+ }
46+
47+ public void setTick(int tick) {
48+ this.tick = tick;
49+ }
50+
51+ public int getPitch() {
52+ return pitch;
53+ }
54+
55+ public void setPitch(int pitch) {
56+ this.pitch = pitch;
57+ }
58+
59+ public int getLine() {
60+ return line;
61+ }
62+
63+ public void setLine(int line) {
64+ this.line = line;
65+ }
66+
67+ public int getCharpos() {
68+ return charpos;
69+ }
70+
71+ public void setCharpos(int charpos) {
72+ this.charpos = charpos;
73+ }
74+
75+}
--- trunk/asom/src/com/momiage/app/asom/logic/MusicTheory.java (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/logic/MusicTheory.java (revision 4)
@@ -0,0 +1,77 @@
1+package com.momiage.app.asom.logic;
2+
3+import java.util.Hashtable;
4+import java.util.Set;
5+import java.util.TreeSet;
6+
7+import com.momiage.app.asom.common.DebugCommon;
8+
9+public class MusicTheory {
10+
11+ protected static final int majorScale[] = { 0, 2, 2, 1, 2, 2, 2, 1, };
12+
13+ protected static final int minorScale[] = { 0, 2, 1, 2, 2, 1, 2, 1, 1 };
14+
15+ protected static final int naturalMinorScale[] = { 0, 2, 1, 2, 2, 1, 2, 2, };
16+ protected static final int harmonicMinorScale[] = { 0, 2, 1, 2, 2, 1, 3, 1, };
17+
18+ protected static final String minorString = "m";
19+
20+ protected static final Hashtable<String, Integer> baseNotes = new Hashtable<String, Integer>();
21+ static {
22+ baseNotes.put("A", 57);
23+ baseNotes.put("A#", 58);
24+ baseNotes.put("Bb", 58);
25+ baseNotes.put("B", 59);
26+ baseNotes.put("Cb", 59);
27+ baseNotes.put("B#", 60);
28+ baseNotes.put("C", 60);
29+ baseNotes.put("C#", 61);
30+ baseNotes.put("Db", 61);
31+ baseNotes.put("D", 62);
32+ baseNotes.put("D#", 63);
33+ baseNotes.put("Eb", 63);
34+ baseNotes.put("E", 64);
35+ baseNotes.put("Fb", 64);
36+ baseNotes.put("E#", 65);
37+ baseNotes.put("F", 65);
38+ baseNotes.put("F#", 66);
39+ baseNotes.put("Gb", 66);
40+ baseNotes.put("G", 67);
41+ baseNotes.put("G#", 68);
42+ baseNotes.put("Ab", 68);
43+ }
44+
45+ protected static Set<Integer> getScaleNotes(int scale[], String key) {
46+
47+ DebugCommon.print(baseNotes.toString());
48+ DebugCommon.print(key);
49+
50+ int iBaseNote = baseNotes.get(key);
51+ iBaseNote -= (12 * 4);
52+
53+ Set<Integer> scaleSet = new TreeSet<Integer>();
54+
55+ int note = iBaseNote;
56+ int scaleIndex = 0;
57+ int scaleLen = scale.length;
58+ while (note < 120) {
59+ if (scaleIndex >= scaleLen) {
60+ scaleIndex = 0;
61+ }
62+ note += scale[scaleIndex++];
63+ scaleSet.add(new Integer(note));
64+ }
65+
66+ DebugCommon.print("scaleSet = " + scaleSet.toString());
67+ return scaleSet;
68+ }
69+
70+ public static Set<Integer> getMinorScaleNotes(String key) {
71+ return getScaleNotes(harmonicMinorScale, key);
72+ }
73+
74+ public static Set<Integer> getMajorScaleNotes(String key) {
75+ return getScaleNotes(majorScale, key);
76+ }
77+}
--- trunk/asom/src/com/momiage/app/asom/logic/SourceInfo.java (nonexistent)
+++ trunk/asom/src/com/momiage/app/asom/logic/SourceInfo.java (revision 4)
@@ -0,0 +1,101 @@
1+package com.momiage.app.asom.logic;
2+
3+import java.util.List;
4+
5+public class SourceInfo {
6+
7+ protected static final String startPointSig = "@@@ASOM_START_POINT";
8+
9+ protected static final String endPointSig = "@@@ASOM_END_POINT";
10+
11+ protected static final String tempoSig = "@@ASOM_Tempo=";
12+
13+ protected int tempo = 120;
14+
15+ protected static final String keySig = "@@ASOM_Key=";
16+
17+ protected String key = "A";
18+
19+ protected static final String startNoteSig = "@@ASOM_StartNote=";
20+
21+ protected String startNote = "A";
22+
23+ protected static final String maxNoteRangeSig = "@@ASOM_MaxNoteRange=";
24+
25+ protected int maxNoteRange = 11;
26+
27+ protected static final String maxLengthRangeSig = "@@ASOM_MaxLengthRange=";
28+
29+ protected int maxLengthRange = 3;
30+
31+ protected static final String scaleOutNoteRateSig = "@@ASOM_ScaleOutNoteRate=";
32+
33+ protected int scaleOutNoteRate = 0;
34+
35+ protected static final String instNoSig = "@@ASOM_InstrumentNo=";
36+
37+ protected int instNo = 12;
38+
39+ protected static final String restCharSig = "@@ASOM_RestChar=";
40+
41+ protected String restChar = ". (){}; ";
42+
43+ protected List<String> sourceBody = null;
44+
45+ /**
46+ * @return instNo を戻します。
47+ */
48+ public int getInstNo() {
49+ return instNo;
50+ }
51+
52+ /**
53+ * @return key を戻します。
54+ */
55+ public String getKey() {
56+ return key;
57+ }
58+
59+ /**
60+ * @return maxNoteRange を戻します。
61+ */
62+ public int getMaxNoteRange() {
63+ return maxNoteRange;
64+ }
65+
66+ /**
67+ * @return omitChar を戻します。
68+ */
69+ public String getRestChar() {
70+ return restChar;
71+ }
72+
73+ /**
74+ * @return scaleOutNoteRate を戻します。
75+ */
76+ public int getScaleOutNoteRate() {
77+ return scaleOutNoteRate;
78+ }
79+
80+ /**
81+ * @return sourceBody を戻します。
82+ */
83+ public List<String> getSourceBody() {
84+ return sourceBody;
85+ }
86+
87+ /**
88+ * @return startNote を戻します。
89+ */
90+ public String getStartNote() {
91+ return startNote;
92+ }
93+
94+ /**
95+ * @return tempo を戻します。
96+ */
97+ public int getTempo() {
98+ return tempo;
99+ }
100+
101+}
--- trunk/asom/build.xml (nonexistent)
+++ trunk/asom/build.xml (revision 4)
@@ -0,0 +1,35 @@
1+<?xml version="1.0" encoding="UTF-8" ?>
2+
3+<project default="dist">
4+
5+ <property name="src.dir" value="src" />
6+ <property name="output.dir" value="exec/lib" />
7+ <property name="classes.dir" value="bin" />
8+
9+ <target name="clean">
10+ <delete dir="${classes.dir}" />
11+ <delete dir="${output.dir}" />
12+ <mkdir dir="${classes.dir}" />
13+ <mkdir dir="${output.dir}" />
14+ </target>
15+
16+ <target name="compile" depends="clean">
17+
18+ <javac srcdir="${src.dir}"
19+ destdir="${classes.dir}"
20+ encoding="MS932"
21+ debug="on"
22+ debuglevel="lines"
23+ />
24+
25+
26+ </target>
27+
28+ <target name="dist" depends="compile">
29+
30+ <jar destfile="${output.dir}/asom.jar"
31+ basedir="${classes.dir}" index="true"/>
32+
33+ </target>
34+
35+</project>
Show on old repository browser