/[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 1481 by senoner, Wed Nov 14 23:42:15 2007 UTC revision 1535 by iliev, Mon Dec 3 13:59:03 2007 UTC
# Line 2383  String LSCPServer::SetGlobalVolume(doubl Line 2383  String LSCPServer::SetGlobalVolume(doubl
2383      return result.Produce();      return result.Produce();
2384  }  }
2385    
2386    String LSCPServer::GetFileInstruments(String Filename) {
2387        dmsg(2,("LSCPServer: GetFileInstruments(String Filename=%s)\n",Filename.c_str()));
2388        LSCPResultSet result;
2389        try {
2390            VerifyFile(Filename);
2391        } catch (Exception e) {
2392            result.Error(e);
2393            return result.Produce();
2394        }
2395        // try to find a sampler engine that can handle the file
2396        bool bFound = false;
2397        std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes();
2398        for (int i = 0; !bFound && i < engineTypes.size(); i++) {
2399            Engine* pEngine = NULL;
2400            try {
2401                pEngine = EngineFactory::Create(engineTypes[i]);
2402                if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine");
2403                InstrumentManager* pManager = pEngine->GetInstrumentManager();
2404                if (pManager) {
2405                    std::vector<InstrumentManager::instrument_id_t> IDs =
2406                        pManager->GetInstrumentFileContent(Filename);
2407                    // return the amount of instruments in the file
2408                    result.Add(IDs.size());
2409                    // no more need to ask other engine types
2410                    bFound = true;
2411                } else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str()));
2412            } catch (Exception e) {
2413                // NOOP, as exception is thrown if engine doesn't support file
2414            }
2415            if (pEngine) EngineFactory::Destroy(pEngine);
2416        }
2417    
2418        if (!bFound) result.Error("Unknown file format");
2419        return result.Produce();
2420    }
2421    
2422    String LSCPServer::ListFileInstruments(String Filename) {
2423        dmsg(2,("LSCPServer: ListFileInstruments(String Filename=%s)\n",Filename.c_str()));
2424        LSCPResultSet result;
2425        try {
2426            VerifyFile(Filename);
2427        } catch (Exception e) {
2428            result.Error(e);
2429            return result.Produce();
2430        }
2431        // try to find a sampler engine that can handle the file
2432        bool bFound = false;
2433        std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes();
2434        for (int i = 0; !bFound && i < engineTypes.size(); i++) {
2435            Engine* pEngine = NULL;
2436            try {
2437                pEngine = EngineFactory::Create(engineTypes[i]);
2438                if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine");
2439                InstrumentManager* pManager = pEngine->GetInstrumentManager();
2440                if (pManager) {
2441                    std::vector<InstrumentManager::instrument_id_t> IDs =
2442                        pManager->GetInstrumentFileContent(Filename);
2443                    // return a list of IDs of the instruments in the file
2444                    String s;
2445                    for (int j = 0; j < IDs.size(); j++) {
2446                        if (s.size()) s += ",";
2447                        s += ToString(IDs[j].Index);
2448                    }
2449                    result.Add(s);
2450                    // no more need to ask other engine types
2451                    bFound = true;
2452                } else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str()));
2453            } catch (Exception e) {
2454                // NOOP, as exception is thrown if engine doesn't support file
2455            }
2456            if (pEngine) EngineFactory::Destroy(pEngine);
2457        }
2458    
2459        if (!bFound) result.Error("Unknown file format");
2460        return result.Produce();
2461    }
2462    
2463    String LSCPServer::GetFileInstrumentInfo(String Filename, uint InstrumentID) {
2464        dmsg(2,("LSCPServer: GetFileInstrumentInfo(String Filename=%s, InstrumentID=%d)\n",Filename.c_str(),InstrumentID));
2465        LSCPResultSet result;
2466        try {
2467            VerifyFile(Filename);
2468        } catch (Exception e) {
2469            result.Error(e);
2470            return result.Produce();
2471        }
2472        InstrumentManager::instrument_id_t id;
2473        id.FileName = Filename;
2474        id.Index    = InstrumentID;
2475        // try to find a sampler engine that can handle the file
2476        bool bFound = false;
2477        std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes();
2478        for (int i = 0; !bFound && i < engineTypes.size(); i++) {
2479            Engine* pEngine = NULL;
2480            try {
2481                pEngine = EngineFactory::Create(engineTypes[i]);
2482                if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine");
2483                InstrumentManager* pManager = pEngine->GetInstrumentManager();
2484                if (pManager) {
2485                    InstrumentManager::instrument_info_t info =
2486                        pManager->GetInstrumentInfo(id);
2487                    // return detailed informations about the file
2488                    result.Add("NAME", info.InstrumentName);
2489                    result.Add("FORMAT_FAMILY", engineTypes[i]);
2490                    result.Add("FORMAT_VERSION", info.FormatVersion);
2491                    result.Add("PRODUCT", info.Product);
2492                    result.Add("ARTISTS", info.Artists);
2493                    // no more need to ask other engine types
2494                    bFound = true;
2495                } else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str()));
2496            } catch (Exception e) {
2497                // NOOP, as exception is thrown if engine doesn't support file
2498            }
2499            if (pEngine) EngineFactory::Destroy(pEngine);
2500        }
2501    
2502        if (!bFound) result.Error("Unknown file format");
2503        return result.Produce();
2504    }
2505    
2506    void LSCPServer::VerifyFile(String Filename) {
2507        struct stat statBuf;
2508        int res = stat(Filename.c_str(), &statBuf);
2509        if (res) {
2510            std::stringstream ss;
2511            ss << "Fail to stat `" << Filename << "`: " << strerror(errno);
2512            throw Exception(ss.str());
2513        }
2514    
2515        if (S_ISDIR(statBuf.st_mode)) {
2516            throw Exception("Directory is specified");
2517        }
2518    }
2519    
2520  /**  /**
2521   * 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
2522   * server for receiving event messages.   * server for receiving event messages.

Legend:
Removed from v.1481  
changed lines
  Added in v.1535

  ViewVC Help
Powered by ViewVC