コード例 #1
0
ファイル: AudioSourceOJM.cpp プロジェクト: TomoAlien/raindrop
bool AudioSourceOJM::Open(std::filesystem::path f)
{
    char sig[4];

    ifile = std::make_shared<std::ifstream>(f.string(), std::ios::binary);

    if (!ifile->is_open())
    {
        Log::Printf("AudioSourceOJM: unable to load %s.\n", f);
        return false;
    }

    ifile->read(sig, 4);

    switch (GetContainerKind(sig))
    {
    case M30:
        parseM30();
        break;
    case OMC:
        parseOMC();
        break;
    default:
        return false;
    }

    ifile->close();
    return true;
}
コード例 #2
0
ファイル: SongLoader.cpp プロジェクト: ingcoliptis/raindrop
std::shared_ptr<VSRG::Song> LoadSong7KFromFilename(std::filesystem::path Filename, std::filesystem::path Prefix, VSRG::Song *Sng)
{
	auto prefix = Prefix.string();

    bool AllocSong = false;
    if (!Sng)
    {
        AllocSong = true;
        Sng = new VSRG::Song();
    }

    std::wstring Ext = Utility::Widen(Filename.extension().string());

    // no extension
    if (!Filename.has_extension() || !VSRGValidExtension(Ext))
    {
        if (AllocSong) delete Sng;
        return nullptr;
    }

    Sng->SongDirectory = Prefix.string();
	auto fn = Prefix / Filename;
	auto fnu8 = Utility::Narrow(fn.wstring());

    for (int i = 0; i < sizeof(LoadersVSRG) / sizeof(loaderVSRGEntry_t); i++)
    {
        if (Ext == LoadersVSRG[i].Ext)
        {
            Log::LogPrintf("Load %s from disk...", fnu8.c_str());
            try
            {
                LoadersVSRG[i].LoadFunc(fn, Sng);
                Log::LogPrintf(" ok\n");
            }
            catch (std::exception &e)
            {
                Log::LogPrintf("Failure loading: %s\n", e.what());
            }
            break;
        }
    }

    if (AllocSong)
        return std::shared_ptr<VSRG::Song>(Sng);
    return nullptr;
}
コード例 #3
0
ファイル: SongLoader.cpp プロジェクト: ingcoliptis/raindrop
std::shared_ptr<VSRG::Song> LoadSong7KFromFilename(const std::filesystem::path& filename, VSRG::Song *Sng)
{
    if (!filename.has_extension())
    {
        return nullptr;
    }

    bool AllocSong = false;
    if (!Sng)
    {
        AllocSong = true;
        Sng = new VSRG::Song();
    }

    Sng->SongDirectory = filename.parent_path();

    for (int i = 0; i < sizeof(LoadersVSRG) / sizeof(loaderVSRGEntry_t); i++)
    {
        if (filename.extension() == LoadersVSRG[i].Ext)
        {
            Log::LogPrintf("Load %s from disk...", filename.string().c_str());
            try
            {
                LoadersVSRG[i].LoadFunc(filename, Sng);
                Log::LogPrintf(" ok\n");
            }
            catch (std::exception &e)
            {
                Log::LogPrintf("Failure loading %s: %s\n", filename.string().c_str(), e.what());
            }
            break;
        }
    }

    if (AllocSong)
        return std::shared_ptr<VSRG::Song>(Sng);
    return nullptr;
}
コード例 #4
0
//-----------------------------------------------------------
static bool loadFontFace(const std::filesystem::path& _fontname, FT_Face & face, std::filesystem::path & filename){
	std::filesystem::path fontname = _fontname;
	filename = ofToDataPath(_fontname,true);
	ofFile fontFile(filename,ofFile::Reference);
	int fontID = 0;
	if(!fontFile.exists()){
#ifdef TARGET_LINUX
        filename = linuxFontPathByName(fontname.string());
#elif defined(TARGET_OSX)
		if(fontname==OF_TTF_SANS){
			fontname = "Helvetica Neue";
			#if MAC_OS_X_VERSION_10_13 && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_13
				fontID = 0;
			#else
				fontID = 4;
			#endif
		}else if(fontname==OF_TTF_SERIF){
			fontname = "Times New Roman";
		}else if(fontname==OF_TTF_MONO){
			fontname = "Menlo Regular";
		}
        filename = osxFontPathByName(fontname.string());
#elif defined(TARGET_WIN32)
		if(fontname==OF_TTF_SANS){
			fontname = "Arial";
		}else if(fontname==OF_TTF_SERIF){
			fontname = "Times New Roman";
		}else if(fontname==OF_TTF_MONO){
			fontname = "Courier New";
		}
        filename = winFontPathByName(fontname.string());
#endif
		if(filename == "" ){
			ofLogError("ofTrueTypeFont") << "loadFontFace(): couldn't find font \"" << fontname << "\"";
			return false;
		}
		ofLogVerbose("ofTrueTypeFont") << "loadFontFace(): \"" << fontname << "\" not a file in data loading system font from \"" << filename << "\"";
	}
	FT_Error err;
    err = FT_New_Face( library, filename.string().c_str(), fontID, &face );
	if (err) {
		// simple error table in lieu of full table (see fterrors.h)
		string errorString = "unknown freetype";
		if(err == 1) errorString = "INVALID FILENAME";
		ofLogError("ofTrueTypeFont") << "loadFontFace(): couldn't create new face for \"" << fontname << "\": FT_Error " << err << " " << errorString;
		return false;
	}

	return true;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: keitee/kb
void print_pdf(
   fs::path const & pdfpath,
   fs::path const & dirpath)
{
   const int height = 842;
   const int width = 595;
   const int margin = 20;

   auto image_paths = get_images(dirpath);

   PDFWriter pdf;
   pdf.StartPDF(pdfpath.string(), ePDFVersion13);

   PDFPage* page = nullptr;
   PageContentContext* context = nullptr;

   auto top = height - margin;
   for (size_t i = 0; i < image_paths.size(); ++i)
   {
      auto dims = pdf.GetImageDimensions(image_paths[i]);

      if (i == 0 || top - dims.second < margin)
      {
         if (page != nullptr)
         {
            pdf.EndPageContentContext(context);
            pdf.WritePageAndRelease(page);
         }

         page = new PDFPage();
         page->SetMediaBox(PDFRectangle(0, 0, width, height));
         context = pdf.StartPageContentContext(page);

         top = height - margin;
      }

      context->DrawImage(margin, top - dims.second, image_paths[i]);

      top -= dims.second + margin;
   }

   if (page != nullptr)
   {
      pdf.EndPageContentContext(context);
      pdf.WritePageAndRelease(page);
   }

   pdf.EndPDF();
}
コード例 #6
0
ファイル: Convert.cpp プロジェクト: TomoAlien/raindrop
void ConvertToSMTiming(VSRG::Song *Sng, std::filesystem::path PathOut)
{
    TimingData BPS, VSpeeds, Warps;
    VSRG::Difficulty* Diff = Sng->Difficulties[0].get();
    Diff->GetPlayableData(nullptr, BPS, VSpeeds, Warps);

    std::ofstream out(PathOut.string());
    // Technically, stepmania's #OFFSET is actually #GAP, not #OFFSET.
    out << "#OFFSET:" << -Diff->Offset << ";\n";

    out << "#BPMS:";

    for (auto i = Diff->Timing.begin();
    i != Diff->Timing.end();
        ++i)
    {
        double Time = 0;
        double Value = 0;
        switch (Diff->BPMType)
        {
        case VSRG::Difficulty::BT_BEAT:
            Time = i->Time;
            Value = i->Value;
            break;
        case VSRG::Difficulty::BT_BEATSPACE:
            Time = i->Time;
            Value = 60000 / i->Value;
            break;
        case VSRG::Difficulty::BT_MS:
            Time = i->Time / 1000.0;
            Value = i->Value;
            break;
        }

        double Beat = QuantizeBeat(IntegrateToTime(BPS, Time + Diff->Offset, 0));

        out << Beat << "=" << Value;

        if ((i + 1) != Diff->Timing.end()) // Only output comma if there's still stuff to output.
            out << "\n,";
    }

    out << ";";
}
コード例 #7
0
ファイル: TTFCache.cpp プロジェクト: zardoru/raindrop
bool TTFCache::SaveCache(std::filesystem::path cachepath)
{
	std::ofstream out(cachepath.string(), std::ios::binary);
	if (!out.is_open()) return false;

	auto size = mCharBuffer.size();
	BinWrite(out, size);

	for (const auto &it : mCharBuffer) {
		BinWrite(out, it.first);
		
		auto csize = it.second.size();
		BinWrite(out, csize);

		out.write((char*)it.second.data(), it.second.size());
	}

	return true;
}
コード例 #8
0
ファイル: Utility.cpp プロジェクト: TomoAlien/raindrop
    std::string GetSha256ForFile(std::filesystem::path Filename)
    {
        SHA256 SHA;
        std::ifstream InStream(Filename.string());
        unsigned char tmpbuf[256];

        if (!InStream.is_open())
            return "";

        while (!InStream.eof())
        {
            InStream.read((char*)tmpbuf, 256);
            size_t cnt = InStream.gcount();

            SHA.add(tmpbuf, cnt);
        }

        return std::string(SHA.getHash());
    }
コード例 #9
0
//------------------------------------------------------------
bool ofFmodSoundPlayer::load(std::filesystem::path fileName, bool stream){

	fileName = ofToDataPath(fileName);

	// fmod uses IO posix internally, might have trouble
	// with unicode paths...
	// says this code:
	// http://66.102.9.104/search?q=cache:LM47mq8hytwJ:www.cleeker.com/doxygen/audioengine__fmod_8cpp-source.html+FSOUND_Sample_Load+cpp&hl=en&ct=clnk&cd=18&client=firefox-a
	// for now we use FMODs way, but we could switch if
	// there are problems:

	bMultiPlay = false;

	// [1] init fmod, if necessary

	initializeFmod();

	// [2] try to unload any previously loaded sounds
	// & prevent user-created memory leaks
	// if they call "loadSound" repeatedly, for example

	unload();

	// [3] load sound

	//choose if we want streaming
	int fmodFlags =  FMOD_SOFTWARE;
	if(stream)fmodFlags =  FMOD_SOFTWARE | FMOD_CREATESTREAM;

    result = FMOD_System_CreateSound(sys, fileName.string().c_str(),  fmodFlags, nullptr, &sound);

	if (result != FMOD_OK){
		bLoadedOk = false;
		ofLogError("ofFmodSoundPlayer") << "loadSound(): could not load \"" << fileName << "\"";
	} else {
		bLoadedOk = true;
		FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_PCM);
		isStreaming = stream;
	}

	return bLoadedOk;
}
コード例 #10
0
ファイル: windows_process.hpp プロジェクト: Surogate/xtsslib
      std::system_error run_process(const std::filesystem::path& filename, const std::vector<std::string>& argv,
                                    const std::vector<std::string>& envp)
      {
         std::memset(&si, 0, sizeof(si));
         std::memset(&pi, 0, sizeof(pi));

         command_line = filename.string();
         for (const auto& s : argv)
         {
            command_line += " " + quote_this(s);
         }
         std::vector<char> env_block;
         env_block.reserve(env.size() * 128);
         for (const auto& keys : envp)
         {
            env_block.insert(env_block.end(), keys.begin(), keys.end());
            env_block.push_back('\0');
         }
         env_block.push_back('\0');

#ifdef _DEBUG
         std::cout << command_line << std::endl;
#endif

		 char* env_block_data = nullptr;
         if(envp.size())
            env_block_data = env_block.data();

         auto result = ::CreateProcessA(NULL, command_line.data(), NULL, NULL,
             TRUE, NULL, env_block_data, running_dir.data(), &si, &pi);
         if (result > 0)
         {
            attached = true;
         }
         else
         {
            return std::system_error(std::error_code(GetLastError(), std::system_category()));
         }
         return std::system_error(std::make_error_code(std::errc(0)));
      }
