[recovery mode] jDrum эмулятор ритм студий

1b23d01c27253b911ed05672b524c933.jpg
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package jdrum;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

/**
 *
 * @author dj DNkey
 */
public class JDrum {
    /**
     * pads values
     */
    public static int[] pads = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    
    /*
    * pads in line 1
    */
    public  static Integer[] line1Pads = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
    /**
     * pads in line 2
     */
    public  static Integer[] line2Pads = {17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32};
    /**
     * pads in line 3
     */
    public  static Integer[] line3Pads = {33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48};
    /**
     * pads in line 4
     */
    public  static Integer[] line4Pads = {49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64};
    /**
     * pads in line 5
     */
    public  static Integer[] line5Pads = {65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80};
    /**
     * pads in line 6
     */
    public  static Integer[] line6Pads = {81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96};

    
    /**
     * pads in column 1
     */
    public  static int[] column1     = {1,17,33,49,65,81};
    
    /**
     * pads in column 2
     */
    public  static int[] column2     = {2,18,34,50,66,82};
    /**
     * pads in column 3
     */
    public  static int[] column3     = {3,19,35,51,67,83};
    /**
     * pads in column 4
     */
    public  static int[] column4     = {4,20,36,52,68,84};
    /**
     * pads in column 5
     */
    public  static int[] column5     = {5,21,37,53,69,85};
    /**
     * pads in column 6
     */
    public  static int[] column6     = {6,22,38,54,70,86};
    /**
     * pads in column 7
     */
    public  static int[] column7     = {7,23,39,55,71,87};
    /**
     * pads in column 8
     */
    public  static int[] column8     = {8,24,40,56,72,88};
    /**
     * pads in column 9
     */
    public  static int[] column9     = {9,25,41,57,73,89};
    /**
     * pads in column 10
     */
    public  static int[] column10    = {10,26,42,58,74,90};
    /**
     * pads in column 11
     */
    public  static int[] column11    = {11,27,43,59,75,91};
    /**
     * pads in column 12
     */
    public  static int[] column12    = {12,28,44,60,76,92};
        /**
     * pads in column 13
     */
    public  static int[] column13    = {13,29,45,61,77,93};
    /**
     * pads in column 14
     */
    public  static int[] column14    = {14,30,46,62,78,94};
    /**
     * pads in column 15
     */
    public  static int[] column15    = {15,31,47,63,79,95};
    /**
     * pads in column 16
     */
    public  static int[] column16    = {16,32,48,64,80,96};
    
    
    /**
     * Sound files bind on lines 1-10
     */
    
    public static Sound line1Sound  = null;
    
    public static Sound line2Sound  = null;
    
    public static Sound line3Sound  = null;

    public static Sound line4Sound  = null;

    public static Sound line5Sound = null;
    
    public static Sound line6Sound  = null;

    
    
    /**
     * play speed
     */
    public  static int speed    = 35;
    
    
    public  static boolean play = false;
    
    public static Main frame;
    
 
    
    /**
     * 
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        new Player().start();
        
        frame = new Main();
        
        frame.setVisible(true);
        
        
    }
    /**
     * Play object Sound in new Thread
     * @param sound 
     */
    public static synchronized void play(Sound sound){
        
        if(sound != null){
                     
           new PlaySound(sound).start();

          
        }
        
    }
    
     public static synchronized void  loadSound(File file){
       //  sound
     } 
     
     /**
      * Play pressed pad
      * @param padNum 
      */
     public static synchronized void  playPad(int padNum){
         
         //change pads value 1 to 0, 0 to 1
         
          if(pads[padNum - 1] == 0){
             JDrum.pads[padNum - 1] = 1;
          } else{
             JDrum.pads[padNum - 1] = 0;
          }
   
           /**
           * Check line
           */
         
          
          if(pads[padNum - 1] == 1){
             playLine(padNum);
          }

     }
     
     /**
      * play sound file on line where press pad
      * @param padNum 
      */
     public static synchronized void playLine(int padNum){
           int line = getPadLine(padNum);

           /**
           * Play sound from line
           */
                  
            
            if(line == 1){
                JDrum.play(line1Sound);
            }

            if(line == 2){
                JDrum.play(line2Sound);
            }

            if(line == 3){
                JDrum.play(line3Sound);
            }

            if(line == 4){
                JDrum.play(line4Sound);
            }

            if(line == 5){
                JDrum.play(line5Sound);
            }

            if(line == 6){
                JDrum.play(line6Sound);
            }

     }
     
