anonymous No title
No License Python
2020年09月26日
Copy
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Dimension;

import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.sound.sampled.*;

public class SynthAkira extends JFrame {

  public static void main(String[] args){

		SynthAkira akira = new SynthAkira("Synth Akira");
		akira.setVisible(true);
  }

  SynthAkira(String title){
    setTitle(title);
    setBounds(100, 100, 600, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container contentPane = getContentPane();
    contentPane.add(new SynthSlider(), BorderLayout.PAGE_START);
    contentPane.add(new DrawCurve(), BorderLayout.CENTER);
	}
}

class SynthSlider extends JPanel implements ChangeListener {

  JSlider slider1;
  JSlider slider2;
  JPanel p1;
  JPanel p2;
  JPanel p3;
  	JPanel p4;
  	JButton b1;
  JButton b2;
  JLabel label1;
  JLabel label2;
  
  	static byte[] wave_data = new byte[44100];
  
	SynthSlider() {
		
		slider1 = new JSlider(0, 1000);
    slider1.setValue(100);
    slider1.addChangeListener(this);
    slider2 = new JSlider(0, 1000);
    slider2.setValue(100);
    slider2.addChangeListener(this);

    p1 = new JPanel();
    p1.add(slider1);
    p1.add(slider2);

    b1 = new JButton("DOWN");
    b2 = new JButton("UP");
    
    p2 = new JPanel();
    p2.add(b1);
    p2.add(b2);
    
    label1 = new JLabel();
    label2 = new JLabel();
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());

    p3 = new JPanel();
    p3.add(label1);
    p3.add(label2);

    p4 = new JPanel();
// 		p4.setPreferredSize(new Dimension(600, 400));
    p4.setLayout(new BorderLayout());
    p4.add(p1, BorderLayout.PAGE_START);
    p4.add(p2, BorderLayout.CENTER);
    p4.add(p3, BorderLayout.PAGE_END);

		add(p4);

    b1.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound(1);
		  }
		});
    b2.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound(2);
		  }
		});
	}

   void setSound(int j){
      try{
          double l1 = j*slider1.getValue()/44100.0;
         double l2 = j*slider2.getValue()/44100.0;
         for(int i=0;i<wave_data.length;i++){
            wave_data[i]= (byte)(110*(wave_data.length-(i+1))/wave_data.length*Math.sin((i*l1)*Math.PI*2)
            *Math.sin((i*l2)*Math.PI*2));
            			}
         AudioFormat   frmt= new AudioFormat(44100,8,1,true,false);
         DataLine.Info info= new DataLine.Info(Clip.class,frmt);
         Clip          clip= (Clip)AudioSystem.getLine(info);
         clip.open(frmt,wave_data,0,wave_data.length);
         clip.start();
	         }
      catch(Exception e){e.printStackTrace(System.err);}
      }

	public void stateChanged(ChangeEvent e) {
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());
	}
}

class DrawCurve extends JPanel { 

	JButton b1;
	Paint paint;
	JPanel p1;

	DrawCurve() { 

		p1 = new JPanel();
      b1 = new JButton ("PUSH");
     b1.setPreferredSize(new Dimension(100, 30));
      paint = new Paint();
     paint.setPreferredSize(new Dimension(600, 200));
     	p1.setPreferredSize(new Dimension(600, 300));
		p1.add(b1);
		p1.add(paint);
		add(p1);

     b1.addActionListener(new ActionListener() {
	      @Override
	      public void actionPerformed(ActionEvent e) {
		 		paint.repaint();
			}
		}); 
	 } 
}

class Paint extends JPanel {
	
	byte[] wave_data = SynthSlider.wave_data;
	
	public Paint() {
		super();
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(Color.RED);
		for(int i = 0; i < (wave_data.length/200-1); i++) {
    			g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
 		}
	}
} 
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Dimension;

import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.sound.sampled.*;

public class SynthAkira extends JFrame {

  public static void main(String[] args){

		SynthAkira akira = new SynthAkira("Synth Akira");
		akira.setVisible(true);
  }

  SynthAkira(String title){
    setTitle(title);
    setBounds(100, 100, 600, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container contentPane = getContentPane();
    contentPane.add(new SynthSlider(), BorderLayout.PAGE_START);
    contentPane.add(new DrawCurve(), BorderLayout.CENTER);
	}
}

class SynthSlider extends JPanel implements ChangeListener {

  JSlider slider1;
  JSlider slider2;
  JPanel p1;
  JPanel p2;
  JPanel p3;
  	JPanel p4;
  	JButton b1;
  JButton b2;
  JLabel label1;
  JLabel label2;
  
  	static byte[] wave_data = new byte[44100];
  
	SynthSlider() {
		
		slider1 = new JSlider(0, 1000);
    slider1.setValue(100);
    slider1.addChangeListener(this);
    slider2 = new JSlider(0, 1000);
    slider2.setValue(100);
    slider2.addChangeListener(this);

    p1 = new JPanel();
    p1.add(slider1);
    p1.add(slider2);

    b1 = new JButton("DOWN");
    b2 = new JButton("UP");
    
    p2 = new JPanel();
    p2.add(b1);
    p2.add(b2);
    
    label1 = new JLabel();
    label2 = new JLabel();
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());

    p3 = new JPanel();
    p3.add(label1);
    p3.add(label2);

    p4 = new JPanel();
// 		p4.setPreferredSize(new Dimension(600, 400));
    p4.setLayout(new BorderLayout());
    p4.add(p1, BorderLayout.PAGE_START);
    p4.add(p2, BorderLayout.CENTER);
    p4.add(p3, BorderLayout.PAGE_END);

		add(p4);

    b1.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound(1);
		  }
		});
    b2.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound(2);
		  }
		});
	}

   void setSound(int j){
      try{
          double l1 = j*slider1.getValue()/44100.0;
         double l2 = j*slider2.getValue()/44100.0;
         for(int i=0;i<wave_data.length;i++){
            wave_data[i]= (byte)(110*(wave_data.length-(i+1))/wave_data.length*Math.sin((i*l1)*Math.PI*2)
            *Math.sin((i*l2)*Math.PI*2));
            			}
         AudioFormat   frmt= new AudioFormat(44100,8,1,true,false);
         DataLine.Info info= new DataLine.Info(Clip.class,frmt);
         Clip          clip= (Clip)AudioSystem.getLine(info);
         clip.open(frmt,wave_data,0,wave_data.length);
         clip.start();
	         }
      catch(Exception e){e.printStackTrace(System.err);}
      }

	public void stateChanged(ChangeEvent e) {
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());
	}
}

class DrawCurve extends JPanel { 

	JButton b1;
	Paint paint;
	JPanel p1;

	DrawCurve() { 

		p1 = new JPanel();
      b1 = new JButton ("PUSH");
     b1.setPreferredSize(new Dimension(100, 30));
      paint = new Paint();
     paint.setPreferredSize(new Dimension(600, 200));
     	p1.setPreferredSize(new Dimension(600, 300));
		p1.add(b1);
		p1.add(paint);
		add(p1);

     b1.addActionListener(new ActionListener() {
	      @Override
	      public void actionPerformed(ActionEvent e) {
		 		paint.repaint();
			}
		}); 
	 } 
}

class Paint extends JPanel {
	
	byte[] wave_data = SynthSlider.wave_data;
	
	public Paint() {
		super();
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(Color.RED);
		for(int i = 0; i < (wave_data.length/200-1); i++) {
    			g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
 		}
	}
} 

Output

Run
No one still commented. Please first comment.