1 |
/* |
/* |
2 |
* jlscp - a java LinuxSampler control protocol API |
* jlscp - a java LinuxSampler control protocol API |
3 |
* |
* |
4 |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of jlscp. |
* This file is part of jlscp. |
7 |
* |
* |
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 |
44 |
* instance. Since it implements all commands specified in the LSCP protocol v1.1, for more |
* instance. Since it implements all commands specified in the LSCP protocol v1.3, for more |
45 |
* information look at the |
* information look at the |
46 |
* <a href=http://www.linuxsampler.org/api/lscp-1.1.html>LSCP</a> specification. |
* <a href=http://www.linuxsampler.org/api/lscp-1.3.html>LSCP</a> specification. |
47 |
* |
* |
48 |
* <p> The following code establishes connection to LinuxSampler instance and gets the |
* <p> The following code establishes connection to LinuxSampler instance and gets the |
49 |
* LinuxSampler version: |
* LinuxSampler version: |
164 |
if(printOnlyMode) setPrintOnlyMode(true); |
if(printOnlyMode) setPrintOnlyMode(true); |
165 |
} |
} |
166 |
|
|
167 |
|
private boolean extendedCharacterEscaping = true; |
168 |
|
|
169 |
|
/** |
170 |
|
* Sets whether strings sent to LinuxSampler should be more aggressively escaped. |
171 |
|
*/ |
172 |
|
public synchronized void |
173 |
|
setExtendedCharacterEscaping(boolean b) { extendedCharacterEscaping = b; } |
174 |
|
|
175 |
|
/** |
176 |
|
* Determines whether strings sent to LinuxSampler should be more aggressively escaped. |
177 |
|
*/ |
178 |
|
public synchronized boolean |
179 |
|
getExtendedCharacterEscaping() { return extendedCharacterEscaping; } |
180 |
|
|
181 |
|
/** |
182 |
|
* @see java.net.Socket#setSoTimeout |
183 |
|
*/ |
184 |
|
public synchronized void |
185 |
|
setSoTimeout(int timeout) { |
186 |
|
soTimeout = timeout; |
187 |
|
|
188 |
|
try { if(sock != null) sock.setSoTimeout(timeout); } |
189 |
|
catch(Exception x) { this.getLogger().log(Level.INFO, "Unable to set timeout", x); } |
190 |
|
} |
191 |
|
|
192 |
|
private String |
193 |
|
toEscapedText(String s) { |
194 |
|
s = toEscapedString(s); |
195 |
|
return conv(s); |
196 |
|
} |
197 |
|
|
198 |
|
private String |
199 |
|
toEscapedFsEntry(String s) { |
200 |
|
s = toEscapedFileName(s); |
201 |
|
return conv(s); |
202 |
|
} |
203 |
|
|
204 |
|
/** |
205 |
|
* Applies an extended character escaping to the specified string if needed. |
206 |
|
*/ |
207 |
|
private String |
208 |
|
conv(String s) { |
209 |
|
return getExtendedCharacterEscaping() ? toExtendedEscapeSequence(s) : s; |
210 |
|
} |
211 |
|
|
212 |
/** |
/** |
213 |
* Determines whether the client is in print-only mode. |
* Determines whether the client is in print-only mode. |
214 |
* Print-only mode means that the client will just print all |
* Print-only mode means that the client will just print all |
389 |
if(!llFSI.isEmpty()) subscribe("FX_SEND_INFO"); |
if(!llFSI.isEmpty()) subscribe("FX_SEND_INFO"); |
390 |
if(!llSC.isEmpty()) subscribe("STREAM_COUNT"); |
if(!llSC.isEmpty()) subscribe("STREAM_COUNT"); |
391 |
if(!llVC.isEmpty()) subscribe("VOICE_COUNT"); |
if(!llVC.isEmpty()) subscribe("VOICE_COUNT"); |
392 |
|
if(!llTSC.isEmpty()) subscribe("TOTAL_STREAM_COUNT"); |
393 |
if(!llTVC.isEmpty()) subscribe("TOTAL_VOICE_COUNT"); |
if(!llTVC.isEmpty()) subscribe("TOTAL_VOICE_COUNT"); |
394 |
if(!llMIMC.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_COUNT"); |
if(!llMIMC.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_COUNT"); |
395 |
if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO"); |
if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO"); |
396 |
if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT"); |
if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT"); |
397 |
if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO"); |
if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO"); |
398 |
|
if(!llDMD.isEmpty()) subscribe("DEVICE_MIDI"); |
399 |
|
if(!llCMD.isEmpty()) subscribe("CHANNEL_MIDI"); |
400 |
if(!llID.isEmpty()) { |
if(!llID.isEmpty()) { |
401 |
subscribe("DB_INSTRUMENT_DIRECTORY_COUNT"); |
subscribe("DB_INSTRUMENT_DIRECTORY_COUNT"); |
402 |
subscribe("DB_INSTRUMENT_DIRECTORY_INFO"); |
subscribe("DB_INSTRUMENT_DIRECTORY_INFO"); |
403 |
subscribe("DB_INSTRUMENT_COUNT"); |
subscribe("DB_INSTRUMENT_COUNT"); |
404 |
subscribe("DB_INSTRUMENT_INFO"); |
subscribe("DB_INSTRUMENT_INFO"); |
405 |
|
subscribe("DB_INSTRUMENTS_JOB_INFO"); |
406 |
} |
} |
407 |
if(!llGI.isEmpty()) subscribe("GLOBAL_INFO"); |
if(!llGI.isEmpty()) subscribe("GLOBAL_INFO"); |
408 |
} |
} |
534 |
private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>(); |
private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>(); |
535 |
private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>(); |
private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>(); |
536 |
private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>(); |
private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>(); |
537 |
|
private final Vector<TotalStreamCountListener> llTSC = new Vector<TotalStreamCountListener>(); |
538 |
private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>(); |
private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>(); |
539 |
|
|
540 |
/** MIDI instrument map count listeners */ |
/** MIDI instrument map count listeners */ |
547 |
/** MIDI instrument info listeners */ |
/** MIDI instrument info listeners */ |
548 |
private final Vector<MidiInstrumentInfoListener> llMII = |
private final Vector<MidiInstrumentInfoListener> llMII = |
549 |
new Vector<MidiInstrumentInfoListener>(); |
new Vector<MidiInstrumentInfoListener>(); |
550 |
|
private final Vector<DeviceMidiDataListener> llDMD = new Vector<DeviceMidiDataListener>(); |
551 |
|
private final Vector<ChannelMidiDataListener> llCMD = new Vector<ChannelMidiDataListener>(); |
552 |
private final Vector<InstrumentsDbListener> llID = new Vector<InstrumentsDbListener>(); |
private final Vector<InstrumentsDbListener> llID = new Vector<InstrumentsDbListener>(); |
553 |
private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>(); |
private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>(); |
554 |
|
|
574 |
!llMIDI.isEmpty() || |
!llMIDI.isEmpty() || |
575 |
!llSC.isEmpty() || |
!llSC.isEmpty() || |
576 |
!llVC.isEmpty() || |
!llVC.isEmpty() || |
577 |
|
!llTSC.isEmpty() || |
578 |
!llTVC.isEmpty() || |
!llTVC.isEmpty() || |
579 |
!llMIMC.isEmpty() || |
!llMIMC.isEmpty() || |
580 |
!llMIMI.isEmpty() || |
!llMIMI.isEmpty() || |
581 |
!llMIC.isEmpty() || |
!llMIC.isEmpty() || |
582 |
!llMII.isEmpty() || |
!llMII.isEmpty() || |
583 |
|
!llDMD.isEmpty() || |
584 |
|
!llCMD.isEmpty() || |
585 |
!llID.isEmpty() || |
!llID.isEmpty() || |
586 |
!llGI.isEmpty(); |
!llGI.isEmpty(); |
587 |
} |
} |
588 |
|
|
589 |
private synchronized void |
private synchronized void |
590 |
|
fireDeviceMidiDataEvent(String s) { |
591 |
|
try { |
592 |
|
String[] list = parseList(s, ' '); |
593 |
|
if(list.length != 5) { |
594 |
|
getLogger().warning("Unknown DEVICE_MIDI format"); |
595 |
|
return; |
596 |
|
} |
597 |
|
|
598 |
|
int dev = parseInt(list[0]); |
599 |
|
int port = parseInt(list[1]); |
600 |
|
|
601 |
|
MidiDataEvent.Type type = parseMidiDataType(list[2]); |
602 |
|
if(type == null) return; |
603 |
|
|
604 |
|
int note = parseInt(list[3]); |
605 |
|
int velocity = parseInt(list[4]); |
606 |
|
|
607 |
|
DeviceMidiDataEvent e = new DeviceMidiDataEvent(this, type, note, velocity); |
608 |
|
e.setDeviceId(dev); |
609 |
|
e.setPortId(port); |
610 |
|
for(DeviceMidiDataListener l : llDMD) l.midiDataArrived(e); |
611 |
|
} catch(LscpException x) { |
612 |
|
getLogger().log ( |
613 |
|
Level.WARNING, LscpI18n.getLogMsg("CommandFailed!"), x |
614 |
|
); |
615 |
|
} |
616 |
|
} |
617 |
|
|
618 |
|
private synchronized void |
619 |
|
fireChannelMidiDataEvent(String s) { |
620 |
|
try { |
621 |
|
String[] list = parseList(s, ' '); |
622 |
|
if(list.length != 4) { |
623 |
|
getLogger().warning("Unknown CHANNEL_MIDI format"); |
624 |
|
return; |
625 |
|
} |
626 |
|
|
627 |
|
int channel = parseInt(list[0]); |
628 |
|
|
629 |
|
MidiDataEvent.Type type = parseMidiDataType(list[1]); |
630 |
|
if(type == null) return; |
631 |
|
|
632 |
|
int note = parseInt(list[2]); |
633 |
|
int velocity = parseInt(list[3]); |
634 |
|
|
635 |
|
ChannelMidiDataEvent e = new ChannelMidiDataEvent(this, type, note, velocity); |
636 |
|
e.setChannelId(channel); |
637 |
|
for(ChannelMidiDataListener l : llCMD) l.midiDataArrived(e); |
638 |
|
} catch(LscpException x) { |
639 |
|
getLogger().log ( |
640 |
|
Level.WARNING, LscpI18n.getLogMsg("CommandFailed!"), x |
641 |
|
); |
642 |
|
} |
643 |
|
} |
644 |
|
|
645 |
|
private MidiDataEvent.Type |
646 |
|
parseMidiDataType(String s) { |
647 |
|
if("NOTE_ON".equals(s)) return MidiDataEvent.Type.NOTE_ON; |
648 |
|
if("NOTE_OFF".equals(s)) return MidiDataEvent.Type.NOTE_OFF; |
649 |
|
|
650 |
|
getLogger().warning("Unknown MIDI data type: " + s); |
651 |
|
return null; |
652 |
|
} |
653 |
|
|
654 |
|
private synchronized void |
655 |
fireEvent(String s) { |
fireEvent(String s) { |
656 |
if(s.startsWith("DB_INSTRUMENT_DIRECTORY_COUNT:")) { |
// Sort by priority |
657 |
|
|
658 |
|
if(s.startsWith("CHANNEL_MIDI:")) { |
659 |
|
s = s.substring("CHANNEL_MIDI:".length()); |
660 |
|
fireChannelMidiDataEvent(s); |
661 |
|
} else if(s.startsWith("DEVICE_MIDI:")) { |
662 |
|
s = s.substring("DEVICE_MIDI:".length()); |
663 |
|
fireDeviceMidiDataEvent(s); |
664 |
|
} else if(s.startsWith("DB_INSTRUMENT_DIRECTORY_COUNT:")) { |
665 |
s = s.substring("DB_INSTRUMENT_DIRECTORY_COUNT:".length()); |
s = s.substring("DB_INSTRUMENT_DIRECTORY_COUNT:".length()); |
666 |
InstrumentsDbEvent e = new InstrumentsDbEvent(this, s); |
InstrumentsDbEvent e = new InstrumentsDbEvent(this, s); |
667 |
for(InstrumentsDbListener l : llID) l.directoryCountChanged(e); |
for(InstrumentsDbListener l : llID) l.directoryCountChanged(e); |
790 |
} catch(NumberFormatException x) { |
} catch(NumberFormatException x) { |
791 |
getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x); |
getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x); |
792 |
} |
} |
793 |
|
} else if(s.startsWith("TOTAL_STREAM_COUNT:")) { |
794 |
|
try { |
795 |
|
s = s.substring("TOTAL_STREAM_COUNT:".length()); |
796 |
|
int i = Integer.parseInt(s); |
797 |
|
TotalStreamCountEvent e = new TotalStreamCountEvent(this, i); |
798 |
|
for(TotalStreamCountListener l : llTSC) l.totalStreamCountChanged(e); |
799 |
|
} catch(NumberFormatException x) { |
800 |
|
getLogger().log ( |
801 |
|
Level.WARNING, "Unknown TOTAL_STREAM_COUNT format", x |
802 |
|
); |
803 |
|
} |
804 |
} else if(s.startsWith("TOTAL_VOICE_COUNT:")) { |
} else if(s.startsWith("TOTAL_VOICE_COUNT:")) { |
805 |
try { |
try { |
806 |
s = s.substring("TOTAL_VOICE_COUNT:".length()); |
s = s.substring("TOTAL_VOICE_COUNT:".length()); |
1273 |
/** |
/** |
1274 |
* Registers the specified listener for receiving event messages. |
* Registers the specified listener for receiving event messages. |
1275 |
* Listeners can be registered regardless of the connection state. |
* Listeners can be registered regardless of the connection state. |
1276 |
|
* @param l The <code>TotalStreamCountListener</code> to register. |
1277 |
|
*/ |
1278 |
|
public synchronized void |
1279 |
|
addTotalStreamCountListener(TotalStreamCountListener l) { |
1280 |
|
if(llTSC.isEmpty()) subscribe("TOTAL_STREAM_COUNT"); |
1281 |
|
llTSC.add(l); |
1282 |
|
} |
1283 |
|
|
1284 |
|
/** |
1285 |
|
* Removes the specified listener. |
1286 |
|
* Listeners can be removed regardless of the connection state. |
1287 |
|
* @param l The <code>TotalStreamCountListener</code> to remove. |
1288 |
|
*/ |
1289 |
|
public synchronized void |
1290 |
|
removeTotalStreamCountListener(TotalStreamCountListener l) { |
1291 |
|
boolean b = llTSC.remove(l); |
1292 |
|
if(b && llTSC.isEmpty()) unsubscribe("TOTAL_STREAM_COUNT"); |
1293 |
|
} |
1294 |
|
|
1295 |
|
/** |
1296 |
|
* Registers the specified listener for receiving event messages. |
1297 |
|
* Listeners can be registered regardless of the connection state. |
1298 |
* @param l The <code>TotalVoiceCountListener</code> to register. |
* @param l The <code>TotalVoiceCountListener</code> to register. |
1299 |
*/ |
*/ |
1300 |
public synchronized void |
public synchronized void |
1405 |
/** |
/** |
1406 |
* Registers the specified listener for receiving event messages. |
* Registers the specified listener for receiving event messages. |
1407 |
* Listeners can be registered regardless of the connection state. |
* Listeners can be registered regardless of the connection state. |
1408 |
|
* @param l The <code>DeviceMidiDataListener</code> to register. |
1409 |
|
*/ |
1410 |
|
public synchronized void |
1411 |
|
addDeviceMidiDataListener(DeviceMidiDataListener l) { |
1412 |
|
if(llDMD.isEmpty()) subscribe("DEVICE_MIDI"); |
1413 |
|
llDMD.add(l); |
1414 |
|
} |
1415 |
|
|
1416 |
|
/** |
1417 |
|
* Removes the specified listener. |
1418 |
|
* Listeners can be removed regardless of the connection state. |
1419 |
|
* @param l The <code>DeviceMidiDataListener</code> to remove. |
1420 |
|
*/ |
1421 |
|
public synchronized void |
1422 |
|
removeDeviceMidiDataListener(DeviceMidiDataListener l) { |
1423 |
|
boolean b = llDMD.remove(l); |
1424 |
|
if(b && llDMD.isEmpty()) unsubscribe("DEVICE_MIDI"); |
1425 |
|
} |
1426 |
|
|
1427 |
|
/** |
1428 |
|
* Registers the specified listener for receiving event messages. |
1429 |
|
* Listeners can be registered regardless of the connection state. |
1430 |
|
* @param l The <code>ChannelMidiDataListener</code> to register. |
1431 |
|
*/ |
1432 |
|
public synchronized void |
1433 |
|
addChannelMidiDataListener(ChannelMidiDataListener l) { |
1434 |
|
if(llCMD.isEmpty()) subscribe("CHANNEL_MIDI"); |
1435 |
|
llCMD.add(l); |
1436 |
|
} |
1437 |
|
|
1438 |
|
/** |
1439 |
|
* Removes the specified listener. |
1440 |
|
* Listeners can be removed regardless of the connection state. |
1441 |
|
* @param l The <code>ChannelMidiDataListener</code> to remove. |
1442 |
|
*/ |
1443 |
|
public synchronized void |
1444 |
|
removeChannelMidiDataListener(ChannelMidiDataListener l) { |
1445 |
|
boolean b = llCMD.remove(l); |
1446 |
|
if(b && llCMD.isEmpty()) unsubscribe("CHANNEL_MIDI"); |
1447 |
|
} |
1448 |
|
|
1449 |
|
/** |
1450 |
|
* Registers the specified listener for receiving event messages. |
1451 |
|
* Listeners can be registered regardless of the connection state. |
1452 |
* @param l The <code>InstrumentsDbListener</code> to register. |
* @param l The <code>InstrumentsDbListener</code> to register. |
1453 |
*/ |
*/ |
1454 |
public synchronized void |
public synchronized void |
1623 |
args.append(' ').append(param); |
args.append(' ').append(param); |
1624 |
|
|
1625 |
for(Parameter p : deplist) { |
for(Parameter p : deplist) { |
1626 |
if(p.getValue() == null) continue; |
if(p == null || p.getName() == null || p.getValue() == null) continue; |
1627 |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
1628 |
} |
} |
1629 |
|
|
1687 |
StringBuffer args = new StringBuffer(aoDriver); |
StringBuffer args = new StringBuffer(aoDriver); |
1688 |
|
|
1689 |
for(Parameter p : paramList) { |
for(Parameter p : paramList) { |
1690 |
if(p.getValue() == null) continue; |
if(p == null || p.getName() == null || p.getValue() == null) continue; |
1691 |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
1692 |
} |
} |
1693 |
|
|
2209 |
args.append(' ').append(param); |
args.append(' ').append(param); |
2210 |
|
|
2211 |
for(Parameter p : deplist) { |
for(Parameter p : deplist) { |
2212 |
if(p.getValue() == null) continue; |
if(p == null || p.getName() == null || p.getValue() == null) continue; |
2213 |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
2214 |
} |
} |
2215 |
|
|
2274 |
StringBuffer args = new StringBuffer(miDriver); |
StringBuffer args = new StringBuffer(miDriver); |
2275 |
|
|
2276 |
for(Parameter p : paramList) { |
for(Parameter p : paramList) { |
2277 |
if(p.getValue() == null) continue; |
if(p == null || p.getName() == null || p.getValue() == null) continue; |
2278 |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
args.append(' ').append(p.getName()).append('=').append(p.getStringValue()); |
2279 |
} |
} |
2280 |
|
|
2421 |
mid.setActive(Boolean.parseBoolean(s)); |
mid.setActive(Boolean.parseBoolean(s)); |
2422 |
} else if(s.startsWith("PORTS: ")) { |
} else if(s.startsWith("PORTS: ")) { |
2423 |
s = s.substring("PORTS: ".length()); |
s = s.substring("PORTS: ".length()); |
2424 |
int ports = Parser.parseInt(s); |
|
2425 |
MidiPort[] midiPorts = new MidiPort[ports > 0 ? ports : 0]; |
Parameter<Integer> ports = (Parameter<Integer>) |
2426 |
|
getMidiInputDriverParameterInfo(drv, "PORTS"); |
2427 |
|
|
2428 |
|
ports.parseValue(s); |
2429 |
|
mid.setPortsParameter(ports); |
2430 |
|
|
2431 |
|
int j = ports.getValue(); |
2432 |
|
MidiPort[] midiPorts = new MidiPort[j > 0 ? j : 0]; |
2433 |
|
|
2434 |
for(int i = 0; i < midiPorts.length; i++) |
for(int i = 0; i < midiPorts.length; i++) |
2435 |
midiPorts[i] = getMidiInputPortInfo(deviceId, i); |
midiPorts[i] = getMidiInputPortInfo(deviceId, i); |
2672 |
public synchronized int |
public synchronized int |
2673 |
addMidiInstrumentMap(String name) throws IOException, LSException, LscpException { |
addMidiInstrumentMap(String name) throws IOException, LSException, LscpException { |
2674 |
verifyConnection(); |
verifyConnection(); |
2675 |
out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + toEscapedString(name) + "'"); |
out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + toEscapedText(name) + "'"); |
2676 |
if(getPrintOnlyMode()) return -1; |
if(getPrintOnlyMode()) return -1; |
2677 |
|
|
2678 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
2823 |
throws IOException, LscpException, LSException { |
throws IOException, LscpException, LSException { |
2824 |
|
|
2825 |
verifyConnection(); |
verifyConnection(); |
2826 |
name = toEscapedString(name); |
name = toEscapedText(name); |
2827 |
out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " + + mapId + " '" + name + "'"); |
out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " + + mapId + " '" + name + "'"); |
2828 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
2829 |
|
|
2873 |
cmd.append(entry.getMidiBank()).append(' '); |
cmd.append(entry.getMidiBank()).append(' '); |
2874 |
cmd.append(entry.getMidiProgram()).append(' '); |
cmd.append(entry.getMidiProgram()).append(' '); |
2875 |
cmd.append(info.getEngine()).append(" '"); |
cmd.append(info.getEngine()).append(" '"); |
2876 |
cmd.append(info.getFilePath()).append("' "); |
cmd.append(conv(info.getFilePath())).append("' "); |
2877 |
cmd.append(info.getInstrumentIndex()).append(' '); |
cmd.append(info.getInstrumentIndex()).append(' '); |
2878 |
cmd.append(info.getVolume()); |
cmd.append(info.getVolume()); |
2879 |
if(!info.getLoadMode().name().equals("DEFAULT")) { |
if(!info.getLoadMode().name().equals("DEFAULT")) { |
2881 |
} |
} |
2882 |
|
|
2883 |
if(info.getName() != null) { |
if(info.getName() != null) { |
2884 |
String s = toEscapedString(info.getName()); |
String s = toEscapedText(info.getName()); |
2885 |
cmd.append(" '").append(s).append("'"); |
cmd.append(" '").append(s).append("'"); |
2886 |
} |
} |
2887 |
|
|
2972 |
} |
} |
2973 |
|
|
2974 |
/** |
/** |
2975 |
* Gets all MIDI instrument contained int the specified MIDI instrument map. |
* Gets all MIDI instrument entries contained int the specified MIDI instrument map. |
2976 |
|
* @param mapId The ID of the map, which instruments should be obtained. |
2977 |
|
* @return An int array providing all MIDI instrument entries |
2978 |
|
* in the specified MIDI instrument map. |
2979 |
|
* @throws IOException If some I/O error occurs. |
2980 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
2981 |
|
* @throws LSException If some other error occurs. |
2982 |
|
*/ |
2983 |
|
public synchronized int[][] |
2984 |
|
getMidiInstrumentEntries(int mapId) throws IOException, LscpException, LSException { |
2985 |
|
verifyConnection(); |
2986 |
|
out.writeLine("LIST MIDI_INSTRUMENTS " + String.valueOf(mapId)); |
2987 |
|
if(getPrintOnlyMode()) return null; |
2988 |
|
|
2989 |
|
String[] entries = parseArray(getSingleLineResultSet().getResult()); |
2990 |
|
int[][] e = new int[entries.length][3]; |
2991 |
|
|
2992 |
|
for(int i = 0; i < entries.length; i++) { |
2993 |
|
Integer[] vals = parseIntList(entries[i]); |
2994 |
|
if(vals.length != 3) { |
2995 |
|
throw new LscpException(LscpI18n.getLogMsg("CommandFailed!")); |
2996 |
|
} |
2997 |
|
|
2998 |
|
e[i][0] = vals[0]; |
2999 |
|
e[i][1] = vals[1]; |
3000 |
|
e[i][2] = vals[2]; |
3001 |
|
} |
3002 |
|
|
3003 |
|
return e; |
3004 |
|
} |
3005 |
|
|
3006 |
|
/** |
3007 |
|
* Gets all MIDI instruments contained int the specified MIDI instrument map. |
3008 |
* @param mapId The ID of the map, which instruments should be obtained. |
* @param mapId The ID of the map, which instruments should be obtained. |
3009 |
* @return A <code>MidiInstrumentInfo</code> array providing |
* @return A <code>MidiInstrumentInfo</code> array providing |
3010 |
* all MIDI instruments from all MIDI instrument maps. |
* all MIDI instruments in the specified MIDI instrument map. |
3011 |
* @throws IOException If some I/O error occurs. |
* @throws IOException If some I/O error occurs. |
3012 |
* @throws LscpException If LSCP protocol corruption occurs. |
* @throws LscpException If LSCP protocol corruption occurs. |
3013 |
* @throws LSException If some other error occurs. |
* @throws LSException If some other error occurs. |
3055 |
throws IOException, LscpException, LSException { |
throws IOException, LscpException, LSException { |
3056 |
|
|
3057 |
verifyConnection(); |
verifyConnection(); |
3058 |
|
requestMidiInstrumentInfo(mapId, bank, program); |
3059 |
|
return getMidiInstrumentInfoResponse(mapId, bank, program); |
3060 |
|
} |
3061 |
|
|
3062 |
|
private void |
3063 |
|
requestMidiInstrumentInfo(int mapId, int bank, int program) throws IOException { |
3064 |
StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO "); |
StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO "); |
3065 |
cmd.append(mapId).append(' '); |
cmd.append(mapId).append(' '); |
3066 |
cmd.append(bank).append(' '); |
cmd.append(bank).append(' '); |
3067 |
cmd.append(program); |
cmd.append(program); |
3068 |
|
|
3069 |
out.writeLine(cmd.toString()); |
out.writeLine(cmd.toString()); |
3070 |
if(getPrintOnlyMode()) return null; |
} |
3071 |
|
|
3072 |
|
private MidiInstrumentInfo |
3073 |
|
getMidiInstrumentInfoResponse(int mapId, int bank, int program) |
3074 |
|
throws IOException, LscpException, LSException { |
3075 |
|
|
3076 |
|
if(getPrintOnlyMode()) return null; |
3077 |
ResultSet rs = getMultiLineResultSet(); |
ResultSet rs = getMultiLineResultSet(); |
3078 |
MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program); |
MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program); |
3079 |
return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult()); |
return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult()); |
3123 |
throws IOException, LscpException, LSException { |
throws IOException, LscpException, LSException { |
3124 |
|
|
3125 |
String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT "; |
String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT "; |
3126 |
String args = '\'' + filename + "' " + instrIdx + ' ' + samplerChn; |
String args = '\'' + conv(filename) + "' " + instrIdx + ' ' + samplerChn; |
3127 |
|
|
3128 |
out.writeLine(cmd + args); |
out.writeLine(cmd + args); |
3129 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
3775 |
|
|
3776 |
verifyConnection(); |
verifyConnection(); |
3777 |
String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl); |
String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl); |
3778 |
if(name != null) s += " '" + toEscapedString(name) + "'"; |
if(name != null) s += " '" + toEscapedText(name) + "'"; |
3779 |
out.writeLine("CREATE FX_SEND " + s); |
out.writeLine("CREATE FX_SEND " + s); |
3780 |
if(getPrintOnlyMode()) return -1; |
if(getPrintOnlyMode()) return -1; |
3781 |
|
|
3906 |
throws IOException, LscpException, LSException { |
throws IOException, LscpException, LSException { |
3907 |
|
|
3908 |
verifyConnection(); |
verifyConnection(); |
3909 |
String args = " " + channel + " " + fxSend + " '" + toEscapedString(name) + "'"; |
String args = " " + channel + " " + fxSend + " '" + toEscapedText(name) + "'"; |
3910 |
out.writeLine("SET FX_SEND NAME" + args); |
out.writeLine("SET FX_SEND NAME" + args); |
3911 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
3912 |
|
|
4013 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4014 |
} |
} |
4015 |
|
|
4016 |
|
/** |
4017 |
|
* Sends a MIDI event to this sampler channel. |
4018 |
|
* @param samplerChn The sampler channel number. |
4019 |
|
* @param type The type of MIDI message to send. |
4020 |
|
* @throws IOException If some I/O error occurs. |
4021 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
4022 |
|
* @throws LSException If <code>samplerChn</code> is not a valid channel number or if |
4023 |
|
* there is no instrument loaded on the specified sampler channel. |
4024 |
|
* @see #getSamplerChannels |
4025 |
|
*/ |
4026 |
|
public synchronized void |
4027 |
|
sendChannelMidiData(int samplerChn, MidiDataEvent.Type type, int arg1, int arg2) |
4028 |
|
throws IOException, LscpException, LSException { |
4029 |
|
|
4030 |
|
verifyConnection(); |
4031 |
|
StringBuffer sb = new StringBuffer(); |
4032 |
|
sb.append("SEND CHANNEL MIDI_DATA "); |
4033 |
|
sb.append(type).append(" ").append(samplerChn).append(" "); |
4034 |
|
sb.append(arg1).append(" ").append(arg2); |
4035 |
|
|
4036 |
|
out.writeLine(sb.toString()); |
4037 |
|
if(getPrintOnlyMode()) return; |
4038 |
|
|
4039 |
|
ResultSet rs = getEmptyResultSet(); |
4040 |
|
} |
4041 |
|
|
4042 |
|
/** |
4043 |
|
* Resets the specified sampler channel. |
4044 |
|
* |
4045 |
|
* @param samplerChn The sampler channel number. |
4046 |
|
* |
4047 |
|
* @throws IOException If some I/O error occurs. |
4048 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
4049 |
|
* @throws LSException If <code>samplerChn</code> is not a valid channel number or if |
4050 |
|
* there is no engine assigned yet to the specified sampler channel. |
4051 |
|
* @see #getSamplerChannels |
4052 |
|
*/ |
4053 |
|
public synchronized void |
4054 |
|
resetChannel(int samplerChn) throws IOException, LscpException, LSException { |
4055 |
|
verifyConnection(); |
4056 |
|
out.writeLine("RESET CHANNEL " + samplerChn); |
4057 |
|
if(getPrintOnlyMode()) return; |
4058 |
|
|
4059 |
|
ResultSet rs = getEmptyResultSet(); |
4060 |
|
} |
4061 |
|
|
4062 |
|
|
4063 |
|
|
4064 |
/** |
/** |
4071 |
public synchronized void |
public synchronized void |
4072 |
addDbDirectory(String dir) throws IOException, LSException, LscpException { |
addDbDirectory(String dir) throws IOException, LSException, LscpException { |
4073 |
verifyConnection(); |
verifyConnection(); |
4074 |
out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + dir + "'"); |
out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "'"); |
4075 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4076 |
|
|
4077 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4106 |
verifyConnection(); |
verifyConnection(); |
4107 |
String s = "REMOVE DB_INSTRUMENT_DIRECTORY "; |
String s = "REMOVE DB_INSTRUMENT_DIRECTORY "; |
4108 |
if(force) s += "FORCE "; |
if(force) s += "FORCE "; |
4109 |
out.writeLine(s + "'" + dir + "'"); |
out.writeLine(s + "'" + conv(dir) + "'"); |
4110 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4111 |
|
|
4112 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4129 |
String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY "; |
String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY "; |
4130 |
if(force) cmd += "FORCE "; |
if(force) cmd += "FORCE "; |
4131 |
|
|
4132 |
for(String s : dirs) out.writeLine(cmd + "'" + s + "'"); |
for(String s : dirs) out.writeLine(cmd + "'" + conv(s) + "'"); |
4133 |
|
|
4134 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4135 |
|
|
4167 |
String s; |
String s; |
4168 |
if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '"; |
if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '"; |
4169 |
else s = "GET DB_INSTRUMENT_DIRECTORIES '"; |
else s = "GET DB_INSTRUMENT_DIRECTORIES '"; |
4170 |
out.writeLine(s + dir + "'"); |
out.writeLine(s + conv(dir) + "'"); |
4171 |
if(getPrintOnlyMode()) return -1; |
if(getPrintOnlyMode()) return -1; |
4172 |
|
|
4173 |
s = getSingleLineResultSet().getResult(); |
s = getSingleLineResultSet().getResult(); |
4186 |
public synchronized String[] |
public synchronized String[] |
4187 |
getDbDirectoryNames(String dir) throws IOException, LscpException, LSException { |
getDbDirectoryNames(String dir) throws IOException, LscpException, LSException { |
4188 |
verifyConnection(); |
verifyConnection(); |
4189 |
out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'"); |
out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + conv(dir) + "'"); |
4190 |
if(getPrintOnlyMode()) return null; |
if(getPrintOnlyMode()) return null; |
4191 |
|
|
4192 |
String[] names = parseEscapedStringList(getSingleLineResultSet().getResult()); |
String[] names = parseEscapedStringList(getSingleLineResultSet().getResult()); |
4208 |
public synchronized DbDirectoryInfo |
public synchronized DbDirectoryInfo |
4209 |
getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException { |
getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException { |
4210 |
verifyConnection(); |
verifyConnection(); |
4211 |
out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + "'"); |
out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + conv(dir) + "'"); |
4212 |
if(getPrintOnlyMode()) return null; |
if(getPrintOnlyMode()) return null; |
4213 |
|
|
4214 |
ResultSet rs = getMultiLineResultSet(); |
ResultSet rs = getMultiLineResultSet(); |
4241 |
if(!hasEndingFileSeparator(dir)) dir += "/"; |
if(!hasEndingFileSeparator(dir)) dir += "/"; |
4242 |
DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length]; |
DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length]; |
4243 |
for(int i = 0; i < dirS.length; i++) { |
for(int i = 0; i < dirS.length; i++) { |
4244 |
infoS[i] = getDbDirectoryInfo(dir + toEscapedFileName(dirS[i])); |
infoS[i] = getDbDirectoryInfo(conv(dir) + toEscapedFsEntry(dirS[i])); |
4245 |
} |
} |
4246 |
return infoS; |
return infoS; |
4247 |
} |
} |
4257 |
* |
* |
4258 |
public synchronized DbDirectoryInfo[] |
public synchronized DbDirectoryInfo[] |
4259 |
getDbDirectories(String dir) throws IOException, LscpException, LSException { |
getDbDirectories(String dir) throws IOException, LscpException, LSException { |
4260 |
String[] dirS = getDbDirectoryNames(dir); |
String[] dirS = getDbDirectoryNames(conv(dir)); |
4261 |
if(dirS.length == 0) return new DbDirectoryInfo[0]; |
if(dirS.length == 0) return new DbDirectoryInfo[0]; |
4262 |
|
|
4263 |
if(dir.charAt(dir.length() - 1) != '/') dir += "/"; |
if(dir.charAt(dir.length() - 1) != '/') dir += "/"; // FIXME: |
4264 |
|
|
4265 |
for(int i = 0; i < dirS.length; i++) { |
for(int i = 0; i < dirS.length; i++) { |
4266 |
out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + dirS[i] + "'"); |
out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + conv(dir + dirS[i]) + "'"); |
4267 |
} |
} |
4268 |
|
|
4269 |
if(getPrintOnlyMode()) return null; |
if(getPrintOnlyMode()) return null; |
4307 |
public synchronized void |
public synchronized void |
4308 |
renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException { |
renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException { |
4309 |
verifyConnection(); |
verifyConnection(); |
4310 |
name = toEscapedString(name); |
name = toEscapedText(name); |
4311 |
out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'"); |
out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + conv(dir) + "' '" + conv(name) + "'"); |
4312 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4313 |
|
|
4314 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4325 |
public synchronized void |
public synchronized void |
4326 |
moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException { |
moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException { |
4327 |
verifyConnection(); |
verifyConnection(); |
4328 |
out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'"); |
out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "' '" + conv(dst) + "'"); |
4329 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4330 |
|
|
4331 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4343 |
moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException { |
moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException { |
4344 |
verifyConnection(); |
verifyConnection(); |
4345 |
for(String s : dirs) { |
for(String s : dirs) { |
4346 |
out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'"); |
out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + conv(s) + "' '" + conv(dst) + "'"); |
4347 |
} |
} |
4348 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4349 |
|
|
4361 |
public synchronized void |
public synchronized void |
4362 |
copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException { |
copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException { |
4363 |
verifyConnection(); |
verifyConnection(); |
4364 |
out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'"); |
out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "' '" + conv(dst) + "'"); |
4365 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4366 |
|
|
4367 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4379 |
copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException { |
copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException { |
4380 |
verifyConnection(); |
verifyConnection(); |
4381 |
for(String s : dirs) { |
for(String s : dirs) { |
4382 |
out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'"); |
out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + conv(s) + "' '" + conv(dst) + "'"); |
4383 |
} |
} |
4384 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4385 |
|
|
4400 |
|
|
4401 |
verifyConnection(); |
verifyConnection(); |
4402 |
String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '"; |
String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '"; |
4403 |
out.writeLine(s + dir + "' '" + toEscapedString(desc) + "'"); |
out.writeLine(s + conv(dir) + "' '" + toEscapedText(desc) + "'"); |
4404 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4405 |
|
|
4406 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4449 |
verifyConnection(); |
verifyConnection(); |
4450 |
String s = "ADD DB_INSTRUMENTS"; |
String s = "ADD DB_INSTRUMENTS"; |
4451 |
if(background) s += " NON_MODAL"; |
if(background) s += " NON_MODAL"; |
4452 |
s += " '" + dbDir + "' '" + filePath + "' "; |
s += " '" + conv(dbDir) + "' '" + conv(filePath) + "' "; |
4453 |
out.writeLine(s + String.valueOf(instrIndex)); |
out.writeLine(s + String.valueOf(instrIndex)); |
4454 |
if(getPrintOnlyMode()) return -1; |
if(getPrintOnlyMode()) return -1; |
4455 |
|
|
4496 |
verifyConnection(); |
verifyConnection(); |
4497 |
String s = "ADD DB_INSTRUMENTS"; |
String s = "ADD DB_INSTRUMENTS"; |
4498 |
if(background) s += " NON_MODAL"; |
if(background) s += " NON_MODAL"; |
4499 |
out.writeLine(s + " '" + dbDir + "' '" + filePath + "'"); |
out.writeLine(s + " '" + conv(dbDir) + "' '" + conv(filePath) + "'"); |
4500 |
if(getPrintOnlyMode()) return -1; |
if(getPrintOnlyMode()) return -1; |
4501 |
|
|
4502 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4579 |
break; |
break; |
4580 |
} |
} |
4581 |
|
|
4582 |
sb.append(" '").append(dbDir).append("' '"); |
sb.append(" '").append(conv(dbDir)).append("' '"); |
4583 |
sb.append(fsDir).append("'"); |
sb.append(conv(fsDir)).append("'"); |
4584 |
out.writeLine(sb.toString()); |
out.writeLine(sb.toString()); |
4585 |
if(getPrintOnlyMode()) return -1; |
if(getPrintOnlyMode()) return -1; |
4586 |
|
|
4599 |
removeDbInstrument(String instr) throws IOException, LscpException, LSException { |
removeDbInstrument(String instr) throws IOException, LscpException, LSException { |
4600 |
|
|
4601 |
verifyConnection(); |
verifyConnection(); |
4602 |
out.writeLine("REMOVE DB_INSTRUMENT '" + instr + "'"); |
out.writeLine("REMOVE DB_INSTRUMENT '" + conv(instr) + "'"); |
4603 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4604 |
|
|
4605 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4616 |
removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException { |
removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException { |
4617 |
verifyConnection(); |
verifyConnection(); |
4618 |
for(String s : instrs) { |
for(String s : instrs) { |
4619 |
out.writeLine("REMOVE DB_INSTRUMENT '" + s + "'"); |
out.writeLine("REMOVE DB_INSTRUMENT '" + conv(s) + "'"); |
4620 |
} |
} |
4621 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4622 |
|
|
4654 |
String s; |
String s; |
4655 |
if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '"; |
if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '"; |
4656 |
else s = "GET DB_INSTRUMENTS '"; |
else s = "GET DB_INSTRUMENTS '"; |
4657 |
out.writeLine(s + dir + "'"); |
out.writeLine(s + conv(dir) + "'"); |
4658 |
if(getPrintOnlyMode()) return -1; |
if(getPrintOnlyMode()) return -1; |
4659 |
|
|
4660 |
s = getSingleLineResultSet().getResult(); |
s = getSingleLineResultSet().getResult(); |
4673 |
public synchronized String[] |
public synchronized String[] |
4674 |
getDbInstrumentNames(String dir) throws IOException, LscpException, LSException { |
getDbInstrumentNames(String dir) throws IOException, LscpException, LSException { |
4675 |
verifyConnection(); |
verifyConnection(); |
4676 |
out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'"); |
out.writeLine("LIST DB_INSTRUMENTS '" + conv(dir) + "'"); |
4677 |
if(getPrintOnlyMode()) return null; |
if(getPrintOnlyMode()) return null; |
4678 |
|
|
4679 |
String[] names = parseEscapedStringList(getSingleLineResultSet().getResult()); |
String[] names = parseEscapedStringList(getSingleLineResultSet().getResult()); |
4695 |
public synchronized DbInstrumentInfo |
public synchronized DbInstrumentInfo |
4696 |
getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException { |
getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException { |
4697 |
verifyConnection(); |
verifyConnection(); |
4698 |
out.writeLine("GET DB_INSTRUMENT INFO '" + instr + "'"); |
out.writeLine("GET DB_INSTRUMENT INFO '" + conv(instr) + "'"); |
4699 |
if(getPrintOnlyMode()) return null; |
if(getPrintOnlyMode()) return null; |
4700 |
|
|
4701 |
ResultSet rs = getMultiLineResultSet(); |
ResultSet rs = getMultiLineResultSet(); |
4724 |
|
|
4725 |
DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length]; |
DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length]; |
4726 |
for(int i = 0; i < instrS.length; i++) { |
for(int i = 0; i < instrS.length; i++) { |
4727 |
infoS[i] = getDbInstrumentInfo(dir + toEscapedFileName(instrS[i])); |
infoS[i] = getDbInstrumentInfo(conv(dir) + toEscapedFsEntry(instrS[i])); |
4728 |
} |
} |
4729 |
return infoS; |
return infoS; |
4730 |
} |
} |
4743 |
String[] instrS = getDbInstrumentNames(dir); |
String[] instrS = getDbInstrumentNames(dir); |
4744 |
if(instrS.length == 0) return new DbInstrumentInfo[0]; |
if(instrS.length == 0) return new DbInstrumentInfo[0]; |
4745 |
|
|
4746 |
if(dir.charAt(dir.length() - 1) != '/') dir += "/"; |
if(dir.charAt(dir.length() - 1) != '/') dir += "/"; FIXME: |
4747 |
|
|
4748 |
for(int i = 0; i < instrS.length; i++) { |
for(int i = 0; i < instrS.length; i++) { |
4749 |
out.writeLine("GET DB_INSTRUMENT INFO '" + dir + instrS[i] + "'"); |
out.writeLine("GET DB_INSTRUMENT INFO '" + conv(dir) + instrS[i] + "'"); |
4750 |
} |
} |
4751 |
|
|
4752 |
if(getPrintOnlyMode()) return null; |
if(getPrintOnlyMode()) return null; |
4792 |
throws IOException, LSException, LscpException { |
throws IOException, LSException, LscpException { |
4793 |
|
|
4794 |
verifyConnection(); |
verifyConnection(); |
4795 |
name = toEscapedString(name); |
name = toEscapedText(name); |
4796 |
out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'"); |
out.writeLine("SET DB_INSTRUMENT NAME '" + conv(instr) + "' '" + conv(name) + "'"); |
4797 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4798 |
|
|
4799 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4810 |
public synchronized void |
public synchronized void |
4811 |
moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException { |
moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException { |
4812 |
verifyConnection(); |
verifyConnection(); |
4813 |
out.writeLine("MOVE DB_INSTRUMENT '" + instr + "' '" + dst + "'"); |
out.writeLine("MOVE DB_INSTRUMENT '" + conv(instr) + "' '" + conv(dst) + "'"); |
4814 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4815 |
|
|
4816 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4828 |
moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException { |
moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException { |
4829 |
verifyConnection(); |
verifyConnection(); |
4830 |
for(String s : instrs) { |
for(String s : instrs) { |
4831 |
out.writeLine("MOVE DB_INSTRUMENT '" + s + "' '" + dst + "'"); |
out.writeLine("MOVE DB_INSTRUMENT '" + conv(s) + "' '" + conv(dst) + "'"); |
4832 |
} |
} |
4833 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4834 |
|
|
4846 |
public synchronized void |
public synchronized void |
4847 |
copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException { |
copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException { |
4848 |
verifyConnection(); |
verifyConnection(); |
4849 |
out.writeLine("COPY DB_INSTRUMENT '" + instr + "' '" + dst + "'"); |
out.writeLine("COPY DB_INSTRUMENT '" + conv(instr) + "' '" + conv(dst) + "'"); |
4850 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4851 |
|
|
4852 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4864 |
copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException { |
copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException { |
4865 |
verifyConnection(); |
verifyConnection(); |
4866 |
for(String s : instrs) { |
for(String s : instrs) { |
4867 |
out.writeLine("COPY DB_INSTRUMENT '" + s + "' '" + dst + "'"); |
out.writeLine("COPY DB_INSTRUMENT '" + conv(s) + "' '" + conv(dst) + "'"); |
4868 |
} |
} |
4869 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4870 |
|
|
4884 |
throws IOException, LSException, LscpException { |
throws IOException, LSException, LscpException { |
4885 |
|
|
4886 |
verifyConnection(); |
verifyConnection(); |
4887 |
desc = toEscapedString(desc); |
desc = toEscapedText(desc); |
4888 |
out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'"); |
out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + conv(instr) + "' '" + desc + "'"); |
4889 |
|
if(getPrintOnlyMode()) return; |
4890 |
|
|
4891 |
|
ResultSet rs = getEmptyResultSet(); |
4892 |
|
} |
4893 |
|
|
4894 |
|
/** |
4895 |
|
* Substitutes all occurrences of the instrument file |
4896 |
|
* <code>oldPath</code> in the database, with <code>newPath</code>. |
4897 |
|
* @param oldPath The absolute path name of the instrument file to substitute. |
4898 |
|
* @param newPath The new absolute path name. |
4899 |
|
* @throws IOException If some I/O error occurs. |
4900 |
|
* @throws LSException If the operation failed. |
4901 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
4902 |
|
*/ |
4903 |
|
public synchronized void |
4904 |
|
setDbInstrumentFilePath(String oldPath, String newPath) |
4905 |
|
throws IOException, LSException, LscpException { |
4906 |
|
|
4907 |
|
verifyConnection(); |
4908 |
|
out.writeLine("SET DB_INSTRUMENT FILE_PATH '" + conv(oldPath) + "' '" + conv(newPath) + "'"); |
4909 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
4910 |
|
|
4911 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
4949 |
StringBuffer sb = new StringBuffer(); |
StringBuffer sb = new StringBuffer(); |
4950 |
sb.append("FIND DB_INSTRUMENT_DIRECTORIES"); |
sb.append("FIND DB_INSTRUMENT_DIRECTORIES"); |
4951 |
if(nonRecursive) sb.append(" NON_RECURSIVE"); |
if(nonRecursive) sb.append(" NON_RECURSIVE"); |
4952 |
sb.append(" '").append(dir).append("'"); |
sb.append(" '").append(conv(dir)).append("'"); |
4953 |
|
|
4954 |
if(query.name != null && query.name.length() > 0) { |
if(query.name != null && query.name.length() > 0) { |
4955 |
sb.append(" NAME='").append(toEscapedString(query.name)).append("'"); |
sb.append(" NAME='").append(toEscapedText(query.name)).append("'"); |
4956 |
} |
} |
4957 |
|
|
4958 |
String s = query.getCreatedAfter(); |
String s = query.getCreatedAfter(); |
4977 |
|
|
4978 |
if(query.description != null && query.description.length() > 0) { |
if(query.description != null && query.description.length() > 0) { |
4979 |
sb.append(" DESCRIPTION='"); |
sb.append(" DESCRIPTION='"); |
4980 |
sb.append(toEscapedString(query.description)).append("'"); |
sb.append(toEscapedText(query.description)).append("'"); |
4981 |
} |
} |
4982 |
|
|
4983 |
out.writeLine(sb.toString()); |
out.writeLine(sb.toString()); |
5030 |
StringBuffer sb = new StringBuffer(); |
StringBuffer sb = new StringBuffer(); |
5031 |
sb.append("FIND DB_INSTRUMENTS"); |
sb.append("FIND DB_INSTRUMENTS"); |
5032 |
if(nonRecursive) sb.append(" NON_RECURSIVE"); |
if(nonRecursive) sb.append(" NON_RECURSIVE"); |
5033 |
sb.append(" '").append(dir).append("'"); |
sb.append(" '").append(conv(dir)).append("'"); |
5034 |
|
|
5035 |
if(query.name != null && query.name.length() > 0) { |
if(query.name != null && query.name.length() > 0) { |
5036 |
sb.append(" NAME='").append(toEscapedString(query.name)).append("'"); |
sb.append(" NAME='").append(toEscapedText(query.name)).append("'"); |
5037 |
} |
} |
5038 |
|
|
5039 |
if(query.formatFamilies.size() > 0) { |
if(query.formatFamilies.size() > 0) { |
5074 |
|
|
5075 |
if(query.description != null && query.description.length() > 0) { |
if(query.description != null && query.description.length() > 0) { |
5076 |
sb.append(" DESCRIPTION='"); |
sb.append(" DESCRIPTION='"); |
5077 |
sb.append(toEscapedString(query.description)).append("'"); |
sb.append(toEscapedText(query.description)).append("'"); |
5078 |
} |
} |
5079 |
|
|
5080 |
if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) { |
if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) { |
5087 |
} |
} |
5088 |
|
|
5089 |
if(query.product != null && query.product.length() > 0) { |
if(query.product != null && query.product.length() > 0) { |
5090 |
sb.append(" PRODUCT='").append(toEscapedString(query.product)).append("'"); |
sb.append(" PRODUCT='").append(toEscapedText(query.product)).append("'"); |
5091 |
} |
} |
5092 |
|
|
5093 |
if(query.artists != null && query.artists.length() > 0) { |
if(query.artists != null && query.artists.length() > 0) { |
5094 |
sb.append(" ARTISTS='").append(toEscapedString(query.artists)).append("'"); |
sb.append(" ARTISTS='").append(toEscapedText(query.artists)).append("'"); |
5095 |
} |
} |
5096 |
|
|
5097 |
if(query.keywords != null && query.keywords.length() > 0) { |
if(query.keywords != null && query.keywords.length() > 0) { |
5098 |
sb.append(" KEYWORDS='"); |
sb.append(" KEYWORDS='"); |
5099 |
sb.append(toEscapedString(query.keywords)).append("'"); |
sb.append(toEscapedText(query.keywords)).append("'"); |
5100 |
} |
} |
5101 |
|
|
5102 |
out.writeLine(sb.toString()); |
out.writeLine(sb.toString()); |
5112 |
} |
} |
5113 |
|
|
5114 |
/** |
/** |
5115 |
|
* Returns a list of all instrument files in the database |
5116 |
|
* that that don't exist in the filesystem. |
5117 |
|
* @throws IOException If some I/O error occurs. |
5118 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
5119 |
|
* @throws LSException If other error occurs. |
5120 |
|
*/ |
5121 |
|
public synchronized String[] |
5122 |
|
findLostDbInstrumentFiles() throws IOException, LscpException, LSException { |
5123 |
|
|
5124 |
|
verifyConnection(); |
5125 |
|
out.writeLine("FIND LOST DB_INSTRUMENT_FILES"); |
5126 |
|
if(getPrintOnlyMode()) return null; |
5127 |
|
|
5128 |
|
return parseEscapedStringList(getSingleLineResultSet().getResult()); |
5129 |
|
} |
5130 |
|
|
5131 |
|
/** |
5132 |
* Gets status information about the specified job. |
* Gets status information about the specified job. |
5133 |
* @param jobId The ID of the job. |
* @param jobId The ID of the job. |
5134 |
* @return A <code>ScanJobInfo</code> instance providing information |
* @return A <code>ScanJobInfo</code> instance providing information |
5166 |
} |
} |
5167 |
|
|
5168 |
/** |
/** |
5169 |
* Resets the specified sampler channel. |
* Resets the whole sampler. |
5170 |
* |
* |
|
* @param samplerChn The sampler channel number. |
|
|
* |
|
5171 |
* @throws IOException If some I/O error occurs. |
* @throws IOException If some I/O error occurs. |
5172 |
* @throws LscpException If LSCP protocol corruption occurs. |
* @throws LscpException If LSCP protocol corruption occurs. |
|
* @throws LSException If <code>samplerChn</code> is not a valid channel number or if |
|
|
* there is no engine assigned yet to the specified sampler channel. |
|
|
* @see #getSamplerChannels |
|
5173 |
*/ |
*/ |
5174 |
public synchronized void |
public synchronized void |
5175 |
resetChannel(int samplerChn) throws IOException, LscpException, LSException { |
resetSampler() throws IOException, LscpException { |
5176 |
verifyConnection(); |
verifyConnection(); |
5177 |
out.writeLine("RESET CHANNEL " + samplerChn); |
out.writeLine("RESET"); |
5178 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return; |
5179 |
|
|
5180 |
ResultSet rs = getEmptyResultSet(); |
try { ResultSet rs = getEmptyResultSet(); } |
5181 |
|
catch(LSException x) { getLogger().warning(x.getMessage()); } |
5182 |
} |
} |
5183 |
|
|
5184 |
/** |
/** |
5185 |
* Resets the whole sampler. |
* Gets the current number of all active streams. |
5186 |
* |
* @return The current number of all active streams. |
5187 |
* @throws IOException If some I/O error occurs. |
* @throws IOException If some I/O error occurs. |
5188 |
* @throws LscpException If LSCP protocol corruption occurs. |
* @throws LscpException If LSCP protocol corruption occurs. |
5189 |
|
* @throws LSException If some other error occurs. |
5190 |
*/ |
*/ |
5191 |
public synchronized void |
public synchronized int |
5192 |
resetSampler() throws IOException, LscpException { |
getTotalStreamCount() throws IOException, LscpException, LSException { |
5193 |
verifyConnection(); |
verifyConnection(); |
5194 |
out.writeLine("RESET"); |
out.writeLine("GET TOTAL_STREAM_COUNT"); |
5195 |
if(getPrintOnlyMode()) return; |
if(getPrintOnlyMode()) return -1; |
5196 |
|
|
5197 |
try { ResultSet rs = getEmptyResultSet(); } |
String s = getSingleLineResultSet().getResult(); |
5198 |
catch(LSException x) { getLogger().warning(x.getMessage()); } |
return parseInt(s); |
5199 |
} |
} |
5200 |
|
|
5201 |
/** |
/** |
5287 |
ResultSet rs = getEmptyResultSet(); |
ResultSet rs = getEmptyResultSet(); |
5288 |
} |
} |
5289 |
|
|
5290 |
|
/** |
5291 |
|
* Gets the number of instruments in the specified instrument file. |
5292 |
|
* @param filename The absolute path name of the instrument file. |
5293 |
|
* @return The number of instruments in the specified instrument file. |
5294 |
|
* @throws IOException If some I/O error occurs. |
5295 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
5296 |
|
* @throws LSException If the file is not found, or other error occur. |
5297 |
|
*/ |
5298 |
|
public synchronized int |
5299 |
|
getFileInstrumentCount(String filename) throws IOException, LscpException, LSException { |
5300 |
|
verifyConnection(); |
5301 |
|
out.writeLine("GET FILE INSTRUMENTS '" + conv(filename) +"'"); |
5302 |
|
if(getPrintOnlyMode()) return -1; |
5303 |
|
|
5304 |
|
String s = getSingleLineResultSet().getResult(); |
5305 |
|
return parseInt(s); |
5306 |
|
} |
5307 |
|
|
5308 |
|
/** |
5309 |
|
* Gets information about the instrument with index |
5310 |
|
* <code>instrIdx</code> in the specified instrument file. |
5311 |
|
* @param filename The absolute path name of the instrument file. |
5312 |
|
* @param instrIdx The index of the instrument in the specified instrument file. |
5313 |
|
* @throws IOException If some I/O error occurs. |
5314 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
5315 |
|
* @throws LSException If failed to retrieve information. |
5316 |
|
*/ |
5317 |
|
public synchronized Instrument |
5318 |
|
getFileInstrumentInfo(String filename, int instrIdx) |
5319 |
|
throws IOException, LscpException, LSException { |
5320 |
|
|
5321 |
|
verifyConnection(); |
5322 |
|
out.writeLine("GET FILE INSTRUMENT INFO '" + conv(filename) + "' " + String.valueOf(instrIdx)); |
5323 |
|
if(getPrintOnlyMode()) return null; |
5324 |
|
|
5325 |
|
ResultSet rs = getMultiLineResultSet(); |
5326 |
|
Instrument instr = new FileInstrument(rs.getMultiLineResult()) { }; |
5327 |
|
|
5328 |
|
return instr; |
5329 |
|
} |
5330 |
|
|
5331 |
|
/** |
5332 |
|
* Gets the list of instruments in the specified instrument file. |
5333 |
|
* @param filename The absolute path name of the instrument file. |
5334 |
|
* @return An <code>Instrument</code> array providing |
5335 |
|
* information about all instruments in the specified instrument file. |
5336 |
|
* @throws IOException If some I/O error occurs. |
5337 |
|
* @throws LscpException If LSCP protocol corruption occurs. |
5338 |
|
* @throws LSException If the specified file name is invalid. |
5339 |
|
*/ |
5340 |
|
public synchronized Instrument[] |
5341 |
|
getFileInstruments(String filename) throws IOException, LscpException, LSException { |
5342 |
|
int l = getFileInstrumentCount(filename); |
5343 |
|
if(l < 0) return null; |
5344 |
|
Instrument[] instrS = new FileInstrument[l]; |
5345 |
|
|
5346 |
|
for(int i = 0; i < instrS.length; i++) { |
5347 |
|
instrS[i] = getFileInstrumentInfo(filename, i); |
5348 |
|
} |
5349 |
|
return instrS; |
5350 |
|
} |
5351 |
|
|
5352 |
|
private static class FileInstrument extends AbstractInstrument { |
5353 |
|
FileInstrument(String[] resultSet) throws LscpException { |
5354 |
|
super(resultSet); |
5355 |
|
} |
5356 |
|
|
5357 |
|
public String |
5358 |
|
getEngine() { |
5359 |
|
// TODO: engine lookup? |
5360 |
|
return getFormatFamily(); |
5361 |
|
} |
5362 |
|
|
5363 |
|
public boolean |
5364 |
|
parse(String s) throws LscpException { |
5365 |
|
if(s.startsWith("PRODUCT: ") || s.startsWith("ARTISTS: ")) return true; |
5366 |
|
return super.parse(s); |
5367 |
|
} |
5368 |
|
} |
5369 |
|
|
5370 |
private void |
private void |
5371 |
getEmptyResultSets(int count, String err) throws LSException { |
getEmptyResultSets(int count, String err) throws LSException { |
5372 |
StringBuffer sb = new StringBuffer(); |
StringBuffer sb = new StringBuffer(); |