-
Notifications
You must be signed in to change notification settings - Fork 3
/
load_audio.py
39 lines (30 loc) · 1.27 KB
/
load_audio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import bpy
from bpy.props import StringProperty
from bpy_extras.io_utils import ImportHelper
import os
class LoadAudio(bpy.types.Operator, ImportHelper):
bl_idname = "sound_nodes.load_audio"
bl_label = "Load Audio"
bl_description = "Choose file from disk"
bl_options = {'REGISTER', 'UNDO'}
filter_glob: StringProperty(
default='*.wav;*.mp3;*.ogg;*.flac',
options={'HIDDEN'}
)
def execute(self, context):
filename = str(os.path.basename(self.filepath))
# save to scene properties
context.scene.sound_nodes.audio_source = self.filepath
# add audio to scene
if not context.scene.sequence_editor:
context.scene.sequence_editor_create()
# delete all sequences that end with "- sound nodes"
for seq in context.scene.sequence_editor.sequences:
if seq.name.endswith("- sound nodes"):
context.scene.sequence_editor.sequences.remove(seq)
# add audio to scene
new_name = filename[:40] + " - sound nodes"
context.scene.sequence_editor.sequences.new_sound(name=new_name, filepath=self.filepath, frame_start=1, channel=4)
# set audio sync mode
context.scene.sync_mode = 'AUDIO_SYNC'
return {'FINISHED'}