/[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 942 by schoenebeck, Sat Nov 25 18:07:34 2006 UTC revision 947 by schoenebeck, Mon Nov 27 21:34:55 2006 UTC
# Line 496  String LSCPServer::LoadInstrument(String Line 496  String LSCPServer::LoadInstrument(String
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
# Line 1544  void  LSCPServer::UnmuteChannels() { Line 1547  void  LSCPServer::UnmuteChannels() {
1547      }      }
1548  }  }
1549    
1550    String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiBankMSB, uint MidiBankLSB, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name) {
1551        dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));
1552    
1553        midi_prog_index_t idx;
1554        idx.midi_bank_msb = MidiBankMSB;
1555        idx.midi_bank_lsb = MidiBankLSB;
1556        idx.midi_prog     = MidiProg;
1557    
1558        MidiInstrumentMapper::entry_t entry;
1559        entry.EngineName      = EngineType;
1560        entry.InstrumentFile  = InstrumentFile;
1561        entry.InstrumentIndex = InstrumentIndex;
1562        entry.LoadMode        = LoadMode;
1563        entry.Volume          = Volume;
1564        entry.Name            = Name;
1565    
1566        LSCPResultSet result;
1567        try {
1568            // PERSISTENT mapping commands might bloock for a long time, so in
1569            // that case we add/replace the mapping in another thread
1570            bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT);
1571            MidiInstrumentMapper::AddOrReplaceMapping(idx, entry, bInBackground);
1572        } catch (Exception e) {
1573            result.Error(e);
1574        }
1575        return result.Produce();
1576    }
1577    
1578    String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiBankMSB, uint MidiBankLSB, uint MidiProg) {
1579        dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n"));
1580    
1581        midi_prog_index_t idx;
1582        idx.midi_bank_msb = MidiBankMSB;
1583        idx.midi_bank_lsb = MidiBankLSB;
1584        idx.midi_prog     = MidiProg;
1585    
1586        LSCPResultSet result;
1587        try {
1588            MidiInstrumentMapper::RemoveMapping(idx);
1589        } catch (Exception e) {
1590            result.Error(e);
1591        }
1592        return result.Produce();
1593    }
1594    
1595    String LSCPServer::GetMidiIstrumentMappings() {
1596        dmsg(2,("LSCPServer: GetMidiIstrumentMappings()\n"));
1597        LSCPResultSet result;
1598        result.Add(MidiInstrumentMapper::Mappings().size());
1599        return result.Produce();
1600    }
1601    
1602    String LSCPServer::GetMidiInstrumentMapping(uint MidiBankMSB, uint MidiBankLSB, uint MidiProg) {
1603        dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
1604        LSCPResultSet result;
1605        try {
1606            midi_prog_index_t idx;
1607            idx.midi_bank_msb = MidiBankMSB;
1608            idx.midi_bank_lsb = MidiBankLSB;
1609            idx.midi_prog     = MidiProg;
1610    
1611            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Mappings();
1612            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);
1613            if (iter == mappings.end()) result.Error("there is no map entry with that index");
1614            else { // found
1615                result.Add("NAME", iter->second.Name);
1616                result.Add("ENGINE_NAME", iter->second.EngineName);
1617                result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile);
1618                result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);
1619                String instrumentName;
1620                Engine* pEngine = EngineFactory::Create(iter->second.EngineName);
1621                if (pEngine) {
1622                    if (pEngine->GetInstrumentManager()) {
1623                        InstrumentManager::instrument_id_t instrID;
1624                        instrID.FileName = iter->second.InstrumentFile;
1625                        instrID.Index    = iter->second.InstrumentIndex;
1626                        instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);
1627                    }
1628                    EngineFactory::Destroy(pEngine);
1629                }
1630                result.Add("INSTRUMENT_NAME", instrumentName);
1631                switch (iter->second.LoadMode) {
1632                    case MidiInstrumentMapper::ON_DEMAND:
1633                        result.Add("LOAD_MODE", "ON_DEMAND");
1634                        break;
1635                    case MidiInstrumentMapper::ON_DEMAND_HOLD:
1636                        result.Add("LOAD_MODE", "ON_DEMAND_HOLD");
1637                        break;
1638                    case MidiInstrumentMapper::PERSISTENT:
1639                        result.Add("LOAD_MODE", "PERSISTENT");
1640                        break;
1641                    default:
1642                        throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");
1643                }
1644                result.Add("VOLUME", iter->second.Volume);
1645            }
1646        } catch (Exception e) {
1647            result.Error(e);
1648        }
1649        return result.Produce();
1650    }
1651    
1652    String LSCPServer::ListMidiInstrumentMappings() {
1653        dmsg(2,("LSCPServer: ListMidiIstrumentMappings()\n"));
1654        LSCPResultSet result;
1655        try {
1656            String s;
1657            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Mappings();
1658            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1659            for (; iter != mappings.end(); iter++) {
1660                if (s.size()) s += ",";
1661                s += "{" + ToString(iter->first.midi_bank_msb) + ","
1662                         + ToString(iter->first.midi_bank_lsb) + ","
1663                         + ToString(iter->first.midi_prog)     + "}";
1664            }
1665            result.Add(s);
1666        } catch (Exception e) {
1667            result.Error(e);
1668        }
1669        return result.Produce();
1670    }
1671    
1672    String LSCPServer::ClearMidiInstrumentMappings() {
1673        dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n"));
1674        LSCPResultSet result;
1675        try {
1676            MidiInstrumentMapper::RemoveAllMappings();
1677        } catch (Exception e) {
1678            result.Error(e);
1679        }
1680        return result.Produce();
1681    }
1682    
1683  /**  /**
1684   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
1685   */   */
# Line 1582  String LSCPServer::GetServerInfo() { Line 1718  String LSCPServer::GetServerInfo() {
1718      LSCPResultSet result;      LSCPResultSet result;
1719      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
1720      result.Add("VERSION", VERSION);      result.Add("VERSION", VERSION);
1721      result.Add("PROTOCOL_VERSION", "1.1");      result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));
1722      return result.Produce();      return result.Produce();
1723  }  }
1724    

Legend:
Removed from v.942  
changed lines
  Added in v.947

  ViewVC Help
Powered by ViewVC