Skip to content

Commit

Permalink
Fix resource loading compatibility for Python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
MustafaAlotbah committed Sep 10, 2024
1 parent 4cf4ceb commit 7a819da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 5 additions & 6 deletions py_guitar_synth/instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@
Mustafa Alotbah
Email: mustafa.alotbah@gmail.com
"""
import importlib.resources as pkg_resources
import importlib.resources as resources
from py_guitar_synth.instrument_parser import load_instrument_from_json, load_impulse_response

# Load the JSON file with the guitar's physical properties
with pkg_resources.path('py_guitar_synth.assets', 'classical_guitar.json') as f:
with resources.as_file(resources.files('py_guitar_synth.assets').joinpath('classical_guitar.json')) as f:
default_classical_guitar = load_instrument_from_json(str(f))

# Load the JSON file with the violine's physical properties
with pkg_resources.path('py_guitar_synth.assets', 'violine.json') as f:
with resources.as_file(resources.files('py_guitar_synth.assets').joinpath('violine.json')) as f:
default_violine = load_instrument_from_json(str(f))

# Load the JSON file with the piano's physical properties
with pkg_resources.path('py_guitar_synth.assets', 'piano.json') as f:
with resources.as_file(resources.files('py_guitar_synth.assets').joinpath('piano.json')) as f:
default_piano = load_instrument_from_json(str(f))

# Load a WAV file (impulse response)
with pkg_resources.path('py_guitar_synth.assets', 'ir.wav') as wav_path:
# Use the path in your audio processing code
with resources.as_file(resources.files('py_guitar_synth.assets').joinpath('ir.wav')) as wav_path:
default_impulse_response = load_impulse_response(str(wav_path))
8 changes: 5 additions & 3 deletions py_guitar_synth/sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
Mustafa Alotbah
Email: mustafa.alotbah@gmail.com
"""
import importlib.resources as pkg_resources
import importlib.resources as resources
from py_guitar_synth.tab_parser import parse_guitar_tab_from_file

with pkg_resources.path('py_guitar_synth.assets', 'law_bass.txt') as f:
# Load the 'law_bass.txt' tab file
with resources.as_file(resources.files('py_guitar_synth.assets').joinpath('law_bass.txt')) as f:
law_bass_f_aini = parse_guitar_tab_from_file(str(f))

with pkg_resources.path('py_guitar_synth.assets', 'agua_marina.txt') as f:
# Load the 'agua_marina.txt' tab file
with resources.as_file(resources.files('py_guitar_synth.assets').joinpath('agua_marina.txt')) as f:
agua_marina = parse_guitar_tab_from_file(str(f))

0 comments on commit 7a819da

Please sign in to comment.