ChannelsMode GetChannelsMode() const { Parameters::StringType mode = Parameters::ZXTune::Sound::Backends::Mp3::CHANNELS_DEFAULT; Params->FindValue(Parameters::ZXTune::Sound::Backends::Mp3::CHANNELS, mode); if (mode == Parameters::ZXTune::Sound::Backends::Mp3::CHANNELS_DEFAULT) { return MODE_DEFAULT; } else if (mode == Parameters::ZXTune::Sound::Backends::Mp3::CHANNELS_STEREO) { return MODE_STEREO; } else if (mode == Parameters::ZXTune::Sound::Backends::Mp3::CHANNELS_JOINTSTEREO) { return MODE_JOINTSTEREO; } else if (mode == Parameters::ZXTune::Sound::Backends::Mp3::CHANNELS_MONO) { return MODE_MONO; } else { throw MakeFormattedError(THIS_LINE, translate("MP3 backend error: invalid channels mode '%1%'."), mode); } }
void CheckCurlResult(CURLcode code, Error::LocationRef loc) const { if (code != CURLE_OK) { throw MakeFormattedError(loc, translate("Network error happends: %1%"), Api->curl_easy_strerror(code)); } }
void CheckLameCall(int res, Error::LocationRef loc) { if (res < 0) { throw MakeFormattedError(loc, translate("Error in MP3 backend: %1%."), res); } }
void CheckVorbisCall(int res, Error::LocationRef loc) { if (res < 0) { throw MakeFormattedError(loc, translate("Error in OGG backend: code %1%."), res); } }
virtual Identifier::Ptr ResolveUri(const String& uri) const { Dbg("Resolving uri '%1%'", uri); if (const Identifier::Ptr id = Resolve(uri)) { return id; } Dbg(" No suitable provider found"); throw MakeFormattedError(THIS_LINE, translate("Failed to resolve uri '%1%'."), uri); }
void Reset() { int error = 0; const auto decoder = VorbisPtr( ::stb_vorbis_open_memory(static_cast<const uint8_t*>(Data->Content->Start()), int(Data->Content->Size()), &error, nullptr), &::stb_vorbis_close); if (!decoder) { throw MakeFormattedError(THIS_LINE, "Failed to create decoder. Error: %1%", error); } Decoder = decoder; }
uint_t GetBitrate() const { Parameters::IntType bitrate = Parameters::ZXTune::Sound::Backends::Mp3::BITRATE_DEFAULT; if (Params->FindValue(Parameters::ZXTune::Sound::Backends::Mp3::BITRATE, bitrate) && !Math::InRange<Parameters::IntType>(bitrate, BITRATE_MIN, BITRATE_MAX)) { throw MakeFormattedError(THIS_LINE, translate("MP3 backend error: bitrate (%1%) is out of range (%2%..%3%)."), static_cast<int_t>(bitrate), BITRATE_MIN, BITRATE_MAX); } return static_cast<uint_t>(bitrate); }
uint_t GetQuality() const { Parameters::IntType quality = Parameters::ZXTune::Sound::Backends::Mp3::QUALITY_DEFAULT; if (Params->FindValue(Parameters::ZXTune::Sound::Backends::Mp3::QUALITY, quality) && !Math::InRange<Parameters::IntType>(quality, QUALITY_MIN, QUALITY_MAX)) { throw MakeFormattedError(THIS_LINE, translate("MP3 backend error: quality (%1%) is out of range (%2%..%3%)."), static_cast<int_t>(quality), QUALITY_MIN, QUALITY_MAX); } return static_cast<uint_t>(quality); }
uint64_t ClockFreq() const override { Parameters::IntType val = Parameters::ZXTune::Core::AYM::CLOCKRATE_DEFAULT; if (Params->FindValue(Parameters::ZXTune::Core::AYM::CLOCKRATE, val) && !Math::InRange(val, Parameters::ZXTune::Core::AYM::CLOCKRATE_MIN, Parameters::ZXTune::Core::AYM::CLOCKRATE_MAX)) { throw MakeFormattedError(THIS_LINE, translate("Invalid clock frequency (%1%)."), val); } return val; }
uint_t GetBuffersCount() const { Parameters::IntType val = Parameters::ZXTune::Sound::Backends::Sdl::BUFFERS_DEFAULT; if (Accessor.FindValue(Parameters::ZXTune::Sound::Backends::Sdl::BUFFERS, val) && (!Math::InRange<Parameters::IntType>(val, BUFFERS_MIN, BUFFERS_MAX))) { throw MakeFormattedError(THIS_LINE, translate("SDL backend error: buffers count (%1%) is out of range (%2%..%3%)."), static_cast<int_t>(val), BUFFERS_MIN, BUFFERS_MAX); } return static_cast<uint_t>(val); }
std::size_t GetMinimalSize() const { Parameters::IntType minRawSize = Parameters::ZXTune::Core::Plugins::Raw::MIN_SIZE_DEFAULT; if (Accessor.FindValue(Parameters::ZXTune::Core::Plugins::Raw::MIN_SIZE, minRawSize) && minRawSize < Parameters::IntType(MIN_MINIMAL_RAW_SIZE)) { throw MakeFormattedError(THIS_LINE, translate("Specified minimal scan size (%1%). Should be more than %2%."), minRawSize, MIN_MINIMAL_RAW_SIZE); } return static_cast<std::size_t>(minRawSize); }
uint_t DutyCycleValue() const override { Parameters::IntType intVal = Parameters::ZXTune::Core::AYM::DUTY_CYCLE_DEFAULT; const bool found = Params->FindValue(Parameters::ZXTune::Core::AYM::DUTY_CYCLE, intVal); //duty cycle in percents should be in range 1..99 inc if (found && (intVal < Parameters::ZXTune::Core::AYM::DUTY_CYCLE_MIN || intVal > Parameters::ZXTune::Core::AYM::DUTY_CYCLE_MAX)) { throw MakeFormattedError(THIS_LINE, translate("Invalid duty cycle value (%1%)."), intVal); } return static_cast<uint_t>(intVal); }
void CheckCall(bool ok, Error::LocationRef loc) const { if (!ok) { if (const char* txt = SdlApi->SDL_GetError()) { throw MakeFormattedError(loc, translate("Error in SDL backend: %1%."), FromStdString(txt)); } throw Error(loc, translate("Unknown error in SDL backend.")); } }
void ApplyData(Chunk data) override { if (Check(data.front().Left(), ToCompare.Left()) && Check(data.front().Right(), ToCompare.Right())) { std::cout << "passed\n"; } else { std::cout << "failed\n"; throw MakeFormattedError(THIS_LINE, "Failed. Value=<%1%,%2%> while expected=<%3%,%4%>", data.front().Left(), data.front().Right(), ToCompare.Left(), ToCompare.Right()); } }
//TODO: pass callback to handle progress and other Binary::Container::Ptr Download() { std::unique_ptr<Dump> result(new Dump()); result->reserve(INITIAL_SIZE); Object.SetOption<void*>(CURLOPT_WRITEDATA, result.get(), THIS_LINE); Object.Perform(THIS_LINE); long retCode = 0; Object.GetInfo(CURLINFO_RESPONSE_CODE, &retCode, THIS_LINE); if (IsHttpErrorCode(retCode)) { throw MakeFormattedError(THIS_LINE, translate("Http error happends: %1%."), retCode); } return Binary::CreateContainer(std::move(result)); }
Binary::Container::Ptr Open(const String& path, const Parameters::Accessor& params, Log::ProgressCallback& cb) const override { try { const NetworkProviderParameters options(params); RemoteResource resource(Api); resource.SetSource(path); resource.SetOptions(options); resource.SetProgressCallback(cb); return resource.Download(); } catch (const Error& e) { throw MakeFormattedError(THIS_LINE, translate("Failed to open network resource '%1%'."), path).AddSuberror(e); } }
DataLocation::Ptr OpenLocation(Parameters::Accessor::Ptr coreParams, Binary::Container::Ptr data, const String& subpath) { const ArchivePluginsEnumerator::Ptr usedPlugins = ArchivePluginsEnumerator::Create(); DataLocation::Ptr resolvedLocation = boost::make_shared<UnresolvedLocation>(data); const Analysis::Path::Ptr sourcePath = Analysis::ParsePath(subpath, Text::MODULE_SUBPATH_DELIMITER[0]); for (Analysis::Path::Ptr unresolved = sourcePath; !unresolved->Empty(); unresolved = sourcePath->Extract(resolvedLocation->GetPath()->AsString())) { const String toResolve = unresolved->AsString(); Dbg("Resolving '%1%'", toResolve); if (!(resolvedLocation = TryToOpenLocation(*usedPlugins, *coreParams, resolvedLocation, *unresolved))) { throw MakeFormattedError(THIS_LINE, translate("Failed to resolve subpath '%1%'."), subpath); } } Dbg("Resolved '%1%'", subpath); return resolvedLocation; }
//duty-cycle related parameter: accumulate letters to bitmask functor inline uint_t LetterToMask(uint_t val, const Char letter) { static const Char LETTERS[] = {'A', 'B', 'C'}; static const uint_t MASKS[] = { Devices::AYM::CHANNEL_MASK_A, Devices::AYM::CHANNEL_MASK_B, Devices::AYM::CHANNEL_MASK_C, }; static_assert(sizeof(LETTERS) / sizeof(*LETTERS) == sizeof(MASKS) / sizeof(*MASKS), "Invalid layout"); const Char* const pos = std::find(LETTERS, std::end(LETTERS), letter); if (pos == std::end(LETTERS)) { throw MakeFormattedError(THIS_LINE, translate("Invalid duty cycle mask item: '%1%'."), String(1, letter)); } return val | MASKS[pos - LETTERS]; }
bool IsABRMode() const { Parameters::StringType mode = Parameters::ZXTune::Sound::Backends::Ogg::MODE_DEFAULT; Params->FindValue(Parameters::ZXTune::Sound::Backends::Ogg::MODE, mode); if (mode == Parameters::ZXTune::Sound::Backends::Ogg::MODE_ABR) { return true; } else if (mode == Parameters::ZXTune::Sound::Backends::Ogg::MODE_QUALITY) { return false; } else { throw MakeFormattedError(THIS_LINE, translate("OGG backend error: invalid mode '%1%'."), mode); } }
Devices::AYM::LayoutType Layout() const override { Parameters::IntType intVal = Parameters::ZXTune::Core::AYM::LAYOUT_DEFAULT; if (Params->FindValue(Parameters::ZXTune::Core::AYM::LAYOUT, intVal)) { if (intVal < static_cast<int_t>(Devices::AYM::LAYOUT_ABC) || intVal >= static_cast<int_t>(Devices::AYM::LAYOUT_LAST)) { throw MakeFormattedError(THIS_LINE, translate("Invalid layout value (%1%)."), intVal); } return static_cast<Devices::AYM::LayoutType>(intVal); } Parameters::StringType strVal; if (Params->FindValue(Parameters::ZXTune::Core::AYM::LAYOUT, strVal)) { return String2Layout(strVal); } return Devices::AYM::LAYOUT_ABC; }
void FreqTable(FrequencyTable& table) const override { Parameters::StringType newName; if (Params->FindValue(Parameters::ZXTune::Core::AYM::TABLE, newName)) { GetFreqTable(newName, table); } else { Parameters::DataType newData; if (Params->FindValue(Parameters::ZXTune::Core::AYM::TABLE, newData)) { // as dump if (newData.size() != table.size() * sizeof(table.front())) { throw MakeFormattedError(THIS_LINE, translate("Invalid frequency table size (%1%)."), newData.size()); } std::memcpy(&table.front(), &newData.front(), newData.size()); } } }
BitrateMode GetBitrateMode() const { Parameters::StringType mode = Parameters::ZXTune::Sound::Backends::Mp3::MODE_DEFAULT; Params->FindValue(Parameters::ZXTune::Sound::Backends::Mp3::MODE, mode); if (mode == Parameters::ZXTune::Sound::Backends::Mp3::MODE_CBR) { return MODE_CBR; } else if (mode == Parameters::ZXTune::Sound::Backends::Mp3::MODE_VBR) { return MODE_VBR; } else if (mode == Parameters::ZXTune::Sound::Backends::Mp3::MODE_ABR) { return MODE_ABR; } else { throw MakeFormattedError(THIS_LINE, translate("MP3 backend error: invalid bitrate mode '%1%'."), mode); } }
Devices::AYM::LayoutType String2Layout(const String& str) { if (str == Text::MODULE_LAYOUT_ABC) { return Devices::AYM::LAYOUT_ABC; } else if (str == Text::MODULE_LAYOUT_ACB) { return Devices::AYM::LAYOUT_ACB; } else if (str == Text::MODULE_LAYOUT_BAC) { return Devices::AYM::LAYOUT_BAC; } else if (str == Text::MODULE_LAYOUT_BCA) { return Devices::AYM::LAYOUT_BCA; } else if (str == Text::MODULE_LAYOUT_CBA) { return Devices::AYM::LAYOUT_CBA; } else if (str == Text::MODULE_LAYOUT_CAB) { return Devices::AYM::LAYOUT_CAB; } else if (str == Text::MODULE_LAYOUT_MONO) { return Devices::AYM::LAYOUT_MONO; } else { throw MakeFormattedError(THIS_LINE, translate("Invalid layout value (%1%)."), str); } }