/[svn]/jsampler/trunk/src/org/jsampler/CC.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/CC.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1914 by iliev, Sun Apr 5 09:15:35 2009 UTC revision 1915 by iliev, Thu Jun 11 09:35:29 2009 UTC
# Line 25  package org.jsampler; Line 25  package org.jsampler;
25  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
26  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
27    
 import java.io.ByteArrayOutputStream;  
28  import java.io.File;  import java.io.File;
29  import java.io.FileInputStream;  import java.io.FileInputStream;
30  import java.io.FileOutputStream;  import java.io.FileOutputStream;
# Line 61  import org.jsampler.event.OrchestraListe Line 60  import org.jsampler.event.OrchestraListe
60  import org.jsampler.task.*;  import org.jsampler.task.*;
61    
62  import org.jsampler.view.InstrumentsDbTreeModel;  import org.jsampler.view.InstrumentsDbTreeModel;
 import org.jsampler.view.JSChannel;  
 import org.jsampler.view.JSChannelsPane;  
63  import org.jsampler.view.JSMainFrame;  import org.jsampler.view.JSMainFrame;
64  import org.jsampler.view.JSProgress;  import org.jsampler.view.JSProgress;
65  import org.jsampler.view.JSViewConfig;  import org.jsampler.view.JSViewConfig;
66    
 import org.linuxsampler.lscp.AudioOutputChannel;  
 import org.linuxsampler.lscp.AudioOutputDevice;  
67  import org.linuxsampler.lscp.Client;  import org.linuxsampler.lscp.Client;
68  import org.linuxsampler.lscp.FxSend;  import org.linuxsampler.lscp.FxSend;
 import org.linuxsampler.lscp.MidiInputDevice;  
 import org.linuxsampler.lscp.MidiPort;  
 import org.linuxsampler.lscp.Parameter;  
 import org.linuxsampler.lscp.SamplerChannel;  
69    
70  import org.linuxsampler.lscp.event.*;  import org.linuxsampler.lscp.event.*;
71    
# Line 323  public class CC { Line 314  public class CC {
314                  });                  });
315          }          }
316                    
         /**  
          * Checks whether the JSampler home directory is specified and exist.  
          * If the JSampler home directory is not specifed, or is specified  
          * but doesn't exist, a procedure of specifying a JSampler home  
          * directory is initiated.  
          * @see org.jsampler.view.JSMainFrame#installJSamplerHome  
          */  
         public static void  
         checkJSamplerHome() {  
                 if(getJSamplerHome() != null) {  
                         File f = new File(getJSamplerHome());  
                         if(f.exists() && f.isDirectory()) {  
                                 return;  
                         }  
                 }  
                   
                 getMainFrame().installJSamplerHome();  
         }  
           
         /**  
          * Changes the JSampler's home directory and moves all files from  
          * the old JSampler's home directory to the new one. If all files are  
          * moved succesfully, the old directory is deleted.  
          * @param path The location of the new JSampler's home directory. If  
          * the last directory in the path doesn't exist, it is created.  
          */  
         public static void  
         changeJSamplerHome(String path) {  
                 File fNew = new File(path);  
                 if(fNew.exists() && fNew.isFile()) {  
                         HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!"));  
                         return;  
                 }  
                   
                 if(!fNew.exists()) {  
                         if(!fNew.mkdir()) {  
                                 String s = fNew.getAbsolutePath();  
                                 HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s));  
                                 return;  
                         }  
                 }  
                   
                 if(getJSamplerHome() == null || path.equals(getJSamplerHome())) {  
                         setJSamplerHome(fNew.getAbsolutePath());  
                         return;  
                 }  
                   
                 File fOld = new File(getJSamplerHome());  
                 if(!fOld.exists() || !fOld.isDirectory()) {  
                         setJSamplerHome(fNew.getAbsolutePath());  
                         return;  
                 }  
                   
                 File[] files = fOld.listFiles();  
                 boolean b = true;  
                 if(files != null) {  
                         String s = fNew.getAbsolutePath() + File.separator;  
                         for(File f : files) if(!f.renameTo(new File(s + f.getName()))) b = false;  
                 }  
                   
                 if(b) fOld.delete();  
                 setJSamplerHome(fNew.getAbsolutePath());  
         }  
           
