MCPcopy Create free account
hub / github.com/csound/csound / importFile

Method importFile

interfaces/CsoundFile.cpp:332–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330#endif
331
332int CsoundFile::importFile(std::string filename)
333{
334 struct stat statbuffer;
335 int returnValue = stat(filename.c_str(), &statbuffer);
336 if(returnValue)
337 {
338 return false;
339 }
340 std::ifstream stream(filename.c_str(), std::ios::binary);
341 if((filename.find(".orc") != filename.npos) ||
342 (filename.find(".ORC") != filename.npos))
343 {
344 returnValue += importOrchestra(stream);
345 }
346 else if((filename.find(".sco") != filename.npos) ||
347 (filename.find(".SCO") != filename.npos))
348 {
349 returnValue += importScore(stream);
350 }
351 else if((filename.find(".mid") != filename.npos) ||
352 (filename.find(".MID") != filename.npos))
353 {
354 returnValue += importMidifile(stream);
355 }
356#if defined(HAVE_MUSICXML2)
357 else if((filename.find(".xml") != filename.npos) ||
358 (filename.find(".XML") != filename.npos))
359 {
360 score.erase();
361 xmlreader xmlReader;
362 Sxmlelement sxmlElement;
363 // Try to read an SXMLFile out of the MusicXML file.
364 SXMLFile sxmlFile = xmlReader.read(filename.c_str());
365 if (sxmlFile) {
366 // Get the document tree of XML elements from the SXMLFile.
367 sxmlElement = sxmlFile->elements();
368 }
369 if (sxmlElement) {
370 // Create a CsoundFileMidiWriter that is attached to this Score.
371 CsoundFileMidiWriter csoundFileMidiWriter(this);
372 // Create a midicontextvisitor, which calls into an abstract
373 // midiwriter interface, which is attached to our
374 // CsoundFileMidiWriter, which implements that midiwriter
375 // interface.
376 midicontextvisitor midicontextvisitor_(csoundFileMidiWriter.tpq,
377 &csoundFileMidiWriter);
378 // Create an xml_tree_browser that is attached to our midicontextvisitor.
379 xml_tree_browser xmlTreeBrowser(&midicontextvisitor_);
380 // The xml_tree_browser will carry the midicontextvisitor to
381 // all the elements of the document tree, in the proper order,
382 // calling newNote as appropriate.
383 xmlTreeBrowser.browse(*sxmlElement);
384 }
385 }
386#endif
387 else
388 {
389 returnValue += importFile(stream);

Callers

nothing calls this directly

Calls 2

getlineFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected