34 |
import java.util.logging.Level; |
import java.util.logging.Level; |
35 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
36 |
|
|
|
import static org.linuxsampler.lscp.Parser.*; |
|
37 |
import org.linuxsampler.lscp.event.*; |
import org.linuxsampler.lscp.event.*; |
38 |
|
|
39 |
|
import static org.linuxsampler.lscp.Parser.*; |
40 |
|
|
41 |
|
|
42 |
/** |
/** |
43 |
* This class is the abstraction representing a client endpoint for communication with LinuxSampler |
* This class is the abstraction representing a client endpoint for communication with LinuxSampler |
344 |
if(!llFSI.isEmpty()) subscribe("FX_SEND_INFO"); |
if(!llFSI.isEmpty()) subscribe("FX_SEND_INFO"); |
345 |
if(!llSC.isEmpty()) subscribe("STREAM_COUNT"); |
if(!llSC.isEmpty()) subscribe("STREAM_COUNT"); |
346 |
if(!llVC.isEmpty()) subscribe("VOICE_COUNT"); |
if(!llVC.isEmpty()) subscribe("VOICE_COUNT"); |
347 |
|
if(!llTSC.isEmpty()) subscribe("TOTAL_STREAM_COUNT"); |
348 |
if(!llTVC.isEmpty()) subscribe("TOTAL_VOICE_COUNT"); |
if(!llTVC.isEmpty()) subscribe("TOTAL_VOICE_COUNT"); |
349 |
if(!llMIMC.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_COUNT"); |
if(!llMIMC.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_COUNT"); |
350 |
if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO"); |
if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO"); |
355 |
subscribe("DB_INSTRUMENT_DIRECTORY_INFO"); |
subscribe("DB_INSTRUMENT_DIRECTORY_INFO"); |
356 |
subscribe("DB_INSTRUMENT_COUNT"); |
subscribe("DB_INSTRUMENT_COUNT"); |
357 |
subscribe("DB_INSTRUMENT_INFO"); |
subscribe("DB_INSTRUMENT_INFO"); |
358 |
|
subscribe("DB_INSTRUMENTS_JOB_INFO"); |
359 |
} |
} |
360 |
if(!llGI.isEmpty()) subscribe("GLOBAL_INFO"); |
if(!llGI.isEmpty()) subscribe("GLOBAL_INFO"); |
361 |
} |
} |
487 |
private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>(); |
private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>(); |
488 |
private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>(); |
private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>(); |
489 |
private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>(); |
private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>(); |
490 |
|
private final Vector<TotalStreamCountListener> llTSC = new Vector<TotalStreamCountListener>(); |
491 |
private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>(); |
private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>(); |
492 |
|
|
493 |
/** MIDI instrument map count listeners */ |
/** MIDI instrument map count listeners */ |
525 |
!llMIDI.isEmpty() || |
!llMIDI.isEmpty() || |
526 |
!llSC.isEmpty() || |
!llSC.isEmpty() || |
527 |
!llVC.isEmpty() || |
!llVC.isEmpty() || |
528 |
|
!llTSC.isEmpty() || |
529 |
!llTVC.isEmpty() || |
!llTVC.isEmpty() || |
530 |
!llMIMC.isEmpty() || |
!llMIMC.isEmpty() || |
531 |
!llMIMI.isEmpty() || |
!llMIMI.isEmpty() || |
547 |
if(s.startsWith("NAME ")) { |
if(s.startsWith("NAME ")) { |
548 |
String[] list; |
String[] list; |
549 |
try { |
try { |
550 |
list = parseQuotedStringList(s.substring("NAME ".length()), ' '); |
s = s.substring("NAME ".length()); |
551 |
|
list = parseEscapedStringList(s, ' '); |
552 |
if(list.length != 2) throw new LscpException(); |
if(list.length != 2) throw new LscpException(); |
553 |
|
list[1] = toNonEscapedString(list[1]); |
554 |
e = new InstrumentsDbEvent(this, list[0], list[1]); |
e = new InstrumentsDbEvent(this, list[0], list[1]); |
555 |
for(InstrumentsDbListener l : llID) { |
for(InstrumentsDbListener l : llID) { |
556 |
l.directoryNameChanged(e); |
l.directoryNameChanged(e); |
576 |
if(s.startsWith("NAME ")) { |
if(s.startsWith("NAME ")) { |
577 |
String[] list; |
String[] list; |
578 |
try { |
try { |
579 |
list = parseQuotedStringList(s.substring("NAME ".length()), ' '); |
s = s.substring("NAME ".length()); |
580 |
|
list = parseEscapedStringList(s, ' '); |
581 |
if(list.length != 2) throw new LscpException(); |
if(list.length != 2) throw new LscpException(); |
582 |
|
list[1] = toNonEscapedString(list[1]); |
583 |
e = new InstrumentsDbEvent(this, list[0], list[1]); |
e = new InstrumentsDbEvent(this, list[0], list[1]); |
584 |
for(InstrumentsDbListener l : llID) { |
for(InstrumentsDbListener l : llID) { |
585 |
l.instrumentNameChanged(e); |
l.instrumentNameChanged(e); |
666 |
} catch(NumberFormatException x) { |
} catch(NumberFormatException x) { |
667 |
getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x); |
getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x); |
668 |
} |
} |
669 |
|
} else if(s.startsWith("TOTAL_STREAM_COUNT:")) { |
670 |
|
try { |
671 |
|
s = s.substring("TOTAL_STREAM_COUNT:".length()); |
672 |
|
int i = Integer.parseInt(s); |
673 |
|
TotalStreamCountEvent e = new TotalStreamCountEvent(this, i); |
674 |
|
for(TotalStreamCountListener l : llTSC) l.totalStreamCountChanged(e); |
675 |
|
} catch(NumberFormatException x) { |
676 |
|
getLogger().log ( |
677 |
|
Level.WARNING, "Unknown TOTAL_STREAM_COUNT format", x |
678 |
|
); |
679 |
|
} |
680 |
} else if(s.startsWith("TOTAL_VOICE_COUNT:")) { |
} else if(s.startsWith("TOTAL_VOICE_COUNT:")) { |
681 |
try { |
try { |
682 |
s = s.substring("TOTAL_VOICE_COUNT:".length()); |
s = s.substring("TOTAL_VOICE_COUNT:".length()); |
1149 |
/** |
/** |
1150 |
* Registers the specified listener for receiving event messages. |
* Registers the specified listener for receiving event messages. |
1151 |
* Listeners can be registered regardless of the connection state. |
* Listeners can be registered regardless of the connection state. |
1152 |
|
* @param l The <code>TotalStreamCountListener</code> to register. |
1153 |
|
*/ |
1154 |
|
public synchronized void |
1155 |
|
addTotalStreamCountListener(TotalStreamCountListener l) { |
1156 |
|
if(llTSC.isEmpty()) subscribe("TOTAL_STREAM_COUNT"); |
1157 |
|
llTSC.add(l); |
1158 |
|
} |
1159 |
|
|
1160 |
|
/** |
1161 |
|
* Removes the specified listener. |
1162 |
|
* Listeners can be removed regardless of the connection state. |
1163 |
|
* @param l The <code>TotalStreamCountListener</code> to remove. |
1164 |
|
*/ |
1165 |
|
public synchronized void |
1166 |
|
removeTotalStreamCountListener(TotalStreamCountListener l) { |
1167 |
|
boolean b = llTSC.remove(l); |
1168 |
|
if(b && llTSC.isEmpty()) unsubscribe("TOTAL_STREAM_COUNT"); |
1169 |
|
} |
1170 |
|
|
1171 |
|
/** |
1172 |
|
* Registers the specified listener for receiving event messages. |
1173 |
|
* Listeners can be registered regardless of the connection state. |
1174 |
* @param l The <code>TotalVoiceCountListener</code> to register. |
* @param l The <code>TotalVoiceCountListener</code> to register. |
1175 |
*/ |
*/ |
1176 |
public synchronized void |
public synchronized void |
1455 |
args.append(' ').append(param); |
args.append(' ').append(param); |
1456 |
|
|
1457 |
for(Parameter p : deplist) { |
for(Parameter p : deplist) { |
1458 |
if(p.getValue() == null) continue; |
if(p == null || p.getName() == null || p.getValue() == null) continue; |
1459 |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
1460 |
} |
} |
1461 |
|
|
1519 |
StringBuffer args = new StringBuffer(aoDriver); |
StringBuffer args = new StringBuffer(aoDriver); |
1520 |
|
|
1521 |
for(Parameter p : paramList) { |
for(Parameter p : paramList) { |
1522 |
if(p.getValue() == null) continue; |
if(p == null || p.getName() == null || p.getValue() == null) continue; |
1523 |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
1524 |
} |
} |
1525 |
|
|
2041 |
args.append(' ').append(param); |
args.append(' ').append(param); |
2042 |
|
|
2043 |
for(Parameter p : deplist) { |
for(Parameter p : deplist) { |
2044 |
if(p.getValue() == null) continue; |
if(p == null || p.getName() == null || p.getValue() == null) continue; |
2045 |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
2046 |
} |
} |
2047 |
|
|
2106 |
StringBuffer args = new StringBuffer(miDriver); |
StringBuffer args = new StringBuffer(miDriver); |
2107 |
|
|
2108 |
for(Parameter p : paramList) { |
for(Parameter p : paramList) { |
2109 |
if(p.getValue() == null) continue; |
if(p == null || p.getName() == null || p.getValue() == null) continue; |
2110 |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
2111 |
} |
} |
2112 |
|
|
2253 |
mid.setActive(Boolean.parseBoolean(s)); |
mid.setActive(Boolean.parseBoolean(s)); |
2254 |
} else if(s.startsWith("PORTS: ")) { |
} else if(s.startsWith("PORTS: ")) { |
2255 |
s = s.substring("PORTS: ".length()); |
s = s.substring("PORTS: ".length()); |
2256 |
int ports = Parser.parseInt(s); |
|
2257 |
MidiPort[] midiPorts = new MidiPort[ports > 0 ? ports : 0]; |
Parameter<Integer> ports = (Parameter<Integer>) |
2258 |
|
getMidiInputDriverParameterInfo(drv, "PORTS"); |
2259 |
|
|
2260 |
|
ports.parseValue(s); |
2261 |
|
mid.setPortsParameter(ports); |
2262 |
|
|
2263 |
|
int j = ports.getValue(); |
2264 |
|
MidiPort[] midiPorts = new MidiPort[j > 0 ? j : 0]; |
2265 |
|
|
2266 |
for(int i = 0; i < midiPorts.length; i++) |
for(int i = 0; i < midiPorts.length; i++) |
2267 |
midiPorts[i] = getMidiInputPortInfo(deviceId, i); |
midiPorts[i] = getMidiInputPortInfo(deviceId, i); |
2504 |
public synchronized int |
public synchronized int |
2505 |
addMidiInstrumentMap(String name) throws IOException, LSException, LscpException { |
addMidiInstrumentMap(String name) throws IOException, LSException, LscpException { |
2506 |
verifyConnection(); |
verifyConnection(); |
2507 |
out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + name + "'"); |
out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + toEscapedString(name) + "'"); |
2508 |
if(getPrintOnlyMode()) return -1; |
if(getPrintOnlyMode()) return -1; |
2509 |
|
|
2510 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
2607 |
|
|
2608 |
for(String s : lnS) { |
for(String s : lnS) { |
2609 |
if(s.startsWith("NAME: ")) { |
if(s.startsWith("NAME: ")) { |
2610 |
name = s.substring("NAME: ".length()); |
name = toNonEscapedString(s.substring("NAME: ".length())); |
2611 |
} else if(s.startsWith("DEFAULT: ")) { |
} else if(s.startsWith("DEFAULT: ")) { |
2612 |
b = Boolean.parseBoolean(s.substring("DEFAULT: ".length())); |
b = Boolean.parseBoolean(s.substring("DEFAULT: ".length())); |
2613 |
} else { |
} else { |
2655 |
throws IOException, LscpException, LSException { |
throws IOException, LscpException, LSException { |
2656 |
|
|
2657 |
verifyConnection(); |
verifyConnection(); |
2658 |
|
name = toEscapedString(name); |
2659 |
out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " + + mapId + " '" + name + "'"); |
out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " + + mapId + " '" + name + "'"); |
2660 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
2661 |
|
|
2711 |
if(!info.getLoadMode().name().equals("DEFAULT")) { |
if(!info.getLoadMode().name().equals("DEFAULT")) { |
2712 |
cmd.append(' ').append(info.getLoadMode().name()); |
cmd.append(' ').append(info.getLoadMode().name()); |
2713 |
} |
} |
2714 |
if(info.getName() != null) cmd.append(" '").append(info.getName()).append("'"); |
|
2715 |
|
if(info.getName() != null) { |
2716 |
|
String s = toEscapedString(info.getName()); |
2717 |
|
cmd.append(" '").append(s).append("'"); |
2718 |
|
} |
2719 |
|
|
2720 |
out.writeLine(cmd.toString()); |
out.writeLine(cmd.toString()); |
2721 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
2804 |
} |
} |
2805 |
|
|
2806 |
/** |
/** |
2807 |
* Gets all MIDI instrument contained int the specified MIDI instrument map. |
* Gets all MIDI instrument entries contained int the specified MIDI instrument map. |
2808 |
|
* @param mapId The ID of the map, which instruments should be obtained. |
2809 |
|
* @return An int array providing all MIDI instrument entries |
2810 |
|
* in the specified MIDI instrument map. |
2811 |
|
* @throws IOException If some I/O error occurs. |
2812 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
2813 |
|
* @throws LSException If some other error occurs. |
2814 |
|
*/ |
2815 |
|
public synchronized int[][] |
2816 |
|
getMidiInstrumentEntries(int mapId) throws IOException, LscpException, LSException { |
2817 |
|
verifyConnection(); |
2818 |
|
out.writeLine("LIST MIDI_INSTRUMENTS " + String.valueOf(mapId)); |
2819 |
|
if(getPrintOnlyMode()) return null; |
2820 |
|
|
2821 |
|
String[] entries = parseArray(getSingleLineResultSet().getResult()); |
2822 |
|
int[][] e = new int[entries.length][3]; |
2823 |
|
|
2824 |
|
for(int i = 0; i < entries.length; i++) { |
2825 |
|
Integer[] vals = parseIntList(entries[i]); |
2826 |
|
if(vals.length != 3) { |
2827 |
|
throw new LscpException(LscpI18n.getLogMsg("CommandFailed!")); |
2828 |
|
} |
2829 |
|
|
2830 |
|
e[i][0] = vals[0]; |
2831 |
|
e[i][1] = vals[1]; |
2832 |
|
e[i][2] = vals[2]; |
2833 |
|
} |
2834 |
|
|
2835 |
|
return e; |
2836 |
|
} |
2837 |
|
|
2838 |
|
/** |
2839 |
|
* Gets all MIDI instruments contained int the specified MIDI instrument map. |
2840 |
* @param mapId The ID of the map, which instruments should be obtained. |
* @param mapId The ID of the map, which instruments should be obtained. |
2841 |
* @return A <code>MidiInstrumentInfo</code> array providing |
* @return A <code>MidiInstrumentInfo</code> array providing |
2842 |
* all MIDI instruments from all MIDI instrument maps. |
* all MIDI instruments in the specified MIDI instrument map. |
2843 |
* @throws IOException If some I/O error occurs. |
* @throws IOException If some I/O error occurs. |
2844 |
* @throws LscpException If LSCP protocol corruption occurs. |
* @throws LscpException If LSCP protocol corruption occurs. |
2845 |
* @throws LSException If some other error occurs. |
* @throws LSException If some other error occurs. |
2887 |
throws IOException, LscpException, LSException { |
throws IOException, LscpException, LSException { |
2888 |
|
|
2889 |
verifyConnection(); |
verifyConnection(); |
2890 |
|
requestMidiInstrumentInfo(mapId, bank, program); |
2891 |
|
return getMidiInstrumentInfoResponse(mapId, bank, program); |
2892 |
|
} |
2893 |
|
|
2894 |
|
private void |
2895 |
|
requestMidiInstrumentInfo(int mapId, int bank, int program) throws IOException { |
2896 |
StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO "); |
StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO "); |
2897 |
cmd.append(mapId).append(' '); |
cmd.append(mapId).append(' '); |
2898 |
cmd.append(bank).append(' '); |
cmd.append(bank).append(' '); |
2899 |
cmd.append(program); |
cmd.append(program); |
2900 |
|
|
2901 |
out.writeLine(cmd.toString()); |
out.writeLine(cmd.toString()); |
2902 |
if(getPrintOnlyMode()) return null; |
} |
2903 |
|
|
2904 |
|
private MidiInstrumentInfo |
2905 |
|
getMidiInstrumentInfoResponse(int mapId, int bank, int program) |
2906 |
|
throws IOException, LscpException, LSException { |
2907 |
|
|
2908 |
|
if(getPrintOnlyMode()) return null; |
2909 |
ResultSet rs = getMultiLineResultSet(); |
ResultSet rs = getMultiLineResultSet(); |
2910 |
MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program); |
MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program); |
2911 |
return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult()); |
return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult()); |
2954 |
loadInstrument(String filename, int instrIdx, int samplerChn, boolean nonModal) |
loadInstrument(String filename, int instrIdx, int samplerChn, boolean nonModal) |
2955 |
throws IOException, LscpException, LSException { |
throws IOException, LscpException, LSException { |
2956 |
|
|
|
filename = getEscapedString(filename); |
|
2957 |
String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT "; |
String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT "; |
2958 |
String args = '\'' + filename + "' " + instrIdx + ' ' + samplerChn; |
String args = '\'' + filename + "' " + instrIdx + ' ' + samplerChn; |
2959 |
|
|
3136 |
out.writeLine("LIST AVAILABLE_ENGINES"); |
out.writeLine("LIST AVAILABLE_ENGINES"); |
3137 |
if(getPrintOnlyMode()) return null; |
if(getPrintOnlyMode()) return null; |
3138 |
|
|
3139 |
return parseQuotedStringList(getSingleLineResultSet().getResult()); |
return parseStringList(getSingleLineResultSet().getResult()); |
3140 |
} |
} |
3141 |
|
|
3142 |
/** |
/** |
3607 |
|
|
3608 |
verifyConnection(); |
verifyConnection(); |
3609 |
String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl); |
String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl); |
3610 |
if(name != null) s += " '" + name + "'"; |
if(name != null) s += " '" + toEscapedString(name) + "'"; |
3611 |
out.writeLine("CREATE FX_SEND " + s); |
out.writeLine("CREATE FX_SEND " + s); |
3612 |
if(getPrintOnlyMode()) return -1; |
if(getPrintOnlyMode()) return -1; |
3613 |
|
|
3738 |
throws IOException, LscpException, LSException { |
throws IOException, LscpException, LSException { |
3739 |
|
|
3740 |
verifyConnection(); |
verifyConnection(); |
3741 |
String args = " " + channel + " " + fxSend + " '" + name + "'"; |
String args = " " + channel + " " + fxSend + " '" + toEscapedString(name) + "'"; |
3742 |
out.writeLine("SET FX_SEND NAME" + args); |
out.writeLine("SET FX_SEND NAME" + args); |
3743 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
3744 |
|
|
3837 |
* @see #getSamplerChannels |
* @see #getSamplerChannels |
3838 |
*/ |
*/ |
3839 |
public synchronized void |
public synchronized void |
3840 |
editInstrument(int samplerChn) throws IOException, LscpException, LSException { |
editChannelInstrument(int samplerChn) throws IOException, LscpException, LSException { |
3841 |
verifyConnection(); |
verifyConnection(); |
3842 |
out.writeLine("EDIT INSTRUMENT " + samplerChn); |
out.writeLine("EDIT CHANNEL INSTRUMENT " + samplerChn); |
3843 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
3844 |
|
|
3845 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
3849 |
|
|
3850 |
/** |
/** |
3851 |
* Adds the specified directory to the instruments database. |
* Adds the specified directory to the instruments database. |
3852 |
* @param dir The absolute path name of the directory to add. |
* @param dir The absolute (escaped) path name of the directory to add. |
3853 |
* @throws IOException If some I/O error occurs. |
* @throws IOException If some I/O error occurs. |
3854 |
* @throws LSException If the creation of the directory failed. |
* @throws LSException If the creation of the directory failed. |
3855 |
* @throws LscpException If LSCP protocol corruption occurs. |
* @throws LscpException If LSCP protocol corruption occurs. |
3865 |
|
|
3866 |
/** |
/** |
3867 |
* Removes the specified directory from the instruments database. |
* Removes the specified directory from the instruments database. |
3868 |
* @param dir The absolute path name of the directory to remove. |
* @param dir The absolute (escaped) path name of the directory to remove. |
3869 |
* @throws IOException If some I/O error occurs. |
* @throws IOException If some I/O error occurs. |
3870 |
* @throws LscpException If LSCP protocol corruption occurs. |
* @throws LscpException If LSCP protocol corruption occurs. |
3871 |
* @throws LSException If the specified directory is not |
* @throws LSException If the specified directory is not |
3900 |
|
|
3901 |
/** |
/** |
3902 |
* Removes the specified directories from the instruments database. |
* Removes the specified directories from the instruments database. |
3903 |
* @param dirs The absolute path names of the directories to remove. |
* @param dirs The absolute (escaped) path names of the directories to remove. |
3904 |
* @param force If <code>true</code> forces the removal of non-empty |
* @param force If <code>true</code> forces the removal of non-empty |
3905 |
* directories. |
* directories. |
3906 |
* @throws IOException If some I/O error occurs. |
* @throws IOException If some I/O error occurs. |
3975 |
out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'"); |
out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'"); |
3976 |
if(getPrintOnlyMode()) return null; |
if(getPrintOnlyMode()) return null; |
3977 |
|
|
3978 |
return parseQuotedStringList(getSingleLineResultSet().getResult()); |
String[] names = parseEscapedStringList(getSingleLineResultSet().getResult()); |
3979 |
|
for(int i = 0; i < names.length; i++) { |
3980 |
|
names[i] = toNonEscapedString(names[i]); |
3981 |
|
} |
3982 |
|
return names; |
3983 |
} |
} |
3984 |
|
|
3985 |
/** |
/** |
4001 |
DbDirectoryInfo info = new DbDirectoryInfo(rs.getMultiLineResult()); |
DbDirectoryInfo info = new DbDirectoryInfo(rs.getMultiLineResult()); |
4002 |
if(dir.equals("/")) { |
if(dir.equals("/")) { |
4003 |
info.setName("/"); |
info.setName("/"); |
4004 |
} else if(dir.length() > 1 && dir.charAt(dir.length() - 1) == '/') { |
} else { |
4005 |
dir = dir.substring(0, dir.length() - 1); |
dir = removeEndingFileSeparator(dir); |
|
} |
|
|
int i = dir.lastIndexOf('/'); |
|
|
if(i != -1 && i < dir.length() - 1) { |
|
|
info.setName(dir.substring(i + 1)); |
|
|
if(i == 0) info.setParentDirectoryPath("/"); |
|
|
else info.setParentDirectoryPath(dir.substring(0, i)); |
|
4006 |
} |
} |
4007 |
|
String s = getFileName(dir); |
4008 |
|
if(s != null) info.setName(toNonEscapedFileName(s)); |
4009 |
|
s = getParentDirectory(dir); |
4010 |
|
if(s != null) info.setParentDirectoryPath(s); |
4011 |
|
|
4012 |
return info; |
return info; |
4013 |
} |
} |
4024 |
public synchronized DbDirectoryInfo[] |
public synchronized DbDirectoryInfo[] |
4025 |
getDbDirectories(String dir) throws IOException, LscpException, LSException { |
getDbDirectories(String dir) throws IOException, LscpException, LSException { |
4026 |
String[] dirS = getDbDirectoryNames(dir); |
String[] dirS = getDbDirectoryNames(dir); |
4027 |
if(dir.charAt(dir.length() - 1) != '/') dir += "/"; |
if(!hasEndingFileSeparator(dir)) dir += "/"; |
4028 |
DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length]; |
DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length]; |
4029 |
for(int i = 0; i < dirS.length; i++) infoS[i] = getDbDirectoryInfo(dir + dirS[i]); |
for(int i = 0; i < dirS.length; i++) { |
4030 |
|
infoS[i] = getDbDirectoryInfo(dir + toEscapedFileName(dirS[i])); |
4031 |
|
} |
4032 |
return infoS; |
return infoS; |
4033 |
} |
} |
4034 |
|
|
4093 |
public synchronized void |
public synchronized void |
4094 |
renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException { |
renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException { |
4095 |
verifyConnection(); |
verifyConnection(); |
4096 |
|
name = toEscapedString(name); |
4097 |
out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'"); |
out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'"); |
4098 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4099 |
|
|
4186 |
|
|
4187 |
verifyConnection(); |
verifyConnection(); |
4188 |
String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '"; |
String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '"; |
4189 |
out.writeLine(s + dir + "' '" + desc + "'"); |
out.writeLine(s + dir + "' '" + toEscapedString(desc) + "'"); |
4190 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4191 |
|
|
4192 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4365 |
break; |
break; |
4366 |
} |
} |
4367 |
|
|
4368 |
sb.append(" '").append(dbDir).append("' '").append(fsDir).append("'"); |
sb.append(" '").append(dbDir).append("' '"); |
4369 |
|
sb.append(fsDir).append("'"); |
4370 |
out.writeLine(sb.toString()); |
out.writeLine(sb.toString()); |
4371 |
if(getPrintOnlyMode()) return -1; |
if(getPrintOnlyMode()) return -1; |
4372 |
|
|
4462 |
out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'"); |
out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'"); |
4463 |
if(getPrintOnlyMode()) return null; |
if(getPrintOnlyMode()) return null; |
4464 |
|
|
4465 |
return parseQuotedStringList(getSingleLineResultSet().getResult()); |
String[] names = parseEscapedStringList(getSingleLineResultSet().getResult()); |
4466 |
|
for(int i = 0; i < names.length; i++) { |
4467 |
|
names[i] = toNonEscapedString(names[i]); |
4468 |
|
} |
4469 |
|
return names; |
4470 |
} |
} |
4471 |
|
|
4472 |
/** |
/** |
4486 |
|
|
4487 |
ResultSet rs = getMultiLineResultSet(); |
ResultSet rs = getMultiLineResultSet(); |
4488 |
DbInstrumentInfo info = new DbInstrumentInfo(rs.getMultiLineResult()); |
DbInstrumentInfo info = new DbInstrumentInfo(rs.getMultiLineResult()); |
4489 |
int i = instr.lastIndexOf('/'); |
String s = getParentDirectory(instr); |
4490 |
if(i != -1 && i < instr.length() - 1) { |
if(s != null) info.setDirectoryPath(s); |
4491 |
info.setName(instr.substring(i + 1)); |
s = getFileName(instr); |
4492 |
if(i == 0) info.setDirectoryPath("/"); |
if(s != null) info.setName(toNonEscapedFileName(s)); |
|
else info.setDirectoryPath(instr.substring(0, i)); |
|
|
} |
|
4493 |
|
|
4494 |
return info; |
return info; |
4495 |
} |
} |
4506 |
public synchronized DbInstrumentInfo[] |
public synchronized DbInstrumentInfo[] |
4507 |
getDbInstruments(String dir) throws IOException, LscpException, LSException { |
getDbInstruments(String dir) throws IOException, LscpException, LSException { |
4508 |
String[] instrS = getDbInstrumentNames(dir); |
String[] instrS = getDbInstrumentNames(dir); |
4509 |
if(dir.charAt(dir.length() - 1) != '/') dir += "/"; |
if(!hasEndingFileSeparator(dir)) dir += "/"; |
4510 |
|
|
4511 |
DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length]; |
DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length]; |
4512 |
for(int i = 0; i < instrS.length; i++) { |
for(int i = 0; i < instrS.length; i++) { |
4513 |
infoS[i] = getDbInstrumentInfo(dir + instrS[i]); |
infoS[i] = getDbInstrumentInfo(dir + toEscapedFileName(instrS[i])); |
4514 |
} |
} |
4515 |
return infoS; |
return infoS; |
4516 |
} |
} |
4578 |
throws IOException, LSException, LscpException { |
throws IOException, LSException, LscpException { |
4579 |
|
|
4580 |
verifyConnection(); |
verifyConnection(); |
4581 |
|
name = toEscapedString(name); |
4582 |
out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'"); |
out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'"); |
4583 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4584 |
|
|
4670 |
throws IOException, LSException, LscpException { |
throws IOException, LSException, LscpException { |
4671 |
|
|
4672 |
verifyConnection(); |
verifyConnection(); |
4673 |
|
desc = toEscapedString(desc); |
4674 |
out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'"); |
out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'"); |
4675 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4676 |
|
|
4718 |
sb.append(" '").append(dir).append("'"); |
sb.append(" '").append(dir).append("'"); |
4719 |
|
|
4720 |
if(query.name != null && query.name.length() > 0) { |
if(query.name != null && query.name.length() > 0) { |
4721 |
sb.append(" NAME='").append(query.name).append("'"); |
sb.append(" NAME='").append(toEscapedString(query.name)).append("'"); |
4722 |
} |
} |
4723 |
|
|
4724 |
String s = query.getCreatedAfter(); |
String s = query.getCreatedAfter(); |
4742 |
} |
} |
4743 |
|
|
4744 |
if(query.description != null && query.description.length() > 0) { |
if(query.description != null && query.description.length() > 0) { |
4745 |
sb.append(" DESCRIPTION='").append(query.description).append("'"); |
sb.append(" DESCRIPTION='"); |
4746 |
|
sb.append(toEscapedString(query.description)).append("'"); |
4747 |
} |
} |
4748 |
|
|
4749 |
out.writeLine(sb.toString()); |
out.writeLine(sb.toString()); |
4750 |
if(getPrintOnlyMode()) return null; |
if(getPrintOnlyMode()) return null; |
4751 |
|
|
4752 |
String[] dirS = parseQuotedStringList(getSingleLineResultSet().getResult()); |
String[] dirS = parseEscapedStringList(getSingleLineResultSet().getResult()); |
4753 |
|
|
4754 |
DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length]; |
DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length]; |
4755 |
for(int i = 0; i < dirS.length; i++) { |
for(int i = 0; i < dirS.length; i++) { |
4799 |
sb.append(" '").append(dir).append("'"); |
sb.append(" '").append(dir).append("'"); |
4800 |
|
|
4801 |
if(query.name != null && query.name.length() > 0) { |
if(query.name != null && query.name.length() > 0) { |
4802 |
sb.append(" NAME='").append(query.name).append("'"); |
sb.append(" NAME='").append(toEscapedString(query.name)).append("'"); |
4803 |
} |
} |
4804 |
|
|
4805 |
if(query.formatFamilies.size() > 0) { |
if(query.formatFamilies.size() > 0) { |
4839 |
} |
} |
4840 |
|
|
4841 |
if(query.description != null && query.description.length() > 0) { |
if(query.description != null && query.description.length() > 0) { |
4842 |
sb.append(" DESCRIPTION='").append(query.description).append("'"); |
sb.append(" DESCRIPTION='"); |
4843 |
|
sb.append(toEscapedString(query.description)).append("'"); |
4844 |
} |
} |
4845 |
|
|
4846 |
if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) { |
if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) { |
4853 |
} |
} |
4854 |
|
|
4855 |
if(query.product != null && query.product.length() > 0) { |
if(query.product != null && query.product.length() > 0) { |
4856 |
sb.append(" PRODUCT='").append(query.product).append("'"); |
sb.append(" PRODUCT='").append(toEscapedString(query.product)).append("'"); |
4857 |
} |
} |
4858 |
|
|
4859 |
if(query.artists != null && query.artists.length() > 0) { |
if(query.artists != null && query.artists.length() > 0) { |
4860 |
sb.append(" ARTISTS='").append(query.artists).append("'"); |
sb.append(" ARTISTS='").append(toEscapedString(query.artists)).append("'"); |
4861 |
} |
} |
4862 |
|
|
4863 |
if(query.keywords != null && query.keywords.length() > 0) { |
if(query.keywords != null && query.keywords.length() > 0) { |
4864 |
sb.append(" KEYWORDS='").append(query.keywords).append("'"); |
sb.append(" KEYWORDS='"); |
4865 |
|
sb.append(toEscapedString(query.keywords)).append("'"); |
4866 |
} |
} |
4867 |
|
|
4868 |
out.writeLine(sb.toString()); |
out.writeLine(sb.toString()); |
4869 |
if(getPrintOnlyMode()) return null; |
if(getPrintOnlyMode()) return null; |
4870 |
|
|
4871 |
String[] instrS = parseQuotedStringList(getSingleLineResultSet().getResult()); |
String[] instrS = parseEscapedStringList(getSingleLineResultSet().getResult()); |
4872 |
|
|
4873 |
DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length]; |
DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length]; |
4874 |
for(int i = 0; i < instrS.length; i++) { |
for(int i = 0; i < instrS.length; i++) { |
4899 |
} |
} |
4900 |
|
|
4901 |
/** |
/** |
4902 |
|
* Removes all instruments and directories and re-creates |
4903 |
|
* the instruments database structure. |
4904 |
|
* @throws IOException If some I/O error occurs. |
4905 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
4906 |
|
* @throws LSException If the formatting of the instruments database failed. |
4907 |
|
*/ |
4908 |
|
public synchronized void |
4909 |
|
formatInstrumentsDb() throws IOException, LscpException, LSException { |
4910 |
|
verifyConnection(); |
4911 |
|
out.writeLine("FORMAT INSTRUMENTS_DB"); |
4912 |
|
if(getPrintOnlyMode()) return; |
4913 |
|
|
4914 |
|
ResultSet rs = getEmptyResultSet(); |
4915 |
|
} |
4916 |
|
|
4917 |
|
/** |
4918 |
* Resets the specified sampler channel. |
* Resets the specified sampler channel. |
4919 |
* |
* |
4920 |
* @param samplerChn The sampler channel number. |
* @param samplerChn The sampler channel number. |
4951 |
} |
} |
4952 |
|
|
4953 |
/** |
/** |
4954 |
|
* Gets the current number of all active streams. |
4955 |
|
* @return The current number of all active streams. |
4956 |
|
* @throws IOException If some I/O error occurs. |
4957 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
4958 |
|
* @throws LSException If some other error occurs. |
4959 |
|
*/ |
4960 |
|
public synchronized int |
4961 |
|
getTotalStreamCount() throws IOException, LscpException, LSException { |
4962 |
|
verifyConnection(); |
4963 |
|
out.writeLine("GET TOTAL_STREAM_COUNT"); |
4964 |
|
if(getPrintOnlyMode()) return -1; |
4965 |
|
|
4966 |
|
String s = getSingleLineResultSet().getResult(); |
4967 |
|
return parseInt(s); |
4968 |
|
} |
4969 |
|
|
4970 |
|
/** |
4971 |
* Gets the current number of all active voices. |
* Gets the current number of all active voices. |
4972 |
* @return The current number of all active voices. |
* @return The current number of all active voices. |
4973 |
* @throws IOException If some I/O error occurs. |
* @throws IOException If some I/O error occurs. |
5056 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
5057 |
} |
} |
5058 |
|
|
5059 |
|
/** |
5060 |
|
* Gets the number of instruments in the specified instrument file. |
5061 |
|
* @param filename The absolute path name of the instrument file. |
5062 |
|
* @return The number of instruments in the specified instrument file. |
5063 |
|
* @throws IOException If some I/O error occurs. |
5064 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
5065 |
|
* @throws LSException If the file is not found, or other error occur. |
5066 |
|
*/ |
5067 |
|
public synchronized int |
5068 |
|
getFileInstrumentCount(String filename) throws IOException, LscpException, LSException { |
5069 |
|
verifyConnection(); |
5070 |
|
out.writeLine("GET FILE INSTRUMENTS '" + filename +"'"); |
5071 |
|
if(getPrintOnlyMode()) return -1; |
5072 |
|
|
5073 |
|
String s = getSingleLineResultSet().getResult(); |
5074 |
|
return parseInt(s); |
5075 |
|
} |
5076 |
|
|
5077 |
|
/** |
5078 |
|
* Gets information about the instrument with index |
5079 |
|
* <code>instrIdx</code> in the specified instrument file. |
5080 |
|
* @param filename The absolute path name of the instrument file. |
5081 |
|
* @param instrIdx The index of the instrument in the specified instrument file. |
5082 |
|
* @throws IOException If some I/O error occurs. |
5083 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
5084 |
|
* @throws LSException If failed to retrieve information. |
5085 |
|
*/ |
5086 |
|
public synchronized Instrument |
5087 |
|
getFileInstrumentInfo(String filename, int instrIdx) |
5088 |
|
throws IOException, LscpException, LSException { |
5089 |
|
|
5090 |
|
verifyConnection(); |
5091 |
|
out.writeLine("GET FILE INSTRUMENT INFO '" + filename + "' " + String.valueOf(instrIdx)); |
5092 |
|
if(getPrintOnlyMode()) return null; |
5093 |
|
|
5094 |
|
ResultSet rs = getMultiLineResultSet(); |
5095 |
|
Instrument instr = new FileInstrument(rs.getMultiLineResult()) { }; |
5096 |
|
|
5097 |
|
return instr; |
5098 |
|
} |
5099 |
|
|
5100 |
|
/** |
5101 |
|
* Gets the list of instruments in the specified instrument file. |
5102 |
|
* @param filename The absolute path name of the instrument file. |
5103 |
|
* @return An <code>Instrument</code> array providing |
5104 |
|
* information about all instruments in the specified instrument file. |
5105 |
|
* @throws IOException If some I/O error occurs. |
5106 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
5107 |
|
* @throws LSException If the specified file name is invalid. |
5108 |
|
*/ |
5109 |
|
public synchronized Instrument[] |
5110 |
|
getFileInstruments(String filename) throws IOException, LscpException, LSException { |
5111 |
|
int l = getFileInstrumentCount(filename); |
5112 |
|
if(l < 0) return null; |
5113 |
|
Instrument[] instrS = new FileInstrument[l]; |
5114 |
|
|
5115 |
|
for(int i = 0; i < instrS.length; i++) { |
5116 |
|
instrS[i] = getFileInstrumentInfo(filename, i); |
5117 |
|
} |
5118 |
|
return instrS; |
5119 |
|
} |
5120 |
|
|
5121 |
|
private static class FileInstrument extends AbstractInstrument { |
5122 |
|
FileInstrument(String[] resultSet) throws LscpException { |
5123 |
|
super(resultSet); |
5124 |
|
} |
5125 |
|
|
5126 |
|
public String |
5127 |
|
getEngine() { |
5128 |
|
// TODO: engine lookup? |
5129 |
|
return getFormatFamily(); |
5130 |
|
} |
5131 |
|
|
5132 |
|
public boolean |
5133 |
|
parse(String s) throws LscpException { |
5134 |
|
if(s.startsWith("PRODUCT: ") || s.startsWith("ARTISTS: ")) return true; |
5135 |
|
return super.parse(s); |
5136 |
|
} |
5137 |
|
} |
5138 |
|
|
5139 |
private void |
private void |
5140 |
getEmptyResultSets(int count, String err) throws LSException { |
getEmptyResultSets(int count, String err) throws LSException { |
5141 |
StringBuffer sb = new StringBuffer(); |
StringBuffer sb = new StringBuffer(); |