package application.musicEditor; import java.awt.*; import java.awt.event.*; import javax.sound.midi.*; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import connector.PukiwikiApplet; import connector.PukiwikiJavaApplication; import connector.SaveButtonDebugFrame; //import javax.swing.JFrame; import java.io.*; //import java.net.HttpURLConnection; import java.net.HttpURLConnection; import java.net.URL; import java.util.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** * This code was edited or generated using CloudGarden's Jigloo * SWT/Swing GUI Builder, which is free for non-commercial * use. If Jigloo is being used commercially (ie, by a corporation, * company or business for any purpose whatever) then you * should purchase a license for each developer using Jigloo. * Please visit www.cloudgarden.com for details. * Use of Jigloo implies acceptance of these licensing terms. * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE. */ public class SoundEditor extends JFrame implements PukiwikiJavaApplication { JButton button1,button2; Image img,wimg; Graphics w,wx,wg; int s = 0; int dw,dh; int er = 0; String m = ""; JTextField tf1; JLabel melodyLabel; JLabel speedLabel; JLabel soundLabel; JTextField tf2; JTextField tf3; SaveButtonDebugFrame debugFrame; String t [][] = {//{" "," ","  ","43","000","0"}, {"A","a","ソ#","44","015","1"}, {"Z","z","ラ ","45","030","0"}, {"S","s","ラ#","46","045","1"}, {"X","x","シ ","47","060","0"}, {"C","c","ド ","48","090","0"}, {"F","f","ド#","49","105","1"}, {"V","v","レ ","50","120","0"}, {"G","g","レ#","51","135","1"}, {"B","b","ミ ","52","150","0"}, {"N","n","ファ ","53","180","0"}, {"J","j","ファ#","54","195","1"}, {"M","m","ソ ","55","210","0"}, {"K","k","ソ#","56","225","1"}, {",","<","ラ ","57","240","0"}, {"L","l","ラ#","58","255","1"}, {".",">","シ ","59","270","0"}, {"/","?","ド ","60","300","0"}, {":","*","ド#","61","315","1"}, {" "," ","  ","0","000","0"}}; Synthesizer synthe = null; Instrument instrs[] = null; Soundbank sb = null; MidiChannel midichs[] = null; int lastnote; public SoundEditor() { ////テキストボックスパネル作成 /* JPanel pnl[] = new JPanel[2]; JPanel speedPanel=new JPanel(); speedPanel.setLayout(new FlowLayout()); setSize(300,150); button1 = new JButton(); button1.setText("play"); button2 = new JButton(); button2.setText("save"); button1.addActionListener(this); button2.addActionListener(this); melodyLabel.setText("メロディー:"); speedLabel.setText("speed(msec.):"); soundLabel.setText("音階:"); pnl[0] = new JPanel(new GridLayout(3 , 2)); pnl[0].add(melodyLabel); pnl[0].add(tf1); pnl[0].add(speedLabel); pnl[0].add(tf2); pnl[0].add(soundLabel); pnl[0].add(tf3); getContentPane().add(pnl[0] , BorderLayout.NORTH); pnl[1] = new JPanel(new GridLayout(1 , 2)); pnl[1].add(button1); pnl[1].add(button2); getContentPane().add(pnl[1] , BorderLayout.SOUTH); this.repaint(); //add("North",tf1); tf1.requestFocus(); tf1.addKeyListener(this); repaint(); //add("South",button); */ try { { getContentPane().setLayout(null); } { melodyLabel=new JLabel(); getContentPane().add(melodyLabel); melodyLabel.setText("メロディー"); melodyLabel.setBounds(5, 1, 150, 25); } { tf1=new JTextField(); getContentPane().add(tf1); tf1.setBounds(210, 1, 207, 25); // tf1.requestFocus(); tf1.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent evt) { keyTypePerformed(evt); } public void keyPressed(KeyEvent evt) { } public void keyReleased(KeyEvent evt) { } }); } { speedLabel=new JLabel(); getContentPane().add(speedLabel); speedLabel.setText("再生スピードを入力(単位はms):"); speedLabel.setBounds(4, 29, 204, 25); } { tf2=new JTextField(); getContentPane().add(tf2); tf2.setBounds(210, 28, 207, 25); } { soundLabel=new JLabel(); getContentPane().add(soundLabel); soundLabel.setText("再生音:"); soundLabel.setBounds(4, 55, 150, 25); soundLabel.setToolTipText("\u518d\u751f\u97f3"); } { tf3=new JTextField(); getContentPane().add(tf3); tf3.setBounds(211, 56, 206, 25); } { button1=new JButton(); getContentPane().add(button1); button1.setText("play"); button1.setBounds(24, 87, 100, 30); button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { play(); } }); } { button2=new JButton(); getContentPane().add(button2); button2.setText("save"); button2.setBounds(124, 87, 100, 30); button2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if(debugFrame!=null) debugFrame.saveButtonActionPerformed(null); } }); } { this.setSize(445, 204); this.setTitle("music editor"); } } catch(Exception e){ e.printStackTrace(); } /* //////////////////compにcomp.txtを読み込む///////////////////////// try { // ターゲット URL url = new URL("http://evekes.net/comp/comp.txt"); // 接続オブジェクト HttpURLConnection http = (HttpURLConnection)url.openConnection(); // GET メソッド http.setRequestMethod("GET"); // 接続 http.connect(); // EUC-JP でリーダーを作成 InputStreamReader isr = new InputStreamReader(http.getInputStream(), "UTF8"); // 行単位で読み込む為の準備 BufferedReader br = new BufferedReader(isr); String comp; // BufferedReader は、readLine が null を返すと読み込み終了 while ( null != (comp = br.readLine() ) ) { // コマンドプロンプトに表示 System.out.println(comp); tf1 = new TextField(comp); } // 各々受け持ちクラスを閉じる br.close(); isr.close(); http.disconnect(); } catch( Exception e ) { } ///////////////////speedにspeed.txtを読み込む///////////////////////// try { // ターゲット URL url = new URL("http://evekes.net/comp/speed.txt"); // 接続オブジェクト HttpURLConnection http = (HttpURLConnection)url.openConnection(); // GET メソッド http.setRequestMethod("GET"); // 接続 http.connect(); // EUC-JP でリーダーを作成 InputStreamReader isr = new InputStreamReader(http.getInputStream(), "EUC-JP"); // 行単位で読み込む為の準備 BufferedReader br = new BufferedReader(isr); String speed; // BufferedReader は、readLine が null を返すと読み込み終了 while ( null != (speed = br.readLine() ) ) { // コマンドプロンプトに表示 System.out.println(speed); tf2 = new TextField(speed); } // 各々受け持ちクラスを閉じる br.close(); isr.close(); http.disconnect(); } catch( Exception e ) { } */ /*c:/comp/下にファイルを保存する場合は以下のプログラムを使用する。 //////////////////compにcomp.txtを読み込む///////////////////////// try{ File file = new File("c:/comp/comp.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String comp; while((comp = br.readLine()) != null){ System.out.println("アプレット起動直後のcomp(comp.txt)の中身:"+comp); tf1 = new TextField(comp); } br.close(); } catch(FileNotFoundException e3){ System.out.println(e3); } catch(IOException e3){ System.out.println(e3); } ///////////////////speedにspeed.txtを読み込む///////////////////////// try{ File file = new File("c:/comp/speed.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String speed; while((speed= br.readLine()) != null){ System.out.println("アプレット起動直後のspeed(speed.txt)の中身:"+speed); tf2 = new TextField(speed); } br.close(); } catch(FileNotFoundException e3){ System.out.println(e3); } catch(IOException e3){ System.out.println(e3); } c:/comp/下にファイルを保存する場合は以上のプログラムを使用する。*/ // getContentPane().setLayout(new BorderLayout()); try { if ((synthe = MidiSystem.getSynthesizer()) == null) { System.out.println("getsynthesizer() failed"); er = 1; repaint();return; } synthe.open(); } catch (Exception e) {e.printStackTrace();} midichs = synthe.getChannels(); sb = synthe.getDefaultSoundbank(); instrs = sb.getInstruments(); if(instrs.length==0) {System.out.println("getDefaultSoundbank()failed");} if(synthe.loadInstrument(instrs[0])) {} else{System.out.println("loadInstrument failed");} // getContentPane().setBounds(10,10,200,200); } ///////////////////////////////////PLAY////////////////////////////////////////////////////////// void play(){ int note = 0; s=0; String str1; String str2; str1 = tf1.getText(); str2 = tf2.getText(); int bpm=100; try{ // bpm = Integer.valueOf(str2).intValue(); bpm=(new Integer(str2)).intValue(); } catch(Exception e){ System.out.println(""+e); System.out.println("tf2="+str2); } System.out.println("t.length="+t.length); System.out.println("文字列:"+str1); System.out.println("長さ:"+str1.length()); for(int a=0;a