/[svn]/linuxsampler/trunk/src/network/lscpserver.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/network/lscpserver.cpp

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

revision 951 by persson, Tue Nov 28 20:55:19 2006 UTC revision 1047 by schoenebeck, Mon Feb 19 19:38:04 2007 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005, 2006 Christian Schoenebeck                        *   *   Copyright (C) 2005 - 2007 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 24  Line 24 
24  #include "lscpserver.h"  #include "lscpserver.h"
25  #include "lscpresultset.h"  #include "lscpresultset.h"
26  #include "lscpevent.h"  #include "lscpevent.h"
27  //#include "../common/global.h"  #include "../common/global.h"
28    
29  #include <fcntl.h>  #include <fcntl.h>
30    
# Line 66  LSCPServer::LSCPServer(Sampler* pSampler Line 66  LSCPServer::LSCPServer(Sampler* pSampler
66      SocketAddress.sin_addr.s_addr = addr;      SocketAddress.sin_addr.s_addr = addr;
67      SocketAddress.sin_port        = port;      SocketAddress.sin_port        = port;
68      this->pSampler = pSampler;      this->pSampler = pSampler;
69        LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_count, "AUDIO_OUTPUT_DEVICE_COUNT");
70        LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_info, "AUDIO_OUTPUT_DEVICE_INFO");
71        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_count, "MIDI_INPUT_DEVICE_COUNT");
72        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_info, "MIDI_INPUT_DEVICE_INFO");
73      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");
74      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
75      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
76      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
77      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
78        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT");
79        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO");
80        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT");
81        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO");
82      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
83      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");
84      hSocket = -1;      hSocket = -1;
# Line 662  String LSCPServer::GetChannelInfo(uint u Line 670  String LSCPServer::GetChannelInfo(uint u
670          String AudioRouting;          String AudioRouting;
671          int Mute = 0;          int Mute = 0;
672          bool Solo = false;          bool Solo = false;
673            String MidiInstrumentMap;
674    
675          if (pEngineChannel) {          if (pEngineChannel) {
676              EngineName          = pEngineChannel->EngineName();              EngineName          = pEngineChannel->EngineName();
# Line 679  String LSCPServer::GetChannelInfo(uint u Line 688  String LSCPServer::GetChannelInfo(uint u
688              }              }
689              Mute = pEngineChannel->GetMute();              Mute = pEngineChannel->GetMute();
690              Solo = pEngineChannel->GetSolo();              Solo = pEngineChannel->GetSolo();
691                if (pEngineChannel->UsesNoMidiInstrumentMap())
692                    MidiInstrumentMap = "NONE";
693                else if (pEngineChannel->UsesDefaultMidiInstrumentMap())
694                    MidiInstrumentMap = "DEFAULT";
695                else
696                    MidiInstrumentMap = ToString(pEngineChannel->GetMidiInstrumentMap());
697          }          }
698    
699          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 700  String LSCPServer::GetChannelInfo(uint u Line 715  String LSCPServer::GetChannelInfo(uint u
715          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
716          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
717          result.Add("SOLO", Solo);          result.Add("SOLO", Solo);
718            result.Add("MIDI_INSTRUMENT_MAP", MidiInstrumentMap);
719      }      }
720      catch (Exception e) {      catch (Exception e) {
721           result.Error(e);           result.Error(e);
# Line 1177  String LSCPServer::SetAudioOutputChannel Line 1193  String LSCPServer::SetAudioOutputChannel
1193    
1194          // set new channel parameter value          // set new channel parameter value
1195          pParameter->SetValue(ParamVal);          pParameter->SetValue(ParamVal);
1196            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceId));
1197      }      }
1198      catch (Exception e) {      catch (Exception e) {
1199          result.Error(e);          result.Error(e);
# Line 1194  String LSCPServer::SetAudioOutputDeviceP Line 1211  String LSCPServer::SetAudioOutputDeviceP
1211          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1212          if (!parameters.count(ParamKey)) throw Exception("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw Exception("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1213          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1214            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceIndex));
1215      }      }
1216      catch (Exception e) {      catch (Exception e) {
1217          result.Error(e);          result.Error(e);
# Line 1211  String LSCPServer::SetMidiInputDevicePar Line 1229  String LSCPServer::SetMidiInputDevicePar
1229          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1230          if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1231          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1232            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1233      }      }
1234      catch (Exception e) {      catch (Exception e) {
1235          result.Error(e);          result.Error(e);
# Line 1235  String LSCPServer::SetMidiInputPortParam Line 1254  String LSCPServer::SetMidiInputPortParam
1254          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1255          if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
1256          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1257            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1258      }      }
1259      catch (Exception e) {      catch (Exception e) {
1260          result.Error(e);          result.Error(e);
# Line 1482  String LSCPServer::SetChannelSolo(bool b Line 1502  String LSCPServer::SetChannelSolo(bool b
1502    
1503          bool oldSolo = pEngineChannel->GetSolo();          bool oldSolo = pEngineChannel->GetSolo();
1504          bool hadSoloChannel = HasSoloChannel();          bool hadSoloChannel = HasSoloChannel();
1505            
1506          pEngineChannel->SetSolo(bSolo);          pEngineChannel->SetSolo(bSolo);
1507            
1508          if(!oldSolo && bSolo) {          if(!oldSolo && bSolo) {
1509              if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);              if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);
1510              if(!hadSoloChannel) MuteNonSoloChannels();              if(!hadSoloChannel) MuteNonSoloChannels();
1511          }          }
1512            
1513          if(oldSolo && !bSolo) {          if(oldSolo && !bSolo) {
1514              if(!HasSoloChannel()) UnmuteChannels();              if(!HasSoloChannel()) UnmuteChannels();
1515              else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);              else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);
# Line 1547  void  LSCPServer::UnmuteChannels() { Line 1567  void  LSCPServer::UnmuteChannels() {
1567      }      }
1568  }  }
1569    
1570  String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiBankMSB, uint MidiBankLSB, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name) {  String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name, bool bModal) {
1571      dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));      dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));
1572    
1573      midi_prog_index_t idx;      midi_prog_index_t idx;
1574      idx.midi_bank_msb = MidiBankMSB;      idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1575      idx.midi_bank_lsb = MidiBankLSB;      idx.midi_bank_lsb = MidiBank & 0x7f;
1576      idx.midi_prog     = MidiProg;      idx.midi_prog     = MidiProg;
1577    
1578      MidiInstrumentMapper::entry_t entry;      MidiInstrumentMapper::entry_t entry;
# Line 1565  String LSCPServer::AddOrReplaceMIDIInstr Line 1585  String LSCPServer::AddOrReplaceMIDIInstr
1585    
1586      LSCPResultSet result;      LSCPResultSet result;
1587      try {      try {
1588          // PERSISTENT mapping commands might bloock for a long time, so in          // PERSISTENT mapping commands might block for a long time, so in
1589          // that case we add/replace the mapping in another thread          // that case we add/replace the mapping in another thread in case
1590          bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT);          // the NON_MODAL argument was supplied, non persistent mappings
1591          MidiInstrumentMapper::AddOrReplaceMapping(idx, entry, bInBackground);          // should return immediately, so we don't need to do that for them
1592            bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal);
1593            MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground);
1594      } catch (Exception e) {      } catch (Exception e) {
1595          result.Error(e);          result.Error(e);
1596      }      }
1597      return result.Produce();      return result.Produce();
1598  }  }
1599    
1600  String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiBankMSB, uint MidiBankLSB, uint MidiProg) {  String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1601      dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n"));      dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n"));
1602    
1603      midi_prog_index_t idx;      midi_prog_index_t idx;
1604      idx.midi_bank_msb = MidiBankMSB;      idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1605      idx.midi_bank_lsb = MidiBankLSB;      idx.midi_bank_lsb = MidiBank & 0x7f;
1606      idx.midi_prog     = MidiProg;      idx.midi_prog     = MidiProg;
1607    
1608      LSCPResultSet result;      LSCPResultSet result;
1609      try {      try {
1610          MidiInstrumentMapper::RemoveMapping(idx);          MidiInstrumentMapper::RemoveEntry(MidiMapID, idx);
1611        } catch (Exception e) {
1612            result.Error(e);
1613        }
1614        return result.Produce();
1615    }
1616    
1617    String LSCPServer::GetMidiInstrumentMappings(uint MidiMapID) {
1618        dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));
1619        LSCPResultSet result;
1620        try {
1621            result.Add(MidiInstrumentMapper::Entries(MidiMapID).size());
1622      } catch (Exception e) {      } catch (Exception e) {
1623          result.Error(e);          result.Error(e);
1624      }      }
1625      return result.Produce();      return result.Produce();
1626  }  }
1627    
1628  String LSCPServer::GetMidiIstrumentMappings() {  
1629      dmsg(2,("LSCPServer: GetMidiIstrumentMappings()\n"));  String LSCPServer::GetAllMidiInstrumentMappings() {
1630        dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));
1631      LSCPResultSet result;      LSCPResultSet result;
1632      result.Add(MidiInstrumentMapper::Mappings().size());      std::vector<int> maps = MidiInstrumentMapper::Maps();
1633        int totalMappings = 0;
1634        for (int i = 0; i < maps.size(); i++) {
1635            try {
1636                totalMappings += MidiInstrumentMapper::Entries(maps[i]).size();
1637            } catch (Exception e) { /*NOOP*/ }
1638        }
1639        result.Add(totalMappings);
1640      return result.Produce();      return result.Produce();
1641  }  }
1642    
1643  String LSCPServer::GetMidiInstrumentMapping(uint MidiBankMSB, uint MidiBankLSB, uint MidiProg) {  String LSCPServer::GetMidiInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1644      dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));      dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
1645      LSCPResultSet result;      LSCPResultSet result;
1646      try {      try {
1647          midi_prog_index_t idx;          midi_prog_index_t idx;
1648          idx.midi_bank_msb = MidiBankMSB;          idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1649          idx.midi_bank_lsb = MidiBankLSB;          idx.midi_bank_lsb = MidiBank & 0x7f;
1650          idx.midi_prog     = MidiProg;          idx.midi_prog     = MidiProg;
1651    
1652          std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Mappings();          std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1653          std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);          std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);
1654          if (iter == mappings.end()) result.Error("there is no map entry with that index");          if (iter == mappings.end()) result.Error("there is no map entry with that index");
1655          else { // found          else { // found
# Line 1649  String LSCPServer::GetMidiInstrumentMapp Line 1690  String LSCPServer::GetMidiInstrumentMapp
1690      return result.Produce();      return result.Produce();
1691  }  }
1692    
1693  String LSCPServer::ListMidiInstrumentMappings() {  String LSCPServer::ListMidiInstrumentMappings(uint MidiMapID) {
1694      dmsg(2,("LSCPServer: ListMidiIstrumentMappings()\n"));      dmsg(2,("LSCPServer: ListMidiInstrumentMappings()\n"));
1695      LSCPResultSet result;      LSCPResultSet result;
1696      try {      try {
1697          String s;          String s;
1698          std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Mappings();          std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1699          std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();          std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1700          for (; iter != mappings.end(); iter++) {          for (; iter != mappings.end(); iter++) {
1701              if (s.size()) s += ",";              if (s.size()) s += ",";
1702              s += "{" + ToString(int(iter->first.midi_bank_msb)) + ","              s += "{" + ToString(MidiMapID) + ","
1703                       + ToString(int(iter->first.midi_bank_lsb)) + ","                       + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1704                       + ToString(int(iter->first.midi_prog))     + "}";                       + ToString(int(iter->first.midi_prog)) + "}";
1705          }          }
1706          result.Add(s);          result.Add(s);
1707      } catch (Exception e) {      } catch (Exception e) {
# Line 1669  String LSCPServer::ListMidiInstrumentMap Line 1710  String LSCPServer::ListMidiInstrumentMap
1710      return result.Produce();      return result.Produce();
1711  }  }
1712    
1713  String LSCPServer::ClearMidiInstrumentMappings() {  String LSCPServer::ListAllMidiInstrumentMappings() {
1714        dmsg(2,("LSCPServer: ListAllMidiInstrumentMappings()\n"));
1715        LSCPResultSet result;
1716        try {
1717            std::vector<int> maps = MidiInstrumentMapper::Maps();
1718            String s;
1719            for (int i = 0; i < maps.size(); i++) {
1720                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(maps[i]);
1721                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1722                for (; iter != mappings.end(); iter++) {
1723                    if (s.size()) s += ",";
1724                    s += "{" + ToString(maps[i]) + ","
1725                             + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1726                             + ToString(int(iter->first.midi_prog)) + "}";
1727                }
1728            }
1729            result.Add(s);
1730        } catch (Exception e) {
1731            result.Error(e);
1732        }
1733        return result.Produce();
1734    }
1735    
1736    String LSCPServer::ClearMidiInstrumentMappings(uint MidiMapID) {
1737      dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n"));      dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n"));
1738      LSCPResultSet result;      LSCPResultSet result;
1739      try {      try {
1740          MidiInstrumentMapper::RemoveAllMappings();          MidiInstrumentMapper::RemoveAllEntries(MidiMapID);
1741        } catch (Exception e) {
1742            result.Error(e);
1743        }
1744        return result.Produce();
1745    }
1746    
1747    String LSCPServer::ClearAllMidiInstrumentMappings() {
1748        dmsg(2,("LSCPServer: ClearAllMidiInstrumentMappings()\n"));
1749        LSCPResultSet result;
1750        try {
1751            std::vector<int> maps = MidiInstrumentMapper::Maps();
1752            for (int i = 0; i < maps.size(); i++)
1753                MidiInstrumentMapper::RemoveAllEntries(maps[i]);
1754        } catch (Exception e) {
1755            result.Error(e);
1756        }
1757        return result.Produce();
1758    }
1759    
1760    String LSCPServer::AddMidiInstrumentMap(String MapName) {
1761        dmsg(2,("LSCPServer: AddMidiInstrumentMap()\n"));
1762        LSCPResultSet result;
1763        try {
1764            int MapID = MidiInstrumentMapper::AddMap(MapName);
1765            result = LSCPResultSet(MapID);
1766        } catch (Exception e) {
1767            result.Error(e);
1768        }
1769        return result.Produce();
1770    }
1771    
1772    String LSCPServer::RemoveMidiInstrumentMap(uint MidiMapID) {
1773        dmsg(2,("LSCPServer: RemoveMidiInstrumentMap()\n"));
1774        LSCPResultSet result;
1775        try {
1776            MidiInstrumentMapper::RemoveMap(MidiMapID);
1777        } catch (Exception e) {
1778            result.Error(e);
1779        }
1780        return result.Produce();
1781    }
1782    
1783    String LSCPServer::RemoveAllMidiInstrumentMaps() {
1784        dmsg(2,("LSCPServer: RemoveAllMidiInstrumentMaps()\n"));
1785        LSCPResultSet result;
1786        try {
1787            MidiInstrumentMapper::RemoveAllMaps();
1788        } catch (Exception e) {
1789            result.Error(e);
1790        }
1791        return result.Produce();
1792    }
1793    
1794    String LSCPServer::GetMidiInstrumentMaps() {
1795        dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n"));
1796        LSCPResultSet result;
1797        try {
1798            result.Add(MidiInstrumentMapper::Maps().size());
1799        } catch (Exception e) {
1800            result.Error(e);
1801        }
1802        return result.Produce();
1803    }
1804    
1805    String LSCPServer::ListMidiInstrumentMaps() {
1806        dmsg(2,("LSCPServer: ListMidiInstrumentMaps()\n"));
1807        LSCPResultSet result;
1808        try {
1809            std::vector<int> maps = MidiInstrumentMapper::Maps();
1810            String sList;
1811            for (int i = 0; i < maps.size(); i++) {
1812                if (sList != "") sList += ",";
1813                sList += ToString(maps[i]);
1814            }
1815            result.Add(sList);
1816        } catch (Exception e) {
1817            result.Error(e);
1818        }
1819        return result.Produce();
1820    }
1821    
1822    String LSCPServer::GetMidiInstrumentMap(uint MidiMapID) {
1823        dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n"));
1824        LSCPResultSet result;
1825        try {
1826            result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID));
1827        } catch (Exception e) {
1828            result.Error(e);
1829        }
1830        return result.Produce();
1831    }
1832    
1833    String LSCPServer::SetMidiInstrumentMapName(uint MidiMapID, String NewName) {
1834        dmsg(2,("LSCPServer: SetMidiInstrumentMapName()\n"));
1835        LSCPResultSet result;
1836        try {
1837            MidiInstrumentMapper::RenameMap(MidiMapID, NewName);
1838        } catch (Exception e) {
1839            result.Error(e);
1840        }
1841        return result.Produce();
1842    }
1843    
1844    /**
1845     * Set the MIDI instrument map the given sampler channel shall use for
1846     * handling MIDI program change messages. There are the following two
1847     * special (negative) values:
1848     *
1849     *    - (-1) :  set to NONE (ignore program changes)
1850     *    - (-2) :  set to DEFAULT map
1851     */
1852    String LSCPServer::SetChannelMap(uint uiSamplerChannel, int MidiMapID) {
1853        dmsg(2,("LSCPServer: SetChannelMap()\n"));
1854        LSCPResultSet result;
1855        try {
1856            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1857            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1858    
1859            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1860            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1861    
1862            if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();
1863            else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();
1864            else                      pEngineChannel->SetMidiInstrumentMap(MidiMapID);
1865        } catch (Exception e) {
1866            result.Error(e);
1867        }
1868        return result.Produce();
1869    }
1870    
1871    String LSCPServer::CreateFxSend(uint uiSamplerChannel, uint MidiCtrl, String Name) {
1872        dmsg(2,("LSCPServer: CreateFxSend()\n"));
1873        LSCPResultSet result;
1874        try {
1875            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1876            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1877    
1878            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1879            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1880    
1881            FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name);
1882            if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)");
1883    
1884            result = LSCPResultSet(pFxSend->Id()); // success
1885        } catch (Exception e) {
1886            result.Error(e);
1887        }
1888        return result.Produce();
1889    }
1890    
1891    String LSCPServer::DestroyFxSend(uint uiSamplerChannel, uint FxSendID) {
1892        dmsg(2,("LSCPServer: DestroyFxSend()\n"));
1893        LSCPResultSet result;
1894        try {
1895            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1896            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1897    
1898            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1899            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1900    
1901            FxSend* pFxSend = NULL;
1902            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
1903                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
1904                    pFxSend = pEngineChannel->GetFxSend(i);
1905                    break;
1906                }
1907            }
1908            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
1909            pEngineChannel->RemoveFxSend(pFxSend);
1910        } catch (Exception e) {
1911            result.Error(e);
1912        }
1913        return result.Produce();
1914    }
1915    
1916    String LSCPServer::GetFxSends(uint uiSamplerChannel) {
1917        dmsg(2,("LSCPServer: GetFxSends()\n"));
1918        LSCPResultSet result;
1919        try {
1920            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1921            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1922    
1923            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1924            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1925    
1926            result.Add(pEngineChannel->GetFxSendCount());
1927        } catch (Exception e) {
1928            result.Error(e);
1929        }
1930        return result.Produce();
1931    }
1932    
1933    String LSCPServer::ListFxSends(uint uiSamplerChannel) {
1934        dmsg(2,("LSCPServer: ListFxSends()\n"));
1935        LSCPResultSet result;
1936        String list;
1937        try {
1938            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1939            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1940    
1941            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1942            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1943    
1944            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
1945                FxSend* pFxSend = pEngineChannel->GetFxSend(i);
1946                if (list != "") list += ",";
1947                list += ToString(pFxSend->Id());
1948            }
1949            result.Add(list);
1950        } catch (Exception e) {
1951            result.Error(e);
1952        }
1953        return result.Produce();
1954    }
1955    
1956    String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) {
1957        dmsg(2,("LSCPServer: GetFxSendInfo()\n"));
1958        LSCPResultSet result;
1959        try {
1960            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1961            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1962    
1963            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1964            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1965    
1966            FxSend* pFxSend = NULL;
1967            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
1968                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
1969                    pFxSend = pEngineChannel->GetFxSend(i);
1970                    break;
1971                }
1972            }
1973            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
1974    
1975            // gather audio routing informations
1976            String AudioRouting;
1977            for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
1978                if (AudioRouting != "") AudioRouting += ",";
1979                AudioRouting += ToString(pFxSend->DestinationChannel(chan));
1980            }
1981    
1982            // success
1983            result.Add("NAME", pFxSend->Name());
1984            result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
1985            result.Add("LEVEL", ToString(pFxSend->Level()));
1986            result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
1987        } catch (Exception e) {
1988            result.Error(e);
1989        }
1990        return result.Produce();
1991    }
1992    
1993    String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) {
1994        dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n"));
1995        LSCPResultSet result;
1996        try {
1997            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1998            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1999    
2000            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2001            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2002    
2003            FxSend* pFxSend = NULL;
2004            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2005                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2006                    pFxSend = pEngineChannel->GetFxSend(i);
2007                    break;
2008                }
2009            }
2010            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2011    
2012            pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel);
2013        } catch (Exception e) {
2014            result.Error(e);
2015        }
2016        return result.Produce();
2017    }
2018    
2019    String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) {
2020        dmsg(2,("LSCPServer: SetFxSendMidiController()\n"));
2021        LSCPResultSet result;
2022        try {
2023            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2024            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2025    
2026            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2027            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2028    
2029            FxSend* pFxSend = NULL;
2030            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2031                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2032                    pFxSend = pEngineChannel->GetFxSend(i);
2033                    break;
2034                }
2035            }
2036            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2037    
2038            pFxSend->SetMidiController(MidiController);
2039        } catch (Exception e) {
2040            result.Error(e);
2041        }
2042        return result.Produce();
2043    }
2044    
2045    String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) {
2046        dmsg(2,("LSCPServer: SetFxSendLevel()\n"));
2047        LSCPResultSet result;
2048        try {
2049            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2050            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2051    
2052            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2053            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2054    
2055            FxSend* pFxSend = NULL;
2056            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2057                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2058                    pFxSend = pEngineChannel->GetFxSend(i);
2059                    break;
2060                }
2061            }
2062            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2063    
2064            pFxSend->SetLevel((float)dLevel);
2065      } catch (Exception e) {      } catch (Exception e) {
2066          result.Error(e);          result.Error(e);
2067      }      }
# Line 1742  String LSCPServer::GetTotalVoiceCountMax Line 2130  String LSCPServer::GetTotalVoiceCountMax
2130      return result.Produce();      return result.Produce();
2131  }  }
2132    
2133    String LSCPServer::GetGlobalVolume() {
2134        LSCPResultSet result;
2135        result.Add(ToString(GLOBAL_VOLUME)); // see common/global.cpp
2136        return result.Produce();
2137    }
2138    
2139    String LSCPServer::SetGlobalVolume(double dVolume) {
2140        LSCPResultSet result;
2141        try {
2142            if (dVolume < 0) throw Exception("Volume may not be negative");
2143            GLOBAL_VOLUME = dVolume; // see common/global.cpp
2144        } catch (Exception e) {
2145            result.Error(e);
2146        }
2147        return result.Produce();
2148    }
2149    
2150  /**  /**
2151   * Will be called by the parser to subscribe a client (frontend) on the   * Will be called by the parser to subscribe a client (frontend) on the
2152   * server for receiving event messages.   * server for receiving event messages.

Legend:
Removed from v.951  
changed lines
  Added in v.1047

  ViewVC Help
Powered by ViewVC