コード例 #11
0
ファイル: TTFCache.cpp プロジェクト: zardoru/raindrop
bool TTFCache::LoadCache(std::filesystem::path cachepath)
{
	std::ifstream in(cachepath.string(), std::ios::binary);
	if (!in.is_open()) return false;

	mCharBuffer.clear();
	int size;

	BinRead(in, size);
	while (!in.eof() && size > 0) {
		size_t chsize;
		int id;
		BinRead(in, id);
		BinRead(in, chsize);

		std::vector<uint8_t> buf(chsize);
		in.read((char*)buf.data(), chsize);

		mCharBuffer[id] = std::move(buf);
		size--;
	}

	return true;
}
コード例 #12
0
int ofURLFileLoaderImpl::saveAsync(const string& url, const std::filesystem::path& path){
	ofHttpRequest request(url,path.string(),true);
	requests.send(request);
	start();
	return request.getId();
}
コード例 #13
0
ofHttpResponse ofURLFileLoaderImpl::saveTo(const string& url, const std::filesystem::path& path){
	ofHttpRequest request(url,path.string(),true);
	return handleRequest(request);
}
コード例 #14
0
ファイル: ofImage.cpp プロジェクト: 2bbb/openFrameworks
static bool loadImage(ofPixels_<PixelType> & pix, const std::filesystem::path& _fileName, const ofImageLoadSettings& settings){
	ofInitFreeImage();

	auto uriStr = _fileName.string();
	UriUriA uri;
	UriParserStateA state;
	state.uri = &uri;

	if(uriParseUriA(&state, uriStr.c_str())!=URI_SUCCESS){
		const int bytesNeeded = 8 + 3 * strlen(uriStr.c_str()) + 1;
		std::vector<char> absUri(bytesNeeded);
	#ifdef TARGET_WIN32
		uriWindowsFilenameToUriStringA(uriStr.c_str(), absUri.data());
	#else
		uriUnixFilenameToUriStringA(uriStr.c_str(), absUri.data());
	#endif
		if(uriParseUriA(&state, absUri.data())!=URI_SUCCESS){
			ofLogError("ofImage") << "loadImage(): malformed uri when loading image from uri " << _fileName;
			uriFreeUriMembersA(&uri);
			return false;
		}
	}
	std::string scheme(uri.scheme.first, uri.scheme.afterLast);
	uriFreeUriMembersA(&uri);

	if(scheme == "http" || scheme == "https"){
		return ofLoadImage(pix, ofLoadURL(_fileName.string()).data);
	}

	std::string fileName = ofToDataPath(_fileName, true);
	bool bLoaded = false;
	FIBITMAP * bmp = nullptr;

	FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
	fif = FreeImage_GetFileType(fileName.c_str(), 0);
	if(fif == FIF_UNKNOWN) {
		// or guess via filename
		fif = FreeImage_GetFIFFromFilename(fileName.c_str());
	}
	if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
		if(fif == FIF_JPEG) {
			int option = getJpegOptionFromImageLoadSetting(settings);
			bmp = FreeImage_Load(fif, fileName.c_str(), option);
		} else {
			bmp = FreeImage_Load(fif, fileName.c_str(), 0);
		}

		if (bmp != nullptr){
			bLoaded = true;
		}
	}

	//-----------------------------

	if ( bLoaded ){
		putBmpIntoPixels(bmp,pix);
	}

	if (bmp != nullptr){
		FreeImage_Unload(bmp);
	}

	return bLoaded;
}