| 643 | } |
| 644 | |
| 645 | void |
| 646 | ReadNodePrivate::createReadNode(bool throwErrors, |
| 647 | const std::string& filename, |
| 648 | const NodeSerializationPtr& serialization) |
| 649 | { |
| 650 | if (creatingReadNode) { |
| 651 | return; |
| 652 | } |
| 653 | |
| 654 | SetCreatingReaderRAIIFlag creatingNode__(this); |
| 655 | QString qpattern = QString::fromUtf8( filename.c_str() ); |
| 656 | std::string ext = QtCompat::removeFileExtension(qpattern).toLower().toStdString(); |
| 657 | std::string readerPluginID; |
| 658 | KnobStringPtr pluginIDKnob = pluginIDStringKnob.lock(); |
| 659 | readerPluginID = pluginIDKnob->getValue(); |
| 660 | |
| 661 | |
| 662 | if ( readerPluginID.empty() ) { |
| 663 | KnobChoicePtr pluginChoiceKnob = pluginSelectorKnob.lock(); |
| 664 | int pluginChoice_i = pluginChoiceKnob->getValue(); |
| 665 | if (pluginChoice_i == 0) { |
| 666 | //Use default |
| 667 | readerPluginID = appPTR->getReaderPluginIDForFileType(ext); |
| 668 | } else { |
| 669 | std::vector<ChoiceOption> entries = pluginChoiceKnob->getEntries_mt_safe(); |
| 670 | if ( (pluginChoice_i >= 0) && ( pluginChoice_i < (int)entries.size() ) ) { |
| 671 | readerPluginID = entries[pluginChoice_i].id; |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | // If the plug-in is the same, do not create a new decoder. |
| 677 | if (embeddedPlugin && embeddedPlugin->getPluginID() == readerPluginID) { |
| 678 | KnobFilePtr fileKnob = inputFileKnob.lock(); |
| 679 | assert(fileKnob); |
| 680 | if (fileKnob) { |
| 681 | // Make sure instance changed action is called on the decoder and not caught in our knobChanged handler. |
| 682 | embeddedPlugin->getEffectInstance()->onKnobValueChanged_public(fileKnob.get(), eValueChangedReasonNatronInternalEdited, _publicInterface->getCurrentTime(), ViewSpec(0), true); |
| 683 | |
| 684 | } |
| 685 | |
| 686 | return; |
| 687 | } |
| 688 | //Destroy any previous reader |
| 689 | //This will store the serialization of the generic knobs |
| 690 | destroyReadNode(); |
| 691 | |
| 692 | bool defaultFallback = false; |
| 693 | |
| 694 | if (readerPluginID.empty()) { |
| 695 | if (throwErrors) { |
| 696 | QString message = tr("Could not find a decoder to read %1 file format") |
| 697 | .arg( QString::fromUtf8( ext.c_str() ) ); |
| 698 | throw std::runtime_error( message.toStdString() ); |
| 699 | } |
| 700 | defaultFallback = true; |
| 701 | |
| 702 | } |
no test coverage detected