317          private final static OrchestraListModel orchestras = new DefaultOrchestraListModel();          private final static OrchestraListModel orchestras = new DefaultOrchestraListModel();
318                    
319          /**          /**
# Line 1006  public class CC { Line 933  public class CC {
933                  }                  }
934          }          }
935                    
         public static String  
         exportInstrMapsToLscpScript() {  
                 StringBuffer sb = new StringBuffer("# Exported by: ");  
                 sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: ");  
                 sb.append(JSampler.VERSION).append("\r\n");  
                 sb.append("# Date: ").append(new java.util.Date().toString()).append("\r\n\r\n");  
                   
                 Client lscpClient = new Client(true);  
                 ByteArrayOutputStream out = new ByteArrayOutputStream();  
                 lscpClient.setPrintOnlyModeOutputStream(out);  
                   
                 exportInstrMapsToLscpScript(lscpClient);  
                 sb.append(out.toString());  
                 out.reset();  
                   
                 return sb.toString();  
         }  
           
         private static void  
         exportInstrMapsToLscpScript(Client lscpClient) {  
                 try {  
                         lscpClient.removeAllMidiInstrumentMaps();  
                         MidiInstrumentMap[] maps = getSamplerModel().getMidiInstrumentMaps();  
                         for(int i = 0; i < maps.length; i++) {  
                                 lscpClient.addMidiInstrumentMap(maps[i].getName());  
                                 exportInstrumentsToLscpScript(i, maps[i], lscpClient);  
                         }  
                 } catch(Exception e) {  
                         getLogger().log(Level.FINE, HF.getErrorMessage(e), e);  
                         HF.showErrorMessage(e);  
                 }  
         }  
           
         private static void  
         exportInstrumentsToLscpScript(int mapId, MidiInstrumentMap map, Client lscpClient)  
                                                                                 throws Exception {  
           
                 boolean b = preferences().getBoolProperty(JSPrefs.LOAD_MIDI_INSTRUMENTS_IN_BACKGROUND);  
                   
                 for(MidiInstrument i : map.getAllMidiInstruments()) {  
                         lscpClient.mapMidiInstrument(mapId, i.getInfo().getEntry(), i.getInfo(), b);  
                 }  
         }  
           
         public static String  
         exportSessionToLscpScript() {  
                 getSamplerModel().setModified(false);  
                   
                 StringBuffer sb = new StringBuffer("# Exported by: ");  
                 sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: ");  
                 sb.append(JSampler.VERSION).append("\r\n");  
                 sb.append("# Date: ").append(new java.util.Date().toString()).append("\r\n\r\n");  
                   
                 Client lscpClient = new Client(true);  
                 ByteArrayOutputStream out = new ByteArrayOutputStream();  
                 lscpClient.setPrintOnlyModeOutputStream(out);  
                   
                 try {  
                         lscpClient.resetSampler();  
                         sb.append(out.toString());  
                         out.reset();  
                         sb.append("\r\n");  
                         lscpClient.setVolume(getSamplerModel().getVolume());  
                         sb.append(out.toString());  
                         out.reset();  
                         sb.append("\r\n");  
                 } catch(Exception e) { getLogger().log(Level.FINE, HF.getErrorMessage(e), e); }  
                                   
                 MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices();  
                 for(int i = 0; i < mDevs.length; i++) {  
                         exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient);  
                         sb.append(out.toString());  
                         out.reset();  
                         sb.append("\r\n");  
                 }  
                   
                 AudioDeviceModel[] aDevs = getSamplerModel().getAudioDevices();  
                 for(int i = 0; i < aDevs.length; i++) {  
                         exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient);  
                         sb.append(out.toString());  
                         out.reset();  
                         sb.append("\r\n");  
                 }  
                   
                 boolean b = preferences().getBoolProperty(JSPrefs.EXPORT_MIDI_MAPS_TO_SESSION_SCRIPT);  
                 if(b) {  
                         exportInstrMapsToLscpScript(lscpClient);  
                         sb.append(out.toString());  
                         out.reset();  
                         sb.append("\r\n");  
                 }  
   
                 int chnId = 0;  
                 for(JSChannelsPane cp : CC.getMainFrame().getChannelsPaneList()) {  
                         for(JSChannel chn : cp.getChannels()) {  
                                 SamplerChannelModel scm;  
                                 scm = getSamplerModel().getChannelById(chn.getChannelId());  
                                 exportChannelToLscpScript(scm.getChannelInfo(), chnId, lscpClient);  
                                 sb.append(out.toString());  
                                 out.reset();  
   
                                 sb.append("\r\n");  
   
                                 exportFxSendsToLscpScript(scm, chnId, lscpClient);  
                                 sb.append(out.toString());  
                                 out.reset();  
   
                                 sb.append("\r\n");  
   
                                 chnId++;  
                         }  
                 }  
                   
                 sb.append(getViewConfig().exportSessionViewConfig());  
                   
                 return sb.toString();  
         }  
           
         private static void  
         exportMidiDeviceToLscpScript(MidiInputDevice mid, int devId, Client lscpCLient) {  
                 try {  
                         String s = mid.getDriverName();  
                         lscpCLient.createMidiInputDevice(s, mid.getAdditionalParameters());  
                           
                         MidiPort[] mPorts = mid.getMidiPorts();  
                         int l = mPorts.length;  
                         if(l != 1) lscpCLient.setMidiInputPortCount(devId, l);  
                           
                         for(int i = 0; i < l; i++) {  
                                 Parameter[] prms = mPorts[i].getAllParameters();  
                                 for(Parameter p : prms) {  
                                         if(!p.isFixed() && p.getStringValue().length() > 0)  
                                                 lscpCLient.setMidiInputPortParameter(devId, i, p);  
                                 }  
                         }  
                 } catch(Exception e) {  
                         getLogger().log(Level.FINE, HF.getErrorMessage(e), e);  
                 }  
         }  
           
         private static void  
         exportAudioDeviceToLscpScript(AudioOutputDevice aod, int devId, Client lscpCLient) {  
                 try {  
                         String s = aod.getDriverName();  
                         lscpCLient.createAudioOutputDevice(s, aod.getAllParameters());  
                           
                         AudioOutputChannel[] chns = aod.getAudioChannels();  
                           
                         for(int i = 0; i < chns.length; i++) {  
                                 Parameter[] prms = chns[i].getAllParameters();  
                                 for(Parameter p : prms) {  
                                         if(p.isFixed() || p.getStringValue().length() == 0);  
                                         else lscpCLient.setAudioOutputChannelParameter(devId, i, p);  
                                 }  
                         }  
                 } catch(Exception e) {  
                         getLogger().log(Level.FINE, HF.getErrorMessage(e), e);  
                 }  
         }  
           
         private static void  
         exportChannelToLscpScript(SamplerChannel chn, int chnId, Client lscpCLient) {  
                 try {  
                         lscpCLient.addSamplerChannel();  
                           
                         SamplerModel sm = getSamplerModel();  
                         int id = chn.getMidiInputDevice();  
                         if(id != -1) {  
                                 for(int i = 0; i < sm.getMidiDeviceCount(); i++) {  
                                         if(sm.getMidiDevice(i).getDeviceId() == id) {  
                                                 lscpCLient.setChannelMidiInputDevice(chnId, i);  
                                                 break;  
                                         }  
                                 }  
                                 lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort());  
                                 lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel());  
                         }  
                           
                         if(chn.getEngine() != null) {  
                                 lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId);  
                                 lscpCLient.setChannelVolume(chnId, chn.getVolume());  
                                 int mapId = chn.getMidiInstrumentMapId();  
                                 lscpCLient.setChannelMidiInstrumentMap(chnId, mapId);  
                         }  
                           
                         id = chn.getAudioOutputDevice();  
                         if(id != -1) {  
                                 for(int i = 0; i < sm.getAudioDeviceCount(); i++) {  
                                         if(sm.getAudioDevice(i).getDeviceId() == id) {  
                                                 lscpCLient.setChannelAudioOutputDevice(chnId, i);  
                                                 break;  
                                         }  
                                 }  
                                   
                                 Integer[] routing = chn.getAudioOutputRouting();  
                                   
                                 for(int j = 0; j < routing.length; j++) {  
                                         int k = routing[j];  
                                         if(k == j) continue;  
                                           
                                         lscpCLient.setChannelAudioOutputChannel(chnId, j, k);  
                                 }  
                         }  
                           
                         String s = chn.getInstrumentFile();  
                         int i = chn.getInstrumentIndex();  
                         if(s != null) lscpCLient.loadInstrument(s, i, chnId, true);  
                           
                         if(chn.isMuted() && !chn.isMutedBySolo()) lscpCLient.setChannelMute(chnId, true);  
                         if(chn.isSoloChannel()) lscpCLient.setChannelSolo(chnId, true);  
                 } catch(Exception e) {  
                         getLogger().log(Level.FINE, HF.getErrorMessage(e), e);  
                 }  
         }  
           
         private static void  
         exportFxSendsToLscpScript(SamplerChannelModel scm, int chnId, Client lscpClient) {  
                 try {  
                         FxSend[] fxSends = scm.getFxSends();  
                           
                         for(int i = 0; i < fxSends.length; i++) {  
                                 FxSend f = fxSends[i];  
                                 lscpClient.createFxSend(chnId, f.getMidiController(), f.getName());  
                                 lscpClient.setFxSendLevel(chnId, i, f.getLevel());  
                                   
                                 Integer[] r = f.getAudioOutputRouting();  
                                 for(int j = 0; j < r.length; j++) {  
                                         lscpClient.setFxSendAudioOutputChannel(chnId, i, j, r[j]);  
                                 }  
                         }  
                 } catch(Exception e) {  
                         getLogger().log(Level.FINE, HF.getErrorMessage(e), e);  
                 }  
         }  
           
936          public static void          public static void
937          scheduleInTaskQueue(final Runnable r) {          scheduleInTaskQueue(final Runnable r) {
938                  Task dummy = new Global.DummyTask();                  Task dummy = new Global.DummyTask();

Legend:
Removed from v.1914  
changed lines
  Added in v.1915

  ViewVC Help
Powered by ViewVC