     /**
      * get line of pressed pad
      * @param padNum
      * @return 
      */
     public static synchronized int getPadLine(int padNum){
          
          int line = 0;

          List list;
          
         
          list = Arrays.asList(line1Pads);
          
          if(list.contains(padNum)){
              line = 1;
          }
          
          
          list = Arrays.asList(line2Pads);
          
          if(list.contains(padNum)){
              line = 2;
          }
          
          
          list = Arrays.asList(line3Pads);
          
          if(list.contains(padNum)){
              line = 3;
          }
          
          
          list = Arrays.asList(line4Pads);
          
          if(list.contains(padNum)){
              line = 4;
          }
          
          
          list = Arrays.asList(line5Pads);
          
          if(list.contains(padNum)){
              line = 5;
          }
          
          
          
          list = Arrays.asList(line6Pads);
          
          if(list.contains(padNum)){
              line = 6;
          }
          
          return line;
     }
     
     /**
      * Save JDrum project to file .drum
      * @param fileName 
      */
     public static void save(String fileName){
         
        //load JDrum settings to save class
        Save save = new Save();
         
        save.pads = JDrum.pads;

        
        if(line1Sound != null){
            save.line1Sound  = line1Sound.file.getAbsolutePath();
        }
    
        if(line2Sound != null){

            save.line2Sound  = line2Sound.file.getAbsolutePath();
        }
        
        if(line3Sound != null){
            save.line3Sound  = line3Sound.file.getAbsolutePath();
        }
        
        if(line3Sound != null){
            save.line4Sound  = line4Sound.file.getAbsolutePath();
        }
        
        if(line5Sound != null){
            save.line5Sound  = line5Sound.file.getAbsolutePath();
        }
        
        if(line6Sound != null){
            save.line6Sound  = line6Sound.file.getAbsolutePath();
        }
 
        save.save(fileName);
        
        
     }
     
     /**
      * Open saved file and load to JDrum
      * @param filePath 
      */
     public static void open(String filePath){

        Save save = new Save();
        save = save.load(filePath);
        
        Sound sound;
        
        
        //line1Sound = new File(save.line1Sound);
        
        if(save.line1Sound != null){
        
            sound      = new Sound();

            sound.loadFile(new File(save.line1Sound));

            line1Sound = sound;
            
            Main.jTextField1.setText(line1Sound.file.getName());
        
        }
        
        
        if(save.line2Sound != null){
            
            sound      = new Sound();
                    
            sound.loadFile(new File(save.line2Sound));
    
            line2Sound = sound;
            
            Main.jTextField2.setText(line2Sound.file.getName());
            
        }

        
        
        if(save.line3Sound != null){
            
            sound      = new Sound();
                    
            sound.loadFile(new File(save.line3Sound));
    
            line3Sound = sound;
            
            Main.jTextField3.setText(line3Sound.file.getName());

        }
        
        
        
        if(save.line4Sound != null){
        
            sound      = new Sound();

            sound.loadFile(new File(save.line4Sound));

            line4Sound = sound;
            
            Main.jTextField4.setText(line4Sound.file.getName());

        }
        
        
        
        
        if(save.line5Sound != null){
            sound      = new Sound();
                    
            sound.loadFile(new File(save.line5Sound));
    
            line5Sound = sound;
            
            Main.jTextField5.setText(line5Sound.file.getName());

        }

        
        if(save.line6Sound != null){
            sound      = new Sound();
                    
            sound.loadFile(new File(save.line6Sound));
    
            line6Sound = sound;
            
            Main.jTextField6.setText(line6Sound.file.getName());

        }
        
        JDrum.pads = save.pads;
        
        frame.changeButton(JDrum.pads);

        
     }

    public static void startRecording() {
        
        String command = "audio-recorder -c start";
        
        String output  = executeCommand(command);

    }
    
    public static void stopRecording() {

        String command = "audio-recorder -c stop";
        
        String output = executeCommand(command);

    }
    
    public static String executeCommand(String command) {

                StringBuffer output = new StringBuffer();

                Process p;
                try {
                        p = Runtime.getRuntime().exec(command);
                        p.waitFor();
                        BufferedReader reader = 
                            new BufferedReader(new InputStreamReader(p.getInputStream()));

                        String line = "";                       
                        while ((line = reader.readLine())!= null) {
                                output.append(line + "\n");
                        }

                } catch (Exception e) {
                        e.printStackTrace();
                }

                return output.toString();

        }
}


© Habrahabr.ru