How to use the scamp.utilities.resolve_relative_path function in scamp

To help you get started, we’ve selected a few scamp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MarcTheSpark / scamp / scamp / _soundfont_host.py View on Github external
soundfont_path = playback_settings.named_soundfonts[soundfont] \
        if soundfont in playback_settings.named_soundfonts else soundfont

    if soundfont_path.startswith("/"):
        # Absolute soundfont path
        return soundfont_path
    elif soundfont_path.startswith("~/"):
        # Relative to user home directory
        return os.path.expanduser(soundfont_path)
    else:
        # Relative to one of the search paths defined in the settings
        for search_path in playback_settings.soundfont_search_paths:
            if search_path.startswith("~/"):
                search_path = os.path.expanduser(search_path)
            if not search_path.startswith("/"):
                search_path = resolve_relative_path(search_path)

            if os.path.exists(os.path.join(search_path, soundfont_path)):
                # look in this search path
                return os.path.join(search_path, soundfont_path)
            elif os.path.exists(os.path.join(search_path, soundfont_path + ".sf2")):
                # try adding an sf2
                return os.path.join(search_path, soundfont_path + ".sf2")
        # give up and just return the path as is
        return soundfont_path
github MarcTheSpark / scamp / misc / old / old_settings.py View on Github external
def make_persistent(self):
        self.save_to_json(resolve_relative_path("settings/playbackSettings.json"))
github MarcTheSpark / scamp / misc / old / old_settings.py View on Github external
try:
    playback_settings = PlaybackSettings.load_from_json(resolve_relative_path("settings/playbackSettings.json"))
except FileNotFoundError:
    logging.warning("Playback settings not found; generating defaults.")
    playback_settings = PlaybackSettings()
    playback_settings.make_persistent()
except (TypeError, json.decoder.JSONDecodeError):
    logging.warning("Error loading playback settings; falling back to defaults.")
    playback_settings = PlaybackSettings()


try:
    quantization_settings = \
        QuantizationSettings.load_from_json(resolve_relative_path("settings/quantizationSettings.json"))
except FileNotFoundError:
    logging.warning("Quantization settings not found; generating defaults.")
    quantization_settings = QuantizationSettings()
    quantization_settings.make_persistent()
except (TypeError, json.decoder.JSONDecodeError):
    logging.warning("Error loading quantization settings; falling back to defaults.")
    quantization_settings = QuantizationSettings()


try:
    engraving_settings = EngravingSettings.load_from_json(resolve_relative_path("settings/engravingSettings.json"))
except FileNotFoundError:
    logging.warning("Engraving settings not found; generating defaults.")
    engraving_settings = EngravingSettings()
    engraving_settings.make_persistent()
except (TypeError, json.decoder.JSONDecodeError):
github MarcTheSpark / scamp / scamp / settings.py View on Github external
def load(cls):
        """
        Loads and instance of this settings object from its corresponding JSON file. If no such file exists, or it is
        corrupted in some way, then this creates a fresh JSON file there. This doesn't work with settings that are
        nested within other settings (like GlissandiSettings), since they do not have corresponding JSON files,
        """
        assert cls._is_root_setting, "Cannot load a non-root setting automatically."
        try:
            return cls.load_from_json(resolve_relative_path(cls._json_path))
        except FileNotFoundError:
            logging.warning("{} not found; generating defaults.".format(cls._settings_name))
            factory_defaults = cls.factory_default()
            factory_defaults.make_persistent()
            return factory_defaults
        except (TypeError, json.decoder.JSONDecodeError):
            logging.warning("Error loading {}; falling back to defaults.".format(cls._settings_name.lower()))
            return cls.factory_default()
github MarcTheSpark / scamp / misc / old / old_settings.py View on Github external
def make_persistent(self):
        self.save_to_json(resolve_relative_path("settings/engravingSettings.json"))