--- jsampler/trunk/src/org/jsampler/task/Global.java 2008/09/11 18:48:36 1776 +++ jsampler/trunk/src/org/jsampler/task/Global.java 2009/03/16 22:12:32 1867 @@ -1,7 +1,7 @@ /* * JSampler - a java front-end for LinuxSampler * - * Copyright (C) 2005-2007 Grigor Iliev + * Copyright (C) 2005-2009 Grigor Iliev * * This file is part of JSampler. * @@ -22,14 +22,14 @@ package org.jsampler.task; -import java.util.logging.Level; - import org.jsampler.CC; -import org.jsampler.HF; +import org.linuxsampler.lscp.SamplerEngine; import org.linuxsampler.lscp.ServerInfo; import org.linuxsampler.lscp.Instrument; +import org.jsampler.SamplerModel; + import static org.jsampler.JSI18n.i18n; @@ -41,10 +41,41 @@ /** Forbits the instantiation of this class. */ private Global() { } + + /** + * Establishes connection to LinuxSampler. + */ + public static class Connect extends EnhancedTask { + /** Creates a new instance of Connect. */ + public + Connect() { + setTitle("Global.Connect_task"); + setDescription(i18n.getMessage("Global.Connect.desc")); + } + + /** The entry point of the task. */ + @Override + public void + exec() throws Exception { CC.getClient().connect(); } + } + + public static class Disconnect extends EnhancedTask { + /** Creates a new instance of Disconnect. */ + public + Disconnect() { + setSilent(true); + setTitle("Global.Disconnect_task"); + setDescription("Disconnecting..."); + } + + /** The entry point of the task. */ + @Override + public void + exec() throws Exception { CC.getClient().disconnect(); } + } /** * This task retrieves information about the LinuxSampler instance. - * @author Grigor Iliev */ public static class GetServerInfo extends EnhancedTask { /** Creates a new instance of GetServerInfo. */ @@ -55,19 +86,13 @@ } /** The entry point of the task. */ + @Override public void - run() { - try { setResult(CC.getClient().getServerInfo()); } - catch(Exception x) { - setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); - CC.getLogger().log(Level.FINE, getErrorMessage(), x); - } - } + exec() throws Exception { setResult(CC.getClient().getServerInfo()); } } /** * This task resets the whole sampler. - * @author Grigor Iliev */ public static class ResetSampler extends EnhancedTask { /** Creates a new instance of ResetSampler. */ @@ -78,14 +103,26 @@ } /** The entry point of the task. */ + @Override public void - run() { - try { CC.getClient().resetSampler(); } - catch(Exception x) { - setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); - CC.getLogger().log(Level.FINE, getErrorMessage(), x); - } + exec() throws Exception { CC.getClient().resetSampler(); } + } + + /** + * This task retrieves the list of all available engines. + */ + public static class GetEngines extends EnhancedTask { + /** Creates a new instance of GetEngines. */ + public + GetEngines() { + setTitle("Global.GetEngines_task"); + setDescription(i18n.getMessage("Global.GetEngines.desc")); } + + /** The entry point of the task. */ + @Override + public void + exec() throws Exception { setResult(CC.getClient().getEngines()); } } /** @@ -100,14 +137,9 @@ } /** The entry point of the task. */ + @Override public void - run() { - try { setResult(CC.getClient().getVolume()); } - catch(Exception x) { - setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); - CC.getLogger().log(Level.FINE, getErrorMessage(), x); - } - } + exec() throws Exception { setResult(CC.getClient().getVolume()); } } @@ -129,14 +161,78 @@ } /** The entry point of the task. */ + @Override public void - run() { - try { - CC.getClient().setVolume(volume); - } catch(Exception x) { - setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); - CC.getLogger().log(Level.FINE, getErrorMessage(), x); - } + exec() throws Exception { CC.getClient().setVolume(volume); } + } + + + /** + * This task sets the global sampler-wide limits of maximum voices and streams. + */ + public static class SetPolyphony extends EnhancedTask { + private int maxVoices; + private int maxStreams; + + /** + * Creates new instance of SetPolyphony. + * @param maxVoices The new global limit of maximum voices or + * -1 to ignore it. + * @param maxStreams The new global limit of maximum disk streams or + * -1 to ignore it. + */ + public + SetPolyphony(int maxVoices, int maxStreams) { + setTitle("Global.SetPolyphony_task"); + setDescription(i18n.getMessage("Global.SetPolyphony.desc")); + this.maxVoices = maxVoices; + this.maxStreams = maxStreams; + } + + /** The entry point of the task. */ + @Override + public void + exec() throws Exception { + if(maxVoices != -1) CC.getClient().setGlobalVoiceLimit(maxVoices); + if(maxStreams != -1) CC.getClient().setGlobalStreamLimit(maxStreams); + } + } + + /** + * This task updates the current number of all active voices + * and the maximum number of active voices allowed. + */ + public static class UpdateTotalVoiceCount extends EnhancedTask { + /** Creates a new instance of UpdateTotalVoiceCount. */ + public + UpdateTotalVoiceCount() { + setSilent(true); + setTitle("Global.UpdateTotalVoiceCount_task"); + setDescription(i18n.getMessage("Global.UpdateTotalVoiceCount.desc")); + } + + /** The entry point of the task. */ + @Override + public void + exec() throws Exception { + SamplerModel sm = CC.getSamplerModel(); + int voices = CC.getClient().getTotalVoiceCount(); + int voicesMax = CC.getClient().getTotalVoiceCountMax(); + sm.updateActiveVoiceInfo(voices, voicesMax); + } + + /** + * Used to decrease the traffic. All task in the queue + * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}. + * @see org.jsampler.CC#addTask + */ + @Override + public boolean + equals(Object obj) { + if(obj == null) return false; + if(!(obj instanceof UpdateTotalVoiceCount)) return false; + + return true; } } @@ -159,15 +255,9 @@ } /** The entry point of the task. */ + @Override public void - run() { - try { - CC.getClient().setSoTimeout(timeout * 1000); - } catch(Exception x) { - setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); - CC.getLogger().log(Level.FINE, getErrorMessage(), x); - } - } + exec() throws Exception { CC.getClient().setSoTimeout(timeout * 1000); } } /** @@ -179,19 +269,17 @@ /** Creates a new instance of GetFileInstruments. */ public GetFileInstruments(String filename) { + setSilent(true); this.filename = filename; setTitle("Global.GetFileInstruments_task"); setDescription(i18n.getMessage("Global.GetFileInstruments.desc")); } /** The entry point of the task. */ + @Override public void - run() { - try { setResult(CC.getClient().getFileInstruments(filename)); } - catch(Exception x) { - String s = getDescription() + ": " + HF.getErrorMessage(x); - CC.getLogger().log(Level.FINE, s, x); - } + exec() throws Exception { + setResult(CC.getClient().getFileInstruments(filename)); } } @@ -205,6 +293,7 @@ /** Creates a new instance of GetFileInstrument. */ public GetFileInstrument(String filename, int instrIdx) { + setSilent(true); this.filename = filename; this.instrIdx = instrIdx; setTitle("Global.GetFileInstrument_task"); @@ -212,17 +301,15 @@ } /** The entry point of the task. */ + @Override public void - run() { - try { setResult(CC.getClient().getFileInstrumentInfo(filename, instrIdx)); } - catch(Exception x) { - String s = getDescription() + ": " + HF.getErrorMessage(x); - CC.getLogger().log(Level.FINE, s, x); - } + exec() throws Exception { + setResult(CC.getClient().getFileInstrumentInfo(filename, instrIdx)); } } public static class DummyTask extends EnhancedTask { + @Override public void run() { } }