jDrum rhythm emulator studios

 3r31220. 3r3-31. Preface: I have a studio equipped, in the studio I decided to purchase electronic midi drums, an instrument with pads from the line: medeli, akai, novation.
 3r31220.
 3r31220. Linux (Ubuntu) is installed on the computer for development, the software mentioned above devices are not supported in Linux, and there are no problems with wine and virtual machine or switching between operating systems.
 3r31220.
 3r31220. I decided to develop a simple tool for writing rhythms.
 3r31220.
 3r31220. 3r314.
 3r31220. Download and test the program can be via this link. .
 3r31220.
 3r31220. Designing 3r348.
 3r31220. Designing began with drawing the interface in NetBeans: 3r3-31208.  3r31220. 3r330.
 3r31220.
 3r31220. [b] The principle of operation 3r348.
 3r31220. The active text field for loading a sample into a line.
 3r31220. 16 buttons when you click on which plays a sample set to the line.
 3r31220. The Play button plays sounds by speakers with samples installed on them with a certain delay (if a sample is set on the line and the button is pressed).
 3r31220.
 3r31220. [b] The code is clearly

 3r31220.
 3r31220. JDrum.java This class contains:
 3r31220. 1. Run the frame.
 3r31220. 2. The main part of logic.
 3r31220. 3. Sets of variables.
 3r31220.
 3r31220. 3r31079. 3r31080. /* 3r31220. * To change this license header, choose License Headers in Project Properties. 3r31220. * To change this template file, choose Tools | Templates 3r31220. * and open the template in the editor. 3r31220. * /
package jdrum; 3r31220. 3r31220. import java.io.BufferedReader; 3r31220. import java.io.File; 3r31220. import java.io.InputStreamReader; 3r31220. import java.util.Arrays; 3r31220. import java.util.List; 3r31220. 3r31220. /** 3r31220. * 3r31220. * @author dj DNkey
* /
public class JDrum {
/** 3r31220. * pads values ​​
* /
public static int[]pads = {3r31220. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0
}; 3r31220. 3r31220. /* 3r31220. * pads in line 1
* /
public static Integer[]line1Pads = {?????????1?1?1?1?1?1?16}; 3r31220. /** 3r31220. * pads in line 2
* /
public static Integer[]line2Pads = {1?1?1?2?2?2?2?2?2?2?2?2?2?3?3?32}; 3r31220. /** 3r31220. * pads in line 3
* /
public static Integer[]line3Pads = {3?3?3?3?3?3?3?4?4?4?4?4?4?4?4?48}; 3r31220. /** 3r31220. * pads in line 4
* /
public static Integer[]line4Pads = {4?5?5?5?5?5?5?5?5?5?5?6?6?6?6?64}; 3r31220. /** 3r31220. * pads in line 5
* /
public static Integer[]line5Pads = {6?6?6?6?6?7?7?7?7?7?7?7?7?7?7?80}; 3r31220. /** 3r31220. * pads in line 6
* /
public static Integer[]line6Pads = {8?8?8?8?8?8?8?8?8?9?9?9?9?9?9?96}; 3r31220. 3r31220. 3r31220. /** 3r31220. * pads in column 1
* /
public static int[]column1 = {?1?3?4?6?81}; 3r31220. 3r31220. /** 3r31220. * pads in column 2
* /
public static int[]column2 = {?1?3?5?6?82}; 3r31220. /** 3r31220. * pads in column 3
* /
public static int[]column3 = {?1?3?5?6?83}; 3r31220. /** 3r31220. * pads in column 4
* /
public static int[]column4 = {?2?3?5?6?84}; 3r31220. /** 3r31220. * pads in column 5
* /
public static int[]column5 = {5.2?3?5?6?85}; 3r31220. /** 3r31220. * pads in column 6
* /
public static int[]column6 = {?2?3?5?7?86}; 3r31220. /** 3r31220. * pads in column 7
* /
public static int[]column7 = {?2?3?5?7?87}; 3r31220. /** 3r31220. * pads in column 8
* /
public static int[]column8 = {?2?4?5?7?88}; 3r31220. /** 3r31220. * pads in column 9
* /
public static int[]column9 = {?2?4?5?7?89}; 3r31220. /** 3r31220. * pads in column 10
* /
public static int[]column10 = {1?2?4?5?7?90}; 3r31220. /** 3r31220. * pads in column 11
* /
public static int[]column11 = {1?2?4?5?7?91}; 3r31220. /** 3r31220. * pads in column 12
* /
public static int[]column12 = {1?2?4?6?7?92}; 3r31220. /** 3r31220. * pads in column 13
* /
public static int[]column13 = {1?2?4?6?7?93}; 3r31220. /** 3r31220. * pads in column 14
* /
public static int[]column14 = {1?3?4?6?7?94}; 3r31220. /** 3r31220. * pads in column 15
* /
public static int[]column15 = {1?3?4?6?7?95}; 3r31220. /** 3r31220. * pads in column 16
* /
public static int[]column16 = {1?3?4?6?8?96}; 3r31220. 3r31220. 3r31220. /** 3r31220. * Sound files bind on lines 1-10
* /
3r31220. public static Sound line1Sound = null; 3r31220. 3r31220. public static Sound line2Sound = null; 3r31220. 3r31220. public static Sound line3Sound = null; 3r31220. 3r31220. public static Sound line4Sound = null; 3r31220. 3r31220. public static Sound line5Sound = null; 3r31220. 3r31220. public static Sound line6Sound = null; 3r31220. 3r31220. 3r31220. 3r31220. /** 3r31220. * play speed 3r31220. * /
public static int speed = 35; 3r31220. 3r31220. 3r31220. public static boolean play = false; 3r31220. 3r31220. public static Main frame; 3r31220. 3r31220. 3r31220. 3r31220. /** 3r31220. * 3r31220. * @param args the command line arguments
* /
public static void main (String[]args) {3r31220. 3r31220. new Player (). start (); 3r31220. 3r31220. frame = new Main (); 3r31220. 3r31220. frame.setVisible (true); 3r31220. 3r31220. 3r31220.}
/** 3r31220. * Play object Sound in new Thread
* @param sound
* /
public static synchronized void play (Sound sound) {
3r31220. if (sound! = null) {
3r31220. new PlaySound (sound) .start (); 3r31220. 3r31220. 3r31220.}
3r31220.}
3r31220. public static synchronized void loadSound (File file) {
//sound
}
3r31220. /** 3r31220. * Play pressed pad
* @param padNum
* /
public static synchronized void playPad (int padNum) {
3r31220. //change pads value 1 to ? 0 to 1
3r31220. if (pads[padNum - 1]== 0) {3r31220. JDrum.pads[padNum - 1]= 1; 3r31220.} else {
JDrum.pads[padNum - 1]= 0; 3r31220.}
3r31220. /** 3r31220. * Check line 3r31220. * /
3r31220. 3r31220. if (pads[padNum - 1]== 1) {3r31220. playLine (padNum); 3r31220.}
3r31220.}
3r31220. /** 3r31220. * play sound file on line where press pad
* @param padNum
* /
public static synchronized void playLine (int padNum) {
int line = getPadLine (padNum); 3r31220. 3r31220. /** 3r31220. * Play sound from line
* /
3r31220. 3r31220. if (line == 1) {3r31220. JDrum.play (line1Sound); 3r31220.}
3r31220. if (line == 2) {3r31220. JDrum.play (line2Sound); 3r31220.}
3r31220. if (line == 3) {3r31220. JDrum.play (line3Sound); 3r31220.}
3r31220. if (line == 4) {3r31220. JDrum.play (line4Sound); 3r31220.}
3r31220. if (line == 5) {3r31220. JDrum.play (line5Sound); 3r31220.}
3r31220. if (line == 6) {3r31220. JDrum.play (line6Sound); 3r31220.}
3r31220.}
3r31220. /** 3r31220. * get line of pressed pad
* @param padNum
* @return
* /
public static synchronized int getPadLine (int padNum) {
3r31220. int line = 0; 3r31220. 3r31220. List
list; 3r31220. 3r31220. 3r31220. list = Arrays.asList (line1Pads); 3r31220. 3r31220. if (list.contains (padNum)) {3r31220.             line = 1; 3r31220.}
3r31220. 3r31220. list = Arrays.asList (line2Pads); 3r31220. 3r31220. if (list.contains (padNum)) {3r31220. line = 2; 3r31220.}
3r31220. 3r31220. list = Arrays.asList (line3Pads); 3r31220. 3r31220. if (list.contains (padNum)) {3r31220. line = 3; 3r31220.}
3r31220. 3r31220. list = Arrays.asList (line4Pads); 3r31220. 3r31220. if (list.contains (padNum)) {3r31220. line = 4; 3r31220.}
3r31220. 3r31220. list = Arrays.asList (line5Pads); 3r31220. 3r31220. if (list.contains (padNum)) {3r31220. line = 5; 3r31220.}
3r31220. 3r31220. 3r31220. list = Arrays.asList (line6Pads); 3r31220. 3r31220. if (list.contains (padNum)) {3r31220. line = 6; 3r31220.}
3r31220. return line; 3r31220.}
3r31220. /** 3r31220. * Save JDrum project to file .drum
* @param fileName
* /
public static void save (String fileName) {
3r31220. //load JDrum settings to save class
Save save = new Save (); 3r31220. 3r31220. save.pads = JDrum.pads; 3r31220. 3r31220. 3r31220. if (line1Sound! = null) {
save.line1Sound = line1Sound.file.getAbsolutePath (); 3r31220.}
3r31220. if (line2Sound! = null) {
3r31220. save.line2Sound = line2Sound.file.getAbsolutePath (); 3r31220.}
3r31220. if (line3Sound! = null) {
save.line3Sound = line3Sound.file.getAbsolutePath (); 3r31220.}
3r31220. if (line3Sound! = null) {
save.line4Sound = line4Sound.file.getAbsolutePath (); 3r31220.}
3r31220. if (line5Sound! = null) {
save.line5Sound = line5Sound.file.getAbsolutePath (); 3r31220.}
3r31220. if (line6Sound! = null) {
save.line6Sound = line6Sound.file.getAbsolutePath (); 3r31220.}
3r31220. save.save (fileName); 3r31220. 3r31220. 3r31220.}
3r31220. /** 3r31220. *
* @param filePath
* /
public static void open (String filePath) {
3r31220. Save save = new Save (); 3r31220. save = save.load (filePath); 3r31220. 3r31220. Sound sound; 3r31220. 3r31220. 3r31220. //line1Sound = new File (save.line1Sound); 3r31220. 3r31220. if (save.line1Sound! = null) {
3r31220. sound = new Sound (); 3r31220. 3r31220. sound.loadFile (new File (save.line1Sound)); 3r31220. 3r31220. line1Sound = sound; 3r31220. 3r31220. Main.jTextField1.setText (line1Sound.file.getName ()); 3r31220. 3r31220.}
3r31220. 3r31220. if (save.line2Sound! = null) {
3r31220. sound = new Sound (); 3r31220. 3r31220. sound.loadFile (new File (save.line2Sound)); 3r31220. 3r31220. line2Sound = sound; 3r31220. 3r31220. Main.jTextField2.setText (line2Sound.file.getName ()); 3r31220. 3r31220.}
3r31220. 3r31220. 3r31220. if (save.line3Sound! = null) {
3r31220. sound = new Sound (); 3r31220. 3r31220. sound.loadFile (new File (save.line3Sound)); 3r31220. 3r31220. line3Sound = sound; 3r31220. 3r31220. Main.jTextField3.setText (line3Sound.file.getName ()); 3r31220. 3r31220.}
3r31220. 3r31220. 3r31220. if (save.line4Sound! = null) {
3r31220. sound = new Sound (); 3r31220. 3r31220. sound.loadFile (new File (save.line4Sound)); 3r31220. 3r31220. line4Sound = sound; 3r31220. 3r31220. Main.jTextField4.setText (line4Sound.file.getName ()); 3r31220. 3r31220.}
3r31220. 3r31220. 3r31220. 3r31220. if (save.line5Sound! = null) {
sound = new Sound (); 3r31220. 3r31220. sound.loadFile (new File (save.line5Sound)); 3r31220. 3r31220. line5Sound = sound; 3r31220. 3r31220. Main.jTextField5.setText (line5Sound.file.getName ()); 3r31220. 3r31220.}
3r31220. 3r31220. if (save.line6Sound! = null) {
sound = new Sound (); 3r31220. 3r31220. sound.loadFile (new File (save.line6Sound)); 3r31220. 3r31220. line6Sound = sound; 3r31220. 3r31220. Main.jTextField6.setText (line6Sound.file.getName ()); 3r31220. 3r31220.}
3r31220. JDrum.pads = save.pads; 3r31220. 3r31220. frame.changeButton (JDrum.pads); 3r31220. 3r31220. 3r31220.}
3r31220. public static void startRecording () {
3r31220. String command = "audio-recorder -c start"; 3r31220. 3r31220. String output = executeCommand (command); 3r31220. 3r31220.}
3r31220. public static void stopRecording () {3r31220. 3r31220. String command = "audio-recorder -c stop"; 3r31220. 3r31220. String output = executeCommand (command); 3r31220. 3r31220.}
3r31220. public static String executeCommand (String command) {
3r31220. StringBuffer output = new StringBuffer (); 3r31220. 3r31220. Process p; 3r31220. try {3r31220. p = Runtime.getRuntime (). exec (command); 3r31220. p.waitFor (); 3r31220. BufferedReader reader =
new BufferedReader (new InputStreamReader (p.getInputStream ())); 3r31220. 3r31220. String line = ""; 3r31220. while ((line = reader.readLine ())! = null) {
output.append (line + "n"); 3r31220.}
3r31220.} catch (Exception e) {
e.printStackTrace (); 3r31220.}
3r31220. return output.toString (); 3r31220. 3r31220.}
} 3r31185.
 3r31220.
 3r31220. Player.java daemon:
 3r31220. 1. Starting sounds on the speakers, if the sample is located on the line and the button is pressed.
 3r31220. 2. Player launches PlaySound classes that work out in a separate stream.
 3r31220. 3r31079. 3r31080. /* 3r31220. * To change this license header, choose License Headers in Project Properties. 3r31220. * To change this template file, choose Tools | Templates 3r31220. * and open the template in the editor. 3r31220. * /
package jdrum; 3r31220. 3r31220. import java.lang.reflect.Field; 3r31220. import java.util.logging.Level; 3r31220. import java.util.logging.Logger; 3r31220. import static jdrum.JDrum.playLine; 3r31220. 3r31220. /** 3r31220. * 3r31220. * @author nn
* /
public class Player extends Thread {
3r31220. Field field; 3r31220. String columnName; 3r31220. 3r31220. int[]column; 3r31220. 3r31220. public int step = 1; 3r31220. 3r31220. public int stopFlag = 0; 3r31220. 3r31220. public Player () {
3r31220. setDaemon (true); 3r31220.}
3r31220. 3r31220. public static int[]column1; 3r31220. 3r31220. public static int[]column2; 3r31220. 3r31220. public static int[]column3; 3r31220. 3r31220. public static int[]column4; 3r31220. 3r31220. public static int[]column5; 3r31220. 3r31220. public static int[]column6; 3r31220. 3r31220. public static int[]column7; 3r31220. 3r31220. public static int[]column8; 3r31220. 3r31220. public static int[]column9; 3r31220. 3r31220. public static int[]column10; 3r31220. 3r31220. public static int[]column11; 3r31220. 3r31220. public static int[]column12; 3r31220. 3r31220. public static int[]column13; 3r31220. 3r31220. public static int[]column14; 3r31220. 3r31220. public static int[]column15; 3r31220. 3r31220. public static int[]column16; 3r31220. 3r31220. 3r31220. public void run () {
3r31220. while (true) {
3r31220. if (JDrum.play) {3r31220. 3r31220. try {3r31220. 3r31220. //get column from JDrum by step 1-10
columnName = "column" + step; 3r31220. 3r31220. field = JDrum.class.getDeclaredField (columnName); 3r31220. 3r31220. field.setAccessible (true); 3r31220. 3r31220. 3r31220. column = (int[]) field.get (null); 3r31220. 3r31220. 3r31220. //play pads from column
for (int i = 0; i <= 5;i++ ){
//System.out.println(columnName);
if (JDrum.pads[column[i]- 1]== 1) {
3r31220. another w3w2w247) 3r31220.} 3r31220.} 3r312203 3r31220.
//next step
(stopFlag == 2) {
JDrum.play = false;
stopFlag = 0;
}
} 3r31220.} catch (IllegalArgumentException ex) {3r31220. Logger.getLogger (Player.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (IllegalAccessException ex) {3r31220. Logger.getLogger (Player.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (NoSuchFieldException ex) {3r31220. Logger.getLogger (Player.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (SecurityException ex) {3r31220. Logger.getLogger (Player.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.}
}
3r31220. 3r31220. //speed sleep
try {3r31220. sleep (JDrum.speed * 10); 3r31220.} catch (InterruptedException e) {3r31220. //handle exception here
}
}
}
3r31220.} 3r31185.
 3r31220.
 3r31220. PlaySound.java launch of sound (class Sound) in a separate stream
 3r31220.
 3r31220. 3r31079. 3r31080. 3r31220. /* 3r31220. * To change this license header, choose License Headers in Project Properties. 3r31220. * To change this template file, choose Tools | Templates 3r31220. * and open the template in the editor. 3r31220. * /
package jdrum; 3r31220. 3r31220. /** 3r31220. * 3r31220. * @author nn
* /
public class PlaySound extends Thread {
3r31220. public sound sound; 3r31220. 3r31220. 3r31220. public PlaySound (Sound sound) {
this.sound = sound; 3r31220.}
3r31220. public void run () {
if (sound! = null) {
sound.play (); 3r31220.}
}
3r31220.}
3r31184. 3r31185.
 3r31220.
 3r31220. Sound.java class audio playback
 3r31220.
 3r31220. 3r31079. 3r31080. /* 3r31220. * To change this license header, choose License Headers in Project Properties. 3r31220. * To change this template file, choose Tools | Templates 3r31220. * and open the template in the editor. 3r31220. * /
package jdrum; 3r31220. 3r31220. import java.io.File; 3r31220. import java.io.IOException; 3r31220. import javax.sound.sampled.AudioFormat; 3r31220. import javax.sound.sampled.AudioInputStream; 3r31220. import javax.sound.sampled.AudioSystem; 3r31220. import javax.sound.sampled.Clip; 3r31220. import javax.sound.sampled.DataLine; 3r31220. import javax.sound.sampled.LineUnavailableException; 3r31220. import javax.sound.sampled.SourceDataLine; 3r31220. 3r31220. /** 3r31220. * 3r31220. * @author nn
* /
public class Sound {3r31220. 3r31220. public boolean playCompleted; 3r31220. 3r31220. 3r31220. public file file; 3r31220. public AudioInputStream stream; 3r31220. public AudioFormat format; 3r31220. public DataLine.Info info; 3r31220. public Clip clip; 3r31220. 3r31220. 3r31220. private final int BUFFER_SIZE = 128000; 3r31220. private file soundFile; 3r31220. private AudioInputStream audioStream; 3r31220. private AudioFormat audioFormat; 3r31220. private SourceDataLine sourceLine; 3r31220. 3r31220. public void loadFile (File file) {
this.file = file; 3r31220. 3r31220.}
3r31220. public void play () {
if (file! = null) {
3r31220. soundFile = file; 3r31220. 3r31220. 3r31220. try {3r31220. audioStream = AudioSystem.getAudioInputStream (soundFile); 3r31220.} catch (Exception e) {
e.printStackTrace (); 3r31220. System.exit (1); 3r31220.}
3r31220. audioFormat = audioStream.getFormat (); 3r31220. 3r31220. DataLine.Info info = new DataLine.Info (SourceDataLine.class, audioFormat); 3r31220. 3r31220. if (! AudioSystem.isLineSupported (info)) {3r31220. System.out.println ("Line not supported" + info); 3r31220.}
3r31220. try {3r31220. sourceLine = (SourceDataLine) AudioSystem.getLine (info); 3r31220. //
sourceLine.open (audioFormat); 3r31220.} catch (LineUnavailableException e) {
e.printStackTrace (); 3r31220. System.exit (1); 3r31220.} catch (Exception e) {
e.printStackTrace (); 3r31220. System.exit (1); 3r31220.}
3r31220. sourceLine.start (); 3r31220. 3r31220. 3r31220. 3r31220. int nBytesRead = 0; 3r31220. byte[]abData = new byte[BUFFER_SIZE]; 3r31220. while (nBytesRead! = -1) {
try {3r31220. nBytesRead = audioStream.read (abData, ? abData.length); 3r31220.} catch (IOException e) {
e.printStackTrace (); 3r31220.}
if (nBytesRead> = 0) {
@SuppressWarnings ("unused")
int nBytesWritten = sourceLine.write (abData, ? nBytesRead); 3r31220.}
}
3r31220. 3r31220. 3r31220. /** 3r31220. try {3r31220. Clip clip = new Clip (); 3r31220. 3r31220. int waitTime = (int) Math.ceil (clip.getMicrosecondLength () /1000.0); 3r31220. Thread.sleep (waitTime); 3r31220.} catch (InterruptedException ex) {3r31220. Logger.getLogger (Sound.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (LineUnavailableException ex) {
Logger.getLogger (Sound.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.}
** /
3r31220. sourceLine.drain (); 3r31220. sourceLine.close (); 3r31220.}
3r31220.}
3r31220. 3r31220.}
3r31184. 3r31185.
 3r31220.
 3r31220. Spreading Main.java will not be there generating interfaces using NetBeans, only some interesting points:
 3r31220.
 3r31220. 3r31079. 3r31080. public Main () {
3r31220. 3r31220. initComponents (); 3r31220. 3r31220. //bind load sample
jTextField1.addMouseListener (new SampleEvent (? this)); 3r31220. jTextField2.addMouseListener (new SampleEvent (? this)); 3r31220. jTextField3.addMouseListener (new SampleEvent (? this)); 3r31220. jTextField4.addMouseListener (new SampleEvent (? this)); 3r31220. jTextField5.addMouseListener (new SampleEvent (? this)); 3r31220. jTextField6.addMouseListener (new SampleEvent (? this)); 3r31220. 3r31220. 3r31220. 3r31220. //bind pad click
Field field; 3r31220. JButton dynamicButton; 3r31220. 3r31220. try {3r31220. 3r31220. for (int buttonNum = 1; buttonNum <= 96; buttonNum++) {
field = this.getClass (). getDeclaredField ("jButton" + buttonNum);
field.setAccessible (true);
dynamicButton = (JButton) field.get (this); current
DynamicButton.setMargin (new Insets (? ? ? 0));
DynamicButton.addMouseListener (new PadEvent (buttonNum, this)); 3r3r???; ) {
Logger.getLogger (Main.class.getName ()) log (Level.SEVERE, null, ex);
} Catch (SecurityException ex) {3r31220.         Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (IllegalArgumentException ex) {3r31220. Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (IllegalAccessException ex) {3r31220. Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.}
3r31220.} 3r31185.
 3r31220.
 3r31220. After initializing the components, you need to assign events to the buttons:
 3r31220. 1. Events rendered in separate classes.
 3r31220. 2. For event assignment for 96 buttons, the Reflection API is applied, which assigns events in the loop by name (name + i).
 3r31220.
 3r31220. SampleEvent.java
 3r31220. 3r31079. 3r31080. /* 3r31220. * To change this license header, choose License Headers in Project Properties. 3r31220. * To change this template file, choose Tools | Templates 3r31220. * and open the template in the editor. 3r31220. * /
package jdrum; 3r31220. 3r31220. import java.awt.event.MouseEvent; 3r31220. import java.awt.event.MouseListener; 3r31220. import java.io.File; 3r31220. import java.lang.reflect.Field; 3r31220. import java.util.logging.Level; 3r31220. import java.util.logging.Logger; 3r31220. import javax.swing.JFileChooser; 3r31220. import javax.swing.JTextField; 3r31220. import javax.swing.filechooser.FileNameExtensionFilter; 3r31220. 3r31220. /** 3r31220. * 3r31220. * @author nn
* /
public class SampleEvent implements MouseListener {
3r31220. public int fieldNum; 3r31220. Main frame; 3r31220. 3r31220. public SampleEvent (int fieldNum, Main frame) {3r31220. this.fieldNum = fieldNum; 3r31220. this.frame = frame; 3r31220.}
3r31220. public void mouseClicked (MouseEvent evt) {
if (evt.getButton () == MouseEvent.BUTTON1) {
JFileChooser fileopen = new JFileChooser (); 3r31220. 3r31220. fileopen.setCurrentDirectory (new java.io.File (System.getProperty ("user.dir"))); 3r31220. 3r31220. FileNameExtensionFilter filter = new FileNameExtensionFilter ("wav", "wav"); 3r31220. fileopen.setFileFilter (filter); 3r31220. 3r31220. 3r31220. 3r31220. int ret = fileopen.showDialog (null, "Open file"); 3r31220. if (ret == JFileChooser.APPROVE_OPTION) {
3r31220. 3r31220. try {3r31220. File file = fileopen.getSelectedFile (); 3r31220. 3r31220. 3r31220. //setup file name to sample field
Field field = frame.getClass (). GetDeclaredField ("jTextField" + fieldNum); 3r31220. field.setAccessible (true); 3r31220. JTextField value = (JTextField) field.get (this); 3r31220. 3r31220. value.setText (file.getName ()); 3r31220. 3r31220. 3r31220. Sound sound = new Sound (); 3r31220. 3r31220. sound.loadFile (file); 3r31220. 3r31220. //play 3r31220. JDrum.play (sound); 3r31220. 3r31220. 3r31220. //setup path
Field f = JDrum.class.getField ("line" + fieldNum + "Sound"); 3r31220. f.setAccessible (true); 3r31220. 3r31220. f.set (null, sound); 3r31220. 3r31220. 3r31220. 3r31220. //System.out.print (JDrum.line1SoundFile); 3r31220. //set full path
3r31220. //System.out.println (file.getAbsolutePath ()); 3r31220.} catch (SecurityException | IllegalArgumentException ex) {
Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (NoSuchFieldException ex) {3r31220. Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (IllegalAccessException ex) {3r31220. Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.}
3r31220.}
}
3r31220. if (evt.getButton () == MouseEvent.BUTTON3) {
3r31220. try {3r31220. Field field = frame.getClass (). GetDeclaredField ("jTextField" + fieldNum); 3r31220. field.setAccessible (true); 3r31220. JTextField value = (JTextField) field.get (this); 3r31220. 3r31220. value.setText (""); 3r31220. 3r31220. 3r31220. Field f = JDrum.class.getField ("line" + fieldNum + "SoundFile"); 3r31220. f.setAccessible (true); 3r31220. f.set (null, null); 3r31220. 3r31220.} catch (NoSuchFieldException ex) {3r31220. Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (SecurityException ex) {3r31220. Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (IllegalArgumentException ex) {3r31220. Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (IllegalAccessException ex) {3r31220. Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.}
3r31220. 3r31220.}
}
3r31220. @Override
public void mousePressed (MouseEvent e) {
//throw new UnsupportedOperationException ("Not supported yet."); //To change the body of generated methods, choose Tools | Templates. 3r31220.}
3r31220. @Override
public void mouseReleased (MouseEvent e) {
//throw new UnsupportedOperationException ("Not supported yet."); //To change the body of generated methods, choose Tools | Templates. 3r31220.}
3r31220. @Override
public void mouseEntered (MouseEvent e) {
//throw new UnsupportedOperationException ("Not supported yet."); //To change the body of generated methods, choose Tools | Templates. 3r31220.}
3r31220. @Override
public void mouseExited (MouseEvent e) {
//throw new UnsupportedOperationException ("Not supported yet."); //To change the body of generated methods, choose Tools | Templates. 3r31220.}
3r31220.} 3r31185.
 3r31220.
 3r31220. PadEvent.java
 3r31220.
 3r31220. 3r31079. 3r31080. /* 3r31220. * To change this license header, choose License Headers in Project Properties. 3r31220. * To change this template file, choose Tools | Templates 3r31220. * and open the template in the editor. 3r31220. * /
package jdrum; 3r31220. 3r31220. import java.awt.Color; 3r31220. import java.awt.event.ActionEvent; 3r31220. import java.awt.event.ActionListener; 3r31220. import java.awt.event.MouseEvent; 3r31220. import java.awt.event.MouseListener; 3r31220. import java.lang.reflect.Field; 3r31220. import java.util.logging.Level; 3r31220. import java.util.logging.Logger; 3r31220. import javax.swing.JButton; 3r31220. 3r31220. /** 3r31220. * 3r31220. * @author nn
* /
public class PadEvent implements MouseListener {
3r31220. public int pudNum; 3r31220. Main frame; 3r31220. 3r31220. public PadEvent (int pudNum, Main frame) {
this.pudNum = pudNum; 3r31220. this.frame = frame; 3r31220.}
3r31220. 3r31220. @Override
public void mouseClicked (MouseEvent evt) {
3r31220. if (evt.getButton () == MouseEvent.BUTTON1) {
3r31220. Field field; 3r31220. JButton dynamicButton; 3r31220. 3r31220. try {3r31220. //change pad color
field = frame.getClass (). getDeclaredField ("jButton" + pudNum); 3r31220. field.setAccessible (true); 3r31220. dynamicButton = (JButton) field.get (this); 3r31220. 3r31220. //change color and play pad
if (! dynamicButton.getBackground (). equals (new Color (14?14?145))) {
dynamicButton.setBackground (new Color (14?14?145)); 3r31220. 3r31220. 3r31220.} else {
dynamicButton.setBackground (null); 3r31220.}
//play pad 3r31220. JDrum.playPad (pudNum); 3r31220. 3r31220. 3r31220.} catch (SecurityException ex) {3r31220. Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (IllegalArgumentException ex) {3r31220. Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (IllegalAccessException ex) {3r31220. Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.} catch (NoSuchFieldException ex) {3r31220. Logger.getLogger (PadEvent.class.getName ()). Log (Level.SEVERE, null, ex); 3r31220.}
3r31220. 3r31220. //change the pad value from 1 to 0 or from 0 to 1
//start the sound assigned to the line 3r31220. //Change the color of the cc button green to serra and from gray to green
//System.out.println("press "+ pudNum); 3r31220. 3r31220. 3r31220. //change the pad value from 1 to 0 or from 0 to 1
//start the sound assigned to the line 3r31220. //Change the color of the cc button green to serra and from gray to green
//System.out.println("press "+ pudNum); 3r31220.}
}
3r31220. @Override
public void mousePressed (MouseEvent e) {
//throw new UnsupportedOperationException ("Not supported yet."); //To change the body of generated methods, choose Tools | Templates. 3r31220.}
3r31220. @Override
public void mouseReleased (MouseEvent e) {
//throw new UnsupportedOperationException ("Not supported yet."); //To change the body of generated methods, choose Tools | Templates. 3r31220.}
3r31220. @Override
public void mouseEntered (MouseEvent e) {
//throw new UnsupportedOperationException ("Not supported yet."); //To change the body of generated methods, choose Tools | Templates. 3r31220.}
3r31220. @Override
public void mouseExited (MouseEvent e) {
//throw new UnsupportedOperationException ("Not supported yet."); //To change the body of generated methods, choose Tools | Templates. 3r31220.}
3r31220.}
3r31184. 3r31185.
 3r31220.
 3r31220. Of course, like any other alpha version of the program, errors occur: 3r3-31208.  3r31220.
 3r31220. 3r31194. javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes /frame, little-endian not supported. at com.sun.media.sound.DirectAudioDevice $ DirectDL.implOpen (DirectAudioDevice.javaCl3) at com.sun.media.sound.AbstractDataLine.open (AbstractDataLine.java:121) at com.sun.media.sound.AbstractDataLine .open (AbstractDataLine.java:153) at jdrum.Sound.play (Sound.java:68) at jdrum.PlaySoundThread.run (PlaySoundThread.java:24) /home/nn/.cache/netbeans/8.2/executor-snippets /run.xml:53: Java returned: 1 BUILD FAILED (total time: 1 minute 57 seconds)
 3r31220. 3r31197.
 3r31220. The error occurs as I understand it after the multi-assignment and keystrokes due to the busy line.
 3r31220.
 3r31220. I think the further development of the program will be toward: 3r3-31208.  3r31220. 1 Changing the playback of wav files on midi.
 3r31220. 2 Additions of notes.
 3r31220. 3 Add changes to sounds in the track. 3r31216. 3r31220. 3r31220. 3r3r12313. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d,! 1): e.attachEvent ("onload", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r31214. 3r31220. 3r31216. 3r31220. 3r31220. 3r31220. 3r31220.
+ 0 -

Add comment