322 |
continue; //Ignore CR |
continue; //Ignore CR |
323 |
if (c == '\n') { |
if (c == '\n') { |
324 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
325 |
bufferedCommands[socket] += "\n"; |
bufferedCommands[socket] += "\r\n"; |
326 |
return true; //Complete command was read |
return true; //Complete command was read |
327 |
} |
} |
328 |
bufferedCommands[socket] += c; |
bufferedCommands[socket] += c; |
496 |
if (!pSamplerChannel->GetAudioOutputDevice()) |
if (!pSamplerChannel->GetAudioOutputDevice()) |
497 |
throw Exception("No audio output device connected to sampler channel"); |
throw Exception("No audio output device connected to sampler channel"); |
498 |
if (bBackground) { |
if (bBackground) { |
499 |
InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel); |
InstrumentManager::instrument_id_t id; |
500 |
|
id.FileName = Filename; |
501 |
|
id.Index = uiInstrument; |
502 |
|
InstrumentManager::LoadInstrumentInBackground(id, pEngineChannel); |
503 |
} |
} |
504 |
else { |
else { |
505 |
// tell the engine channel which instrument to load |
// tell the engine channel which instrument to load |
591 |
*/ |
*/ |
592 |
String LSCPServer::GetAvailableEngines() { |
String LSCPServer::GetAvailableEngines() { |
593 |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
594 |
LSCPResultSet result("1"); |
LSCPResultSet result; |
595 |
|
try { |
596 |
|
int n = EngineFactory::AvailableEngineTypes().size(); |
597 |
|
result.Add(n); |
598 |
|
} |
599 |
|
catch (Exception e) { |
600 |
|
result.Error(e); |
601 |
|
} |
602 |
return result.Produce(); |
return result.Produce(); |
603 |
} |
} |
604 |
|
|
607 |
*/ |
*/ |
608 |
String LSCPServer::ListAvailableEngines() { |
String LSCPServer::ListAvailableEngines() { |
609 |
dmsg(2,("LSCPServer: ListAvailableEngines()\n")); |
dmsg(2,("LSCPServer: ListAvailableEngines()\n")); |
610 |
LSCPResultSet result("\'GIG\'"); |
LSCPResultSet result; |
611 |
|
try { |
612 |
|
String s = EngineFactory::AvailableEngineTypesAsString(); |
613 |
|
result.Add(s); |
614 |
|
} |
615 |
|
catch (Exception e) { |
616 |
|
result.Error(e); |
617 |
|
} |
618 |
return result.Produce(); |
return result.Produce(); |
619 |
} |
} |
620 |
|
|
662 |
String AudioRouting; |
String AudioRouting; |
663 |
int Mute = 0; |
int Mute = 0; |
664 |
bool Solo = false; |
bool Solo = false; |
665 |
|
String MidiInstrumentMap; |
666 |
|
|
667 |
if (pEngineChannel) { |
if (pEngineChannel) { |
668 |
EngineName = pEngineChannel->EngineName(); |
EngineName = pEngineChannel->EngineName(); |
680 |
} |
} |
681 |
Mute = pEngineChannel->GetMute(); |
Mute = pEngineChannel->GetMute(); |
682 |
Solo = pEngineChannel->GetSolo(); |
Solo = pEngineChannel->GetSolo(); |
683 |
|
if (pEngineChannel->UsesNoMidiInstrumentMap()) |
684 |
|
MidiInstrumentMap = "NONE"; |
685 |
|
else if (pEngineChannel->UsesDefaultMidiInstrumentMap()) |
686 |
|
MidiInstrumentMap = "DEFAULT"; |
687 |
|
else |
688 |
|
MidiInstrumentMap = ToString(pEngineChannel->GetMidiInstrumentMap()); |
689 |
} |
} |
690 |
|
|
691 |
result.Add("ENGINE_NAME", EngineName); |
result.Add("ENGINE_NAME", EngineName); |
707 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
708 |
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
709 |
result.Add("SOLO", Solo); |
result.Add("SOLO", Solo); |
710 |
|
result.Add("MIDI_INSTRUMENT_MAP", MidiInstrumentMap); |
711 |
} |
} |
712 |
catch (Exception e) { |
catch (Exception e) { |
713 |
result.Error(e); |
result.Error(e); |
1555 |
} |
} |
1556 |
} |
} |
1557 |
|
|
1558 |
|
String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name) { |
1559 |
|
dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n")); |
1560 |
|
|
1561 |
|
midi_prog_index_t idx; |
1562 |
|
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
1563 |
|
idx.midi_bank_lsb = MidiBank & 0x7f; |
1564 |
|
idx.midi_prog = MidiProg; |
1565 |
|
|
1566 |
|
MidiInstrumentMapper::entry_t entry; |
1567 |
|
entry.EngineName = EngineType; |
1568 |
|
entry.InstrumentFile = InstrumentFile; |
1569 |
|
entry.InstrumentIndex = InstrumentIndex; |
1570 |
|
entry.LoadMode = LoadMode; |
1571 |
|
entry.Volume = Volume; |
1572 |
|
entry.Name = Name; |
1573 |
|
|
1574 |
|
LSCPResultSet result; |
1575 |
|
try { |
1576 |
|
// PERSISTENT mapping commands might bloock for a long time, so in |
1577 |
|
// that case we add/replace the mapping in another thread |
1578 |
|
bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT); |
1579 |
|
MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground); |
1580 |
|
} catch (Exception e) { |
1581 |
|
result.Error(e); |
1582 |
|
} |
1583 |
|
return result.Produce(); |
1584 |
|
} |
1585 |
|
|
1586 |
|
String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) { |
1587 |
|
dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n")); |
1588 |
|
|
1589 |
|
midi_prog_index_t idx; |
1590 |
|
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
1591 |
|
idx.midi_bank_lsb = MidiBank & 0x7f; |
1592 |
|
idx.midi_prog = MidiProg; |
1593 |
|
|
1594 |
|
LSCPResultSet result; |
1595 |
|
try { |
1596 |
|
MidiInstrumentMapper::RemoveEntry(MidiMapID, idx); |
1597 |
|
} catch (Exception e) { |
1598 |
|
result.Error(e); |
1599 |
|
} |
1600 |
|
return result.Produce(); |
1601 |
|
} |
1602 |
|
|
1603 |
|
String LSCPServer::GetMidiInstrumentMappings(uint MidiMapID) { |
1604 |
|
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
1605 |
|
LSCPResultSet result; |
1606 |
|
try { |
1607 |
|
result.Add(MidiInstrumentMapper::Entries(MidiMapID).size()); |
1608 |
|
} catch (Exception e) { |
1609 |
|
result.Error(e); |
1610 |
|
} |
1611 |
|
return result.Produce(); |
1612 |
|
} |
1613 |
|
|
1614 |
|
|
1615 |
|
String LSCPServer::GetAllMidiInstrumentMappings() { |
1616 |
|
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
1617 |
|
LSCPResultSet result; |
1618 |
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
1619 |
|
int totalMappings = 0; |
1620 |
|
for (int i = 0; i < maps.size(); i++) { |
1621 |
|
try { |
1622 |
|
totalMappings += MidiInstrumentMapper::Entries(maps[i]).size(); |
1623 |
|
} catch (Exception e) { /*NOOP*/ } |
1624 |
|
} |
1625 |
|
result.Add(totalMappings); |
1626 |
|
return result.Produce(); |
1627 |
|
} |
1628 |
|
|
1629 |
|
String LSCPServer::GetMidiInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) { |
1630 |
|
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
1631 |
|
LSCPResultSet result; |
1632 |
|
try { |
1633 |
|
midi_prog_index_t idx; |
1634 |
|
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
1635 |
|
idx.midi_bank_lsb = MidiBank & 0x7f; |
1636 |
|
idx.midi_prog = MidiProg; |
1637 |
|
|
1638 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID); |
1639 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx); |
1640 |
|
if (iter == mappings.end()) result.Error("there is no map entry with that index"); |
1641 |
|
else { // found |
1642 |
|
result.Add("NAME", iter->second.Name); |
1643 |
|
result.Add("ENGINE_NAME", iter->second.EngineName); |
1644 |
|
result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile); |
1645 |
|
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
1646 |
|
String instrumentName; |
1647 |
|
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
1648 |
|
if (pEngine) { |
1649 |
|
if (pEngine->GetInstrumentManager()) { |
1650 |
|
InstrumentManager::instrument_id_t instrID; |
1651 |
|
instrID.FileName = iter->second.InstrumentFile; |
1652 |
|
instrID.Index = iter->second.InstrumentIndex; |
1653 |
|
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
1654 |
|
} |
1655 |
|
EngineFactory::Destroy(pEngine); |
1656 |
|
} |
1657 |
|
result.Add("INSTRUMENT_NAME", instrumentName); |
1658 |
|
switch (iter->second.LoadMode) { |
1659 |
|
case MidiInstrumentMapper::ON_DEMAND: |
1660 |
|
result.Add("LOAD_MODE", "ON_DEMAND"); |
1661 |
|
break; |
1662 |
|
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
1663 |
|
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
1664 |
|
break; |
1665 |
|
case MidiInstrumentMapper::PERSISTENT: |
1666 |
|
result.Add("LOAD_MODE", "PERSISTENT"); |
1667 |
|
break; |
1668 |
|
default: |
1669 |
|
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
1670 |
|
} |
1671 |
|
result.Add("VOLUME", iter->second.Volume); |
1672 |
|
} |
1673 |
|
} catch (Exception e) { |
1674 |
|
result.Error(e); |
1675 |
|
} |
1676 |
|
return result.Produce(); |
1677 |
|
} |
1678 |
|
|
1679 |
|
String LSCPServer::ListMidiInstrumentMappings(uint MidiMapID) { |
1680 |
|
dmsg(2,("LSCPServer: ListMidiInstrumentMappings()\n")); |
1681 |
|
LSCPResultSet result; |
1682 |
|
try { |
1683 |
|
String s; |
1684 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID); |
1685 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin(); |
1686 |
|
for (; iter != mappings.end(); iter++) { |
1687 |
|
if (s.size()) s += ","; |
1688 |
|
s += "{" + ToString(MidiMapID) + "," |
1689 |
|
+ ToString((int(iter->first.midi_bank_msb) << 7) & int(iter->first.midi_bank_lsb)) + "," |
1690 |
|
+ ToString(int(iter->first.midi_prog)) + "}"; |
1691 |
|
} |
1692 |
|
result.Add(s); |
1693 |
|
} catch (Exception e) { |
1694 |
|
result.Error(e); |
1695 |
|
} |
1696 |
|
return result.Produce(); |
1697 |
|
} |
1698 |
|
|
1699 |
|
String LSCPServer::ListAllMidiInstrumentMappings() { |
1700 |
|
dmsg(2,("LSCPServer: ListAllMidiInstrumentMappings()\n")); |
1701 |
|
LSCPResultSet result; |
1702 |
|
try { |
1703 |
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
1704 |
|
String s; |
1705 |
|
for (int i = 0; i < maps.size(); i++) { |
1706 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(maps[i]); |
1707 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin(); |
1708 |
|
for (; iter != mappings.end(); iter++) { |
1709 |
|
if (s.size()) s += ","; |
1710 |
|
s += "{" + ToString(maps[i]) + "," |
1711 |
|
+ ToString((int(iter->first.midi_bank_msb) << 7) & int(iter->first.midi_bank_lsb)) + "," |
1712 |
|
+ ToString(int(iter->first.midi_prog)) + "}"; |
1713 |
|
} |
1714 |
|
} |
1715 |
|
result.Add(s); |
1716 |
|
} catch (Exception e) { |
1717 |
|
result.Error(e); |
1718 |
|
} |
1719 |
|
return result.Produce(); |
1720 |
|
} |
1721 |
|
|
1722 |
|
String LSCPServer::ClearMidiInstrumentMappings(uint MidiMapID) { |
1723 |
|
dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n")); |
1724 |
|
LSCPResultSet result; |
1725 |
|
try { |
1726 |
|
MidiInstrumentMapper::RemoveAllEntries(MidiMapID); |
1727 |
|
} catch (Exception e) { |
1728 |
|
result.Error(e); |
1729 |
|
} |
1730 |
|
return result.Produce(); |
1731 |
|
} |
1732 |
|
|
1733 |
|
String LSCPServer::ClearAllMidiInstrumentMappings() { |
1734 |
|
dmsg(2,("LSCPServer: ClearAllMidiInstrumentMappings()\n")); |
1735 |
|
LSCPResultSet result; |
1736 |
|
try { |
1737 |
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
1738 |
|
for (int i = 0; i < maps.size(); i++) |
1739 |
|
MidiInstrumentMapper::RemoveAllEntries(maps[i]); |
1740 |
|
} catch (Exception e) { |
1741 |
|
result.Error(e); |
1742 |
|
} |
1743 |
|
return result.Produce(); |
1744 |
|
} |
1745 |
|
|
1746 |
|
String LSCPServer::AddMidiInstrumentMap(String MapName) { |
1747 |
|
dmsg(2,("LSCPServer: AddMidiInstrumentMap()\n")); |
1748 |
|
LSCPResultSet result; |
1749 |
|
try { |
1750 |
|
int MapID = MidiInstrumentMapper::AddMap(MapName); |
1751 |
|
result = LSCPResultSet(MapID); |
1752 |
|
} catch (Exception e) { |
1753 |
|
result.Error(e); |
1754 |
|
} |
1755 |
|
return result.Produce(); |
1756 |
|
} |
1757 |
|
|
1758 |
|
String LSCPServer::RemoveMidiInstrumentMap(uint MidiMapID) { |
1759 |
|
dmsg(2,("LSCPServer: RemoveMidiInstrumentMap()\n")); |
1760 |
|
LSCPResultSet result; |
1761 |
|
try { |
1762 |
|
MidiInstrumentMapper::RemoveMap(MidiMapID); |
1763 |
|
} catch (Exception e) { |
1764 |
|
result.Error(e); |
1765 |
|
} |
1766 |
|
return result.Produce(); |
1767 |
|
} |
1768 |
|
|
1769 |
|
String LSCPServer::RemoveAllMidiInstrumentMaps() { |
1770 |
|
dmsg(2,("LSCPServer: RemoveAllMidiInstrumentMaps()\n")); |
1771 |
|
LSCPResultSet result; |
1772 |
|
try { |
1773 |
|
MidiInstrumentMapper::RemoveAllMaps(); |
1774 |
|
} catch (Exception e) { |
1775 |
|
result.Error(e); |
1776 |
|
} |
1777 |
|
return result.Produce(); |
1778 |
|
} |
1779 |
|
|
1780 |
|
String LSCPServer::GetMidiInstrumentMaps() { |
1781 |
|
dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n")); |
1782 |
|
LSCPResultSet result; |
1783 |
|
try { |
1784 |
|
result.Add(MidiInstrumentMapper::Maps().size()); |
1785 |
|
} catch (Exception e) { |
1786 |
|
result.Error(e); |
1787 |
|
} |
1788 |
|
return result.Produce(); |
1789 |
|
} |
1790 |
|
|
1791 |
|
String LSCPServer::ListMidiInstrumentMaps() { |
1792 |
|
dmsg(2,("LSCPServer: ListMidiInstrumentMaps()\n")); |
1793 |
|
LSCPResultSet result; |
1794 |
|
try { |
1795 |
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
1796 |
|
String sList; |
1797 |
|
for (int i = 0; i < maps.size(); i++) { |
1798 |
|
if (sList != "") sList += ","; |
1799 |
|
sList += ToString(maps[i]); |
1800 |
|
} |
1801 |
|
result.Add(sList); |
1802 |
|
} catch (Exception e) { |
1803 |
|
result.Error(e); |
1804 |
|
} |
1805 |
|
return result.Produce(); |
1806 |
|
} |
1807 |
|
|
1808 |
|
String LSCPServer::GetMidiInstrumentMap(uint MidiMapID) { |
1809 |
|
dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n")); |
1810 |
|
LSCPResultSet result; |
1811 |
|
try { |
1812 |
|
result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID)); |
1813 |
|
} catch (Exception e) { |
1814 |
|
result.Error(e); |
1815 |
|
} |
1816 |
|
return result.Produce(); |
1817 |
|
} |
1818 |
|
|
1819 |
|
String LSCPServer::SetMidiInstrumentMapName(uint MidiMapID, String NewName) { |
1820 |
|
dmsg(2,("LSCPServer: SetMidiInstrumentMapName()\n")); |
1821 |
|
LSCPResultSet result; |
1822 |
|
try { |
1823 |
|
MidiInstrumentMapper::RenameMap(MidiMapID, NewName); |
1824 |
|
} catch (Exception e) { |
1825 |
|
result.Error(e); |
1826 |
|
} |
1827 |
|
return result.Produce(); |
1828 |
|
} |
1829 |
|
|
1830 |
|
/** |
1831 |
|
* Set the MIDI instrument map the given sampler channel shall use for |
1832 |
|
* handling MIDI program change messages. There are the following two |
1833 |
|
* special (negative) values: |
1834 |
|
* |
1835 |
|
* - (-1) : set to NONE (ignore program changes) |
1836 |
|
* - (-2) : set to DEFAULT map |
1837 |
|
*/ |
1838 |
|
String LSCPServer::SetChannelMap(uint uiSamplerChannel, int MidiMapID) { |
1839 |
|
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
1840 |
|
LSCPResultSet result; |
1841 |
|
try { |
1842 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1843 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1844 |
|
|
1845 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1846 |
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
1847 |
|
|
1848 |
|
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
1849 |
|
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
1850 |
|
else pEngineChannel->SetMidiInstrumentMap(MidiMapID); |
1851 |
|
} catch (Exception e) { |
1852 |
|
result.Error(e); |
1853 |
|
} |
1854 |
|
return result.Produce(); |
1855 |
|
} |
1856 |
|
|
1857 |
/** |
/** |
1858 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
1859 |
*/ |
*/ |
1892 |
LSCPResultSet result; |
LSCPResultSet result; |
1893 |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
1894 |
result.Add("VERSION", VERSION); |
result.Add("VERSION", VERSION); |
1895 |
result.Add("PROTOCOL_VERSION", "1.0"); |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
1896 |
return result.Produce(); |
return result.Produce(); |
1897 |
} |
} |
1898 |
|
|