def execute(self): input = connected_node_sound(self, 0) if isinstance(input, dict): if "sound" in input.keys(): sound = input["sound"] else: sound = None else: return None if not isinstance(sound, aud.Sound): return None obj = bpy.data.objects[self.control_name] if obj is not None: if self.anim_type == "loc": value_obj = obj.location[int(self.control_axis)] elif self.anim_type == "rot": value_obj = obj.rotation_euler[int(self.control_axis)] else: value_obj = obj.scale[int(self.control_axis)] if self.operand == "con": # Play as value has approached trigger if value_obj == self.trigger_value and self.last_value != self.trigger_value: if sound != None: aud.Device().play(sound) else: # Play as value has deviated from trigger if self.trigger_value == self.last_value and value_obj != self.trigger_value: if sound != None: aud.Device().play(sound) self.last_value = value_obj
def start(self, args): """Start Function""" scene = bge.logic.getCurrentScene() cam = scene.active_camera # Loading the device... self.device = aud.Device() self.device.distance_model = aud.DISTANCE_MODEL_LINEAR # Loading the sound... sName = bge.logic.expandPath("//")+args["Sound File"] self.sound = aud.Sound(sName) # Playing the sound... self.handle = self.device.play(self.sound) # 3D Sound configuration... self.__3dSound = args["3D Sound"] self.handle.relative = (self.__3dSound == False) self.handle.distance_maximum = abs(args["Max Distance"]) self.handle.distance_reference = abs(args["Min Distance"]) self.handle.pitch = args["Pitch"] self.handle.volume = args["Volume"] if args["Loop Sound"]: self.handle.loop_count = -1 else: self.handle.loop_count = 0 self.__deleteObj = args["Delete Object After End"]
def execute(self, context): dev = aud.Device() dev.stopAll() print(path) return {'FINISHED'}
def play_tune(scene): handle = bpy.types.RenderSettings.music_handle addon_prefs = bpy.context.preferences.addons[__package__].preferences if addon_prefs.tuneEnabler: device = aud.Device() tunePlay = aud.Sound.file(addon_prefs.tuneLocation) bpy.types.RenderSettings.music_handle = device.play(tunePlay)
def play_sound(*args): import pathlib import aud ping_path = pathlib.Path(__file__).with_name('ping.ogg') aud_dev = aud.Device() aud_sound = aud.Sound(str(ping_path)) aud_dev.play(aud_sound)
def execute(self, context): try: st_t = time.time() return_data = GlobalData.importer.ImportCreation( vanilla_skins=context.scene.bsgimp_use_vanilla_blocks, create_parent=context.scene.bsgimp_create_parent, join_line_components=context.scene. bsgimp_line_type_join_components, generate_material=context.scene.bsgimp_generate_materials, bracethreshold=context.scene. bsgimp_line_type_brace_delete_threshold, line_type_cleanup=context.scene. bsgimp_line_type_cleanup_options, node_grouping_mode=context.scene. bsgimp_make_unique_node_groups, use_node_groups=context.scene.bsgimp_use_node_group, node_group_setup=context.scene.bsgimp_node_set, merge_decor_blocks=context.scene.bsgimp_merge_decor_components, surface_block_resolution=context.scene. bsgimp_surface_type_resolution, surface_block_thickness_mult=context.scene. bsgimp_surface_type_thickness_multiplier, skip_surfaces=context.scene.bsgimp_surface_type_skip_surfaces) et_t = time.time() if (et_t - st_t) > 5 and context.scene.bsgimp_notify_on_complete: device = aud.Device() path_to_sound = os.path.join( os.path.dirname( os.path.realpath(__file__)), 'import-complete.mp3' ) if not dev_mode else 'import-complete.mp3' sound = aud.Sound(path_to_sound) device.play(sound) for material in return_data['imported_materials']: newmat = bpy.context.scene.bsgimp_purgeable_materials.add() newmat.obj_pointer = material for object_imp in return_data['imported_objects']: try: newobj = bpy.context.scene.bsgimp_selectable_imports.add() # newobj.name = object_imp.name newobj.obj_pointer = object_imp # print(object_imp) # object_imp.select_set(True) except: pass self.report({'INFO'}, 'Import complete in {:.2f} seconds'.format( (et_t - st_t))) except: self.report( {'ERROR'}, 'Error encountered in the import process. Check console') traceback.print_exc() return ({'FINISHED'})
def play_tune(scene): handle = bpy.types.RenderSettings.music_handle addon_prefs = bpy.context.preferences.addons[__package__].preferences #TODO Create a logic for the 3 states # when render completes # when render is interrupted by error or cancelled if addon_prefs.tuneEnabler: device = aud.Device() device.volume=addon_prefs.tuneVol tunePlay = aud.Sound.file(addon_prefs.tuneLocation) interruptPlay = aud.Sound.file(addon_prefs.interruptLocation) # handle = device.play(interruptPlay) Interruption(cancel or error) tune play handle = device.play(tunePlay)
def execute(self, context): cm_node = context.node cm = context.scene.cm_pg start_frm = cm_node.start_frm stop_frm = cm_node.stop_frm frame_time = bpy.context.scene.render.fps / bpy.context.scene.render.fps_base first = True sound_out = None if start_frm >= stop_frm: return {"FINISHED"} for i in range(start_frm, stop_frm + 1): context.scene.frame_current = i delay = (context.scene.frame_current - start_frm) / frame_time sound = cm_node.get_sound() if sound is not None: sound = sound.delay(delay) if first: sound_out = sound first = False else: sound_out = sound_out.mix(sound) if sound_out is not None: path = bpy.path.abspath(cm_node.file_name) my_file = Path(path) if my_file.is_file(): if cm_node.overwrite: os.remove(path) else: self.report({"ERROR"}, "File Exists - Overwrite not Checked") return {"FINISHED"} snd_out = sound_out.write(path, aud.RATE_16000, aud.CHANNELS_STEREO, aud.FORMAT_FLOAT32, aud.CONTAINER_FLAC, aud.CODEC_FLAC) if not context.scene.sequence_editor: context.scene.sequence_editor_create() soundstrip = context.scene.sequence_editor.sequences.new_sound( f"{cm_node.sequence_name}: {start_frm}-{stop_frm}", path, cm_node.sequence_channel, start_frm, ) soundstrip.show_waveform = True aud.Device().play(sound_out) context.scene.frame_current = start_frm return {"FINISHED"}
def register(): try: if 'rp_playlist' in bpy.context.scene: bpy.context.scene.rp_playlist.clear() except: pass bpy.utils.register_class(RP_Playlist) bpy.types.Scene.rp_playlist = bpy.props.CollectionProperty( type=RP_Playlist) bpy.types.WindowManager.radiola_clear = bpy.props.BoolProperty( default=False) bpy.types.WindowManager.radiola = bpy.props.IntProperty() bpy.types.WindowManager.radiola_ind = bpy.props.IntProperty() bpy.types.WindowManager.radiola_dev = aud.Device() bpy.utils.register_class(OP_radiola) bpy.utils.register_class(OP_radiola_panel)
def play_chaching_sound(self): # TODO: make pitch higher as costs rise try: import aud device = aud.Device() # chaching.mp3 is by Lucish_ CC-BY-3.0 https://freesound.org/people/Lucish_/sounds/554841/ sound = aud.Sound( os.path.join(context.scene.BIMProperties.data_dir, "chaching.mp3")) handle = device.play(sound) sound_buffered = aud.Sound.buffer(sound) handle_buffered = device.play(sound_buffered) handle.stop() handle_buffered.stop() except: pass # ah well
def register(): for c in classes: bpy.utils.register_class(c) bpy.types.WindowManager.mp_index = bpy.props.IntProperty() bpy.types.WindowManager.mp_cycled = bpy.props.BoolProperty( \ description='start first if last is played',default=False) bpy.types.WindowManager.mp_pause = bpy.props.BoolProperty(False) bpy.types.WindowManager.mp_playing = bpy.props.BoolProperty(False) bpy.types.Scene.mp_volume = bpy.props.FloatProperty(name="Volume", default=1.0, min=0.0, max=1.0, update=volume_up) bpy.types.WindowManager.mp_d = aud.Device() bpy.types.WindowManager.mp_MusHandle = bpy.props.FloatProperty( name="MusHandle", default=0.0, min=0.0, max=600) bpy.types.Scene.mp_playlist = bpy.props.CollectionProperty( type=MP_Playlist) bpy.types.Scene.mp_playlist_names = bpy.props.CollectionProperty( type=MP_Playlist)
def execute(self): input = connected_node_sound(self, 0) if isinstance(input, dict): if "sound" in input.keys(): sound = input["sound"] else: sound = None else: return None play_sound = connected_node_output(self, 1) if isinstance(play_sound, dict): if "bool" in play_sound.keys(): play_sound = play_sound["bool"] else: sockets = self.inputs.keys() play_sound = get_socket_values(self, sockets, self.inputs)[1] if isinstance(sound, aud.Sound) and play_sound: aud.Device().play(sound)
def execute(self, context): addon_data = context.scene.freesound_data if (not addon_data.freesound_list_loaded): return {'FINISHED'} addon_data.sound_is_playing = True client = Freesound_Validate.get_client(Freesound_Validate) try: sound_id = FREESOUND_UL_List.get_sound_id(FREESOUND_UL_List) sound_info = client.get_sound(sound_id) if (addon_data.high_quality): preview_file = str( sound_info.previews.preview_hq_mp3.split("/")[-1]) else: preview_file = str( sound_info.previews.preview_lq_mp3.split("/")[-1]) if (preview_file): if (isfile(dirname(realpath(__file__)) + '/' + preview_file)): soundfile = dirname( realpath(__file__)) + '/' + preview_file else: soundfile = sound_info.retrieve_preview( dirname(realpath(__file__)), sound_info.name, addon_data.high_quality) addon_data.soundfile = soundfile device = aud.Device() sound = aud.Sound.file(soundfile) Freesound_Play.handle = device.play(sound) Freesound_Play.handle.loop_count = -1 except: print("[Play] Search something first...") return {'CANCELLED'} return {'FINISHED'}
def init(cont): own = cont.owner #toggle menghilang own.visible = True var.w = wave.open(soundFile) w = var.w var.frameRate = w.getframerate() var.totalFrames = w.getnframes() var.totalTime = w.getnframes() / w.getframerate() own['totalTime'] = var.totalTime var.startYPos = own.worldPosition.y cont.activate(cont.actuators['s1']) device = aud.Device() factory = aud.Sound(soundFile) handle = device.play(factory) var.isStart = True var.handle = handle
import aud, sys, time device = aud.Device() dMusic = aud.DynamicMusic(device) sound1 = aud.Sound.file(sys.argv[1]) sound2 = aud.Sound.file(sys.argv[2]) effect = aud.Sound.file(sys.argv[3]) dMusic.addScene(sound1) dMusic.addScene(sound2) dMusic.addTransition(1, 2, effect) dMusic.fadeTime = 3 dMusic.volume = 0.5 dMusic.scene = 1 time.sleep(5) dMusic.scene = 2 time.sleep(500)
def manage_build(background_pass=False): print("Managing build") scene = bpy.context.scene sceneProperties = scene.TLM_SceneProperties if sceneProperties.tlm_lightmap_engine == "Cycles": if background_pass: nodes.apply_lightmaps() nodes.apply_materials() #From here the name is changed... end = "_baked" if sceneProperties.tlm_denoise_use: end = "_denoised" if sceneProperties.tlm_filtering_use: end = "_filtered" formatEnc = ".hdr" if sceneProperties.tlm_encoding_use and scene.TLM_EngineProperties.tlm_bake_mode != "Background": if sceneProperties.tlm_encoding_device == "CPU": print("CPU Encoding") if sceneProperties.tlm_encoding_mode_a == "HDR": if sceneProperties.tlm_format == "EXR": formatEnc = ".exr" if sceneProperties.tlm_encoding_mode_a == "RGBM": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_a == "RGBD": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_a == "SDR": formatEnc = ".png" else: print("GPU Encoding") if sceneProperties.tlm_encoding_mode_b == "HDR": if sceneProperties.tlm_format == "EXR": formatEnc = ".exr" if sceneProperties.tlm_encoding_mode_b == "LogLuv": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_b == "RGBM": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_b == "RGBD": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_b == "SDR": formatEnc = ".png" if not background_pass: nodes.exchangeLightmapsToPostfix("_baked", end, formatEnc) if scene.TLM_EngineProperties.tlm_setting_supersample == "2x": supersampling_scale = 2 elif scene.TLM_EngineProperties.tlm_setting_supersample == "4x": supersampling_scale = 4 else: supersampling_scale = 1 pack.postpack() for image in bpy.data.images: if image.users < 1: bpy.data.images.remove(image) if scene.TLM_SceneProperties.tlm_headless: filepath = bpy.data.filepath dirpath = os.path.join( os.path.dirname(bpy.data.filepath), scene.TLM_EngineProperties.tlm_lightmap_savedir) for obj in bpy.context.scene.objects: if obj.type == 'MESH' and obj.name in bpy.context.view_layer.objects: if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: cache.backup_material_restore(obj) for obj in bpy.context.scene.objects: if obj.type == 'MESH' and obj.name in bpy.context.view_layer.objects: if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: cache.backup_material_rename(obj) for mat in bpy.data.materials: if mat.users < 1: bpy.data.materials.remove(mat) for mat in bpy.data.materials: if mat.name.startswith("."): if "_Original" in mat.name: bpy.data.materials.remove(mat) for obj in bpy.context.scene.objects: if obj.type == 'MESH' and obj.name in bpy.context.view_layer.objects: if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: if obj.TLM_ObjectProperties.tlm_mesh_lightmap_unwrap_mode == "AtlasGroupA": atlasName = obj.TLM_ObjectProperties.tlm_atlas_pointer img_name = atlasName + '_baked' Lightmapimage = bpy.data.images[img_name] obj["Lightmap"] = Lightmapimage.filepath_raw elif obj.TLM_ObjectProperties.tlm_postpack_object: atlasName = obj.TLM_ObjectProperties.tlm_postatlas_pointer img_name = atlasName + '_baked' + ".hdr" Lightmapimage = bpy.data.images[img_name] obj["Lightmap"] = Lightmapimage.filepath_raw else: img_name = obj.name + '_baked' Lightmapimage = bpy.data.images[img_name] obj["Lightmap"] = Lightmapimage.filepath_raw for image in bpy.data.images: if image.name.endswith("_baked"): bpy.data.images.remove(image, do_unlink=True) if "tlm_plus_mode" in bpy.app.driver_namespace: #First DIR pass if bpy.app.driver_namespace["tlm_plus_mode"] == 1: #First DIR pass filepath = bpy.data.filepath dirpath = os.path.join( os.path.dirname(bpy.data.filepath), scene.TLM_EngineProperties.tlm_lightmap_savedir) for obj in bpy.context.scene.objects: if obj.type == 'MESH' and obj.name in bpy.context.view_layer.objects: if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: cache.backup_material_restore(obj) for obj in bpy.context.scene.objects: if obj.type == 'MESH' and obj.name in bpy.context.view_layer.objects: if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: cache.backup_material_rename(obj) for mat in bpy.data.materials: if mat.users < 1: bpy.data.materials.remove(mat) for mat in bpy.data.materials: if mat.name.startswith("."): if "_Original" in mat.name: bpy.data.materials.remove(mat) for image in bpy.data.images: if image.name.endswith("_baked"): bpy.data.images.remove(image, do_unlink=True) dirpath = os.path.join( os.path.dirname(bpy.data.filepath), bpy.context.scene. TLM_EngineProperties.tlm_lightmap_savedir) files = os.listdir(dirpath) for index, file in enumerate(files): filename = extension = os.path.splitext(file)[0] extension = os.path.splitext(file)[1] os.rename( os.path.join(dirpath, file), os.path.join(dirpath, filename + "_dir" + extension)) print("First DIR pass complete") bpy.app.driver_namespace["tlm_plus_mode"] = 2 prepare_build(self=0, background_mode=False, shutdown_after_build=False) if not background_pass and bpy.context.scene.TLM_EngineProperties.tlm_lighting_mode != "combinedao": #pass setGui(0) elif bpy.app.driver_namespace["tlm_plus_mode"] == 2: filepath = bpy.data.filepath dirpath = os.path.join( os.path.dirname(bpy.data.filepath), bpy.context.scene. TLM_EngineProperties.tlm_lightmap_savedir) files = os.listdir(dirpath) for index, file in enumerate(files): filename = os.path.splitext(file)[0] extension = os.path.splitext(file)[1] if not filename.endswith("_dir"): os.rename( os.path.join(dirpath, file), os.path.join(dirpath, filename + "_ao" + extension)) print("Second AO pass complete") total_time = sec_to_hours((time() - start_time)) if bpy.context.scene.TLM_SceneProperties.tlm_verbose: print(total_time) bpy.context.scene["TLM_Buildstat"] = total_time reset_settings(previous_settings["settings"]) bpy.app.driver_namespace["tlm_plus_mode"] = 0 if not background_pass: #TODO CHANGE! nodes.exchangeLightmapsToPostfix(end, end + "_dir", formatEnc) nodes.applyAOPass() else: total_time = sec_to_hours((time() - start_time)) if bpy.context.scene.TLM_SceneProperties.tlm_verbose: print(total_time) bpy.context.scene["TLM_Buildstat"] = total_time reset_settings(previous_settings["settings"]) print("Lightmap building finished") if sceneProperties.tlm_lightmap_engine == "LuxCoreRender": pass if sceneProperties.tlm_lightmap_engine == "OctaneRender": pass if bpy.context.scene.TLM_EngineProperties.tlm_bake_mode == "Background": pass if not background_pass and bpy.context.scene.TLM_EngineProperties.tlm_lighting_mode != "combinedao": #pass setGui(0) if scene.TLM_SceneProperties.tlm_alert_on_finish: alertSelect = scene.TLM_SceneProperties.tlm_alert_sound if alertSelect == "dash": soundfile = "dash.ogg" elif alertSelect == "pingping": soundfile = "pingping.ogg" elif alertSelect == "gentle": soundfile = "gentle.ogg" else: soundfile = "noot.ogg" scriptDir = os.path.dirname(os.path.realpath(__file__)) sound_path = os.path.abspath( os.path.join(scriptDir, '..', 'assets/' + soundfile)) device = aud.Device() sound = aud.Sound.file(sound_path) device.play(sound) if bpy.app.background: if bpy.context.scene.TLM_SceneProperties.tlm_verbose: print("Writing background process report") write_directory = os.path.join( os.path.dirname(bpy.data.filepath), bpy.context.scene.TLM_EngineProperties.tlm_lightmap_savedir) if os.path.exists(os.path.join(write_directory, "process.tlm")): process_status = json.loads( open(os.path.join(write_directory, "process.tlm")).read()) process_status[1]["completed"] = True with open(os.path.join(write_directory, "process.tlm"), 'w') as file: json.dump(process_status, file, indent=2) if postprocess_shutdown: sys.exit()
def play_sound(scene): ping_path = pathlib.Path(__file__).with_name('ping.ogg') aud_dev = aud.Device() aud_sound = aud.Sound(str(ping_path)) aud_dev.play(aud_sound)
def manage_build(background_pass=False): print("Managing build") scene = bpy.context.scene sceneProperties = scene.TLM_SceneProperties if sceneProperties.tlm_lightmap_engine == "Cycles": if background_pass: nodes.apply_lightmaps() nodes.apply_materials() #From here the name is changed... end = "_baked" if sceneProperties.tlm_denoise_use: end = "_denoised" if sceneProperties.tlm_filtering_use: end = "_filtered" formatEnc = ".hdr" if sceneProperties.tlm_encoding_use and scene.TLM_EngineProperties.tlm_bake_mode != "Background": if sceneProperties.tlm_encoding_device == "CPU": print("CPU Encoding") if sceneProperties.tlm_encoding_mode_a == "HDR": if sceneProperties.tlm_format == "EXR": formatEnc = ".exr" if sceneProperties.tlm_encoding_mode_a == "RGBM": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_a == "RGBD": formatEnc = "_encoded.png" else: print("GPU Encoding") if sceneProperties.tlm_encoding_mode_b == "HDR": if sceneProperties.tlm_format == "EXR": formatEnc = ".exr" if sceneProperties.tlm_encoding_mode_b == "LogLuv": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_b == "RGBM": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_b == "RGBD": formatEnc = "_encoded.png" if not background_pass: nodes.exchangeLightmapsToPostfix("_baked", end, formatEnc) if scene.TLM_EngineProperties.tlm_setting_supersample == "2x": supersampling_scale = 2 elif scene.TLM_EngineProperties.tlm_setting_supersample == "4x": supersampling_scale = 4 else: supersampling_scale = 1 pack.postpack() for image in bpy.data.images: if image.users < 1: bpy.data.images.remove(image) if scene.TLM_SceneProperties.tlm_headless: filepath = bpy.data.filepath dirpath = os.path.join( os.path.dirname(bpy.data.filepath), scene.TLM_EngineProperties.tlm_lightmap_savedir) for obj in bpy.data.objects: if obj.type == "MESH": if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: cache.backup_material_restore(obj) for obj in bpy.data.objects: if obj.type == "MESH": if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: cache.backup_material_rename(obj) for mat in bpy.data.materials: if mat.users < 1: bpy.data.materials.remove(mat) for mat in bpy.data.materials: if mat.name.startswith("."): if "_Original" in mat.name: bpy.data.materials.remove(mat) for obj in bpy.data.objects: if obj.type == "MESH": if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: img_name = obj.name + '_baked' Lightmapimage = bpy.data.images[img_name] obj["Lightmap"] = Lightmapimage.filepath_raw for image in bpy.data.images: if image.name.endswith("_baked"): bpy.data.images.remove(image, do_unlink=True) total_time = sec_to_hours((time() - start_time)) if bpy.context.scene.TLM_SceneProperties.tlm_verbose: print(total_time) bpy.context.scene["TLM_Buildstat"] = total_time reset_settings(previous_settings["settings"]) if sceneProperties.tlm_lightmap_engine == "LuxCoreRender": pass if sceneProperties.tlm_lightmap_engine == "OctaneRender": pass if bpy.context.scene.TLM_EngineProperties.tlm_bake_mode == "Background": pass if scene.TLM_SceneProperties.tlm_alert_on_finish: alertSelect = scene.TLM_SceneProperties.tlm_alert_sound if alertSelect == "dash": soundfile = "dash.ogg" elif alertSelect == "pingping": soundfile = "pingping.ogg" elif alertSelect == "gentle": soundfile = "gentle.ogg" else: soundfile = "noot.ogg" scriptDir = os.path.dirname(os.path.realpath(__file__)) sound_path = os.path.abspath( os.path.join(scriptDir, '..', 'assets/' + soundfile)) device = aud.Device() sound = aud.Sound.file(sound_path) device.play(sound) print("Lightmap building finished") if bpy.app.background: if bpy.context.scene.TLM_SceneProperties.tlm_verbose: print("Writing background process report") write_directory = os.path.join( os.path.dirname(bpy.data.filepath), bpy.context.scene.TLM_EngineProperties.tlm_lightmap_savedir) if os.path.exists(os.path.join(write_directory, "process.tlm")): process_status = json.loads( open(os.path.join(write_directory, "process.tlm")).read()) process_status[1]["completed"] = True with open(os.path.join(write_directory, "process.tlm"), 'w') as file: json.dump(process_status, file, indent=2) if postprocess_shutdown: sys.exit()
def execute(self, context): aud.Device().stopAll() return {"FINISHED"}
return sequence.limit(0, position) def tetris(bpm=300, freq=220, rate=44100): notes = "e2Hcd2cH A2Ace2dc H3cd2e2 c2A2A4 pd2fa2gf e3ce2dc H2Hcd2e2 c2A2A2p2" s11 = parseNotes(notes, bpm, freq, rate) notes = "e4c4 d4H4 c4A4 G#4p4 e4c4 d4H4 A2c2a4 g#4p4" s12 = parseNotes(notes, bpm, freq, rate) notes = "EeEeEeEe AaAaAaAa AbabAbabAbabAbab AaAaAAHC DdDdDdDd CcCcCcCc HhHhHhHh AaAaA2p2" s21 = parseNotes(notes, bpm, freq, rate, notechars="AXHCXDXEFXGXaXhcXdXefXgXp") notes = "aeaeaeae g#dg#dg#dg#d aeaeaeae g#dg#dg#2p2 aeaeaeae g#dg#dg#dg#d aeaeaeae g#dg#dg#2p2" s22 = parseNotes(notes, bpm, freq / 2, rate) return s11.join(s12).join(s11).volume(0.5).mix( s21.join(s22).join(s21).volume(0.3)) if __name__ == "__main__": dev = aud.Device() handle = dev.play(tetris(300, 220, dev.rate)) while handle.status: time.sleep(0.1)
def manage_build(background_pass=False, load_atlas=0): print("Managing build") if load_atlas: print("Managing in load atlas mode") scene = bpy.context.scene sceneProperties = scene.TLM_SceneProperties if sceneProperties.tlm_lightmap_engine == "Cycles": if background_pass: print("In background pass") try: nodes.apply_lightmaps() except Exception as e: print("An error occured during lightmap application. See the line below for more detail:") print(f"{type(e).__name__} at line {e.__traceback__.tb_lineno} of {__file__}: {e}") tlm_log.append("An error occured during lightmap application. See the line below for more detail:") tlm_log.append(f"{type(e).__name__} at line {e.__traceback__.tb_lineno} of {__file__}: {e}") if not bpy.context.scene.TLM_SceneProperties.tlm_verbose: print("Turn on verbose mode to get more detail.") try: nodes.apply_materials(load_atlas) #From here the name is changed... except Exception as e: print("An error occured during material application. See the line below for more detail:") print(f"{type(e).__name__} at line {e.__traceback__.tb_lineno} of {__file__}: {e}") tlm_log.append("An error occured during material application. See the line below for more detail:") tlm_log.append(f"{type(e).__name__} at line {e.__traceback__.tb_lineno} of {__file__}: {e}") if not bpy.context.scene.TLM_SceneProperties.tlm_verbose: print("Turn on verbose mode to get more detail.") end = "_baked" if sceneProperties.tlm_denoise_use: end = "_denoised" if sceneProperties.tlm_filtering_use: end = "_filtered" formatEnc = ".hdr" if sceneProperties.tlm_encoding_use and scene.TLM_EngineProperties.tlm_bake_mode != "Background": if sceneProperties.tlm_encoding_device == "CPU": print("CPU Encoding") if sceneProperties.tlm_encoding_mode_a == "HDR": if sceneProperties.tlm_format == "EXR": formatEnc = ".exr" if sceneProperties.tlm_encoding_mode_a == "RGBM": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_a == "RGBD": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_a == "SDR": formatEnc = ".png" else: print("GPU Encoding") if sceneProperties.tlm_encoding_mode_b == "HDR": if sceneProperties.tlm_format == "EXR": formatEnc = ".exr" if sceneProperties.tlm_encoding_mode_b == "LogLuv": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_b == "RGBM": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_b == "RGBD": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode_b == "SDR": formatEnc = ".png" if not background_pass: nodes.exchangeLightmapsToPostfix("_baked", end, formatEnc) if scene.TLM_EngineProperties.tlm_setting_supersample == "2x": supersampling_scale = 2 elif scene.TLM_EngineProperties.tlm_setting_supersample == "4x": supersampling_scale = 4 else: supersampling_scale = 1 pack.postpack() #We need to also make sure out postpacked atlases gets split w. premultiplied #CHECK FOR ATLAS MAPS! if bpy.context.scene.TLM_SceneProperties.tlm_split_premultiplied: dirpath = os.path.join(os.path.dirname(bpy.data.filepath), scene.TLM_EngineProperties.tlm_lightmap_savedir) dirfiles = [f for f in listdir(dirpath) if isfile(join(dirpath, f))] for atlas in bpy.context.scene.TLM_PostAtlasList: for file in dirfiles: if file.startswith(atlas.name): print("TODO: SPLIT LOGLUV FOR: " + str(file)) encoding.splitLogLuvAlpha(os.path.join(dirpath, file), dirpath, 0) #Need to update file list for some reason? dirfiles = [f for f in listdir(dirpath) if isfile(join(dirpath, f))] for atlas in bpy.context.scene.TLM_PostAtlasList: #FIND SOME WAY TO FIND THE RIGTH FILE! TOO TIRED NOW! for obj in bpy.context.scene.objects: if obj.TLM_ObjectProperties.tlm_postpack_object: if obj.TLM_ObjectProperties.tlm_postatlas_pointer == atlas.name: for slot in obj.material_slots: mat = slot.material node_tree = mat.node_tree foundBakedNode = False #for file in dirfiles: # if file.startswith(atlas.name): # if file.endswith("XYZ"): #Find nodes for node in node_tree.nodes: if node.name == "TLM_Lightmap": print("Found the main lightmap node: LOGLUV") for file in dirfiles: if file.startswith(atlas.name) and file.endswith("XYZ.png"): print("Found an atlas file: " + str(file)) node.image.filepath_raw = os.path.join(dirpath, file) print("CHANGED LIGHTMAP MAIN INTO XYZ: " + str(file)) if node.name == "TLM_Lightmap_Extra": print("Found the main lightmap node: LOGLUV") for file in dirfiles: if file.startswith(atlas.name) and file.endswith("W.png"): print("Found an atlas file: " + str(file)) node.image.filepath_raw = os.path.join(dirpath, file) print("CHANGED LIGHTMAP MAIN INTO W: " + str(file)) #print("Found the extra lightmap node: LOGLUV") # if node.image.filepath_raw.startswith(atlas.name): # if node.image.filepath_raw.endswith("W.png"): # print("ALREADY W: " + str(node.image.filepath_raw)) # else: # for file in dirfiles: # if file.startswith(atlas.name): # if file.endswith("W.png"): # node.image.filepath_raw = os.path.join(dirpath, file) # print("CHANGED LIGHTMAP MAIN INTO W: " + str(file)) #for file in dirfiles: # if file.endswith(end + ".hdr"): #for atlas in bpy.context.scene.TLM_PostAtlasList: #print("TODO: SPLIT LOGLUV FOR: " + str(atlas.name) + "..file?") #CHECK FOR ATLAS MAPS! #dirfiles = [f for f in listdir(dirpath) if isfile(join(dirpath, f))] # for file in dirfiles: # if file.endswith(end + ".hdr"): # img = bpy.data.images.load(os.path.join(dirpath, file), check_existing=False) # encoding.encodeLogLuvGPU(img, dirpath, 0) # if sceneProperties.tlm_split_premultiplied: # image_name = img.name # if image_name[-4:] == '.exr' or image_name[-4:] == '.hdr': # image_name = image_name[:-4] # image_name = image_name + '_encoded.png' # print("SPLIT PREMULTIPLIED: " + image_name) # encoding.splitLogLuvAlpha(os.path.join(dirpath, image_name), dirpath, 0) for image in bpy.data.images: if image.users < 1: bpy.data.images.remove(image) if scene.TLM_SceneProperties.tlm_headless: filepath = bpy.data.filepath dirpath = os.path.join(os.path.dirname(bpy.data.filepath), scene.TLM_EngineProperties.tlm_lightmap_savedir) for obj in bpy.context.scene.objects: if obj.type == 'MESH' and obj.name in bpy.context.view_layer.objects: if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: cache.backup_material_restore(obj) for obj in bpy.context.scene.objects: if obj.type == 'MESH' and obj.name in bpy.context.view_layer.objects: if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: cache.backup_material_rename(obj) for mat in bpy.data.materials: if mat.users < 1: bpy.data.materials.remove(mat) for mat in bpy.data.materials: if mat.name.startswith("."): if "_Original" in mat.name: bpy.data.materials.remove(mat) for obj in bpy.context.scene.objects: if obj.type == 'MESH' and obj.name in bpy.context.view_layer.objects: if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: if obj.TLM_ObjectProperties.tlm_mesh_lightmap_unwrap_mode == "AtlasGroupA": atlasName = obj.TLM_ObjectProperties.tlm_atlas_pointer img_name = atlasName + '_baked' Lightmapimage = bpy.data.images[img_name] obj["Lightmap"] = Lightmapimage.filepath_raw elif obj.TLM_ObjectProperties.tlm_postpack_object: atlasName = obj.TLM_ObjectProperties.tlm_postatlas_pointer img_name = atlasName + '_baked' + ".hdr" Lightmapimage = bpy.data.images[img_name] obj["Lightmap"] = Lightmapimage.filepath_raw else: img_name = obj.name + '_baked' Lightmapimage = bpy.data.images[img_name] obj["Lightmap"] = Lightmapimage.filepath_raw for image in bpy.data.images: if image.name.endswith("_baked"): bpy.data.images.remove(image, do_unlink=True) if "tlm_plus_mode" in bpy.app.driver_namespace: #First DIR pass if bpy.app.driver_namespace["tlm_plus_mode"] == 1: #First DIR pass filepath = bpy.data.filepath dirpath = os.path.join(os.path.dirname(bpy.data.filepath), scene.TLM_EngineProperties.tlm_lightmap_savedir) for obj in bpy.context.scene.objects: if obj.type == 'MESH' and obj.name in bpy.context.view_layer.objects: if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: cache.backup_material_restore(obj) for obj in bpy.context.scene.objects: if obj.type == 'MESH' and obj.name in bpy.context.view_layer.objects: if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: cache.backup_material_rename(obj) for mat in bpy.data.materials: if mat.users < 1: bpy.data.materials.remove(mat) for mat in bpy.data.materials: if mat.name.startswith("."): if "_Original" in mat.name: bpy.data.materials.remove(mat) for image in bpy.data.images: if image.name.endswith("_baked"): bpy.data.images.remove(image, do_unlink=True) dirpath = os.path.join(os.path.dirname(bpy.data.filepath), bpy.context.scene.TLM_EngineProperties.tlm_lightmap_savedir) files = os.listdir(dirpath) for index, file in enumerate(files): filename = extension = os.path.splitext(file)[0] extension = os.path.splitext(file)[1] os.rename(os.path.join(dirpath, file), os.path.join(dirpath, filename + "_dir" + extension)) print("First DIR pass complete") bpy.app.driver_namespace["tlm_plus_mode"] = 2 prepare_build(self=0, background_mode=False, shutdown_after_build=False) if not background_pass and bpy.context.scene.TLM_EngineProperties.tlm_lighting_mode != "combinedao": #pass setGui(0) elif bpy.app.driver_namespace["tlm_plus_mode"] == 2: filepath = bpy.data.filepath dirpath = os.path.join(os.path.dirname(bpy.data.filepath), bpy.context.scene.TLM_EngineProperties.tlm_lightmap_savedir) files = os.listdir(dirpath) for index, file in enumerate(files): filename = os.path.splitext(file)[0] extension = os.path.splitext(file)[1] if not filename.endswith("_dir"): os.rename(os.path.join(dirpath, file), os.path.join(dirpath, filename + "_ao" + extension)) print("Second AO pass complete") total_time = sec_to_hours((time() - start_time)) tlm_log.append(total_time) if bpy.context.scene.TLM_SceneProperties.tlm_verbose: print(total_time) bpy.context.scene["TLM_Buildstat"] = total_time reset_settings(previous_settings["settings"]) bpy.app.driver_namespace["tlm_plus_mode"] = 0 if not background_pass: #TODO CHANGE! nodes.exchangeLightmapsToPostfix(end, end + "_dir", formatEnc) nodes.applyAOPass() else: total_time = sec_to_hours((time() - start_time)) tlm_log.append(total_time) if bpy.context.scene.TLM_SceneProperties.tlm_verbose: print(total_time) bpy.context.scene["TLM_Buildstat"] = total_time reset_settings(previous_settings["settings"]) tlm_log.append("Lightmap building finished") tlm_log.append("--------------------------") print("Lightmap building finished") if sceneProperties.tlm_lightmap_engine == "LuxCoreRender": pass if sceneProperties.tlm_lightmap_engine == "OctaneRender": pass if bpy.context.scene.TLM_EngineProperties.tlm_bake_mode == "Background": pass if not background_pass and scene.TLM_EngineProperties.tlm_bake_mode != "Background" and bpy.context.scene.TLM_EngineProperties.tlm_lighting_mode != "combinedao": #pass setGui(0) if scene.TLM_SceneProperties.tlm_alert_on_finish: alertSelect = scene.TLM_SceneProperties.tlm_alert_sound if alertSelect == "dash": soundfile = "dash.ogg" elif alertSelect == "pingping": soundfile = "pingping.ogg" elif alertSelect == "gentle": soundfile = "gentle.ogg" else: soundfile = "noot.ogg" scriptDir = os.path.dirname(os.path.realpath(__file__)) sound_path = os.path.abspath(os.path.join(scriptDir, '..', 'assets/'+soundfile)) device = aud.Device() sound = aud.Sound.file(sound_path) device.play(sound) if logging: print("Log file output:") tlm_log.dumpLog() if bpy.app.background: if bpy.context.scene.TLM_SceneProperties.tlm_verbose: print("Writing background process report") write_directory = os.path.join(os.path.dirname(bpy.data.filepath), bpy.context.scene.TLM_EngineProperties.tlm_lightmap_savedir) if os.path.exists(os.path.join(write_directory, "process.tlm")): process_status = json.loads(open(os.path.join(write_directory, "process.tlm")).read()) process_status[1]["completed"] = True with open(os.path.join(write_directory, "process.tlm"), 'w') as file: json.dump(process_status, file, indent=2) if postprocess_shutdown: sys.exit()
def bake_ordered(self, context, process): scene = context.scene cycles = scene.cycles stats = [] # //////////// PRECONFIGURATION print("BAKING:!") #scene.TLM_SceneProperties.shiftMaterials = [] if not bpy.data.is_saved: self.report({'INFO'}, "Please save your file first") return {'FINISHED'} total_time = time() if not denoise.check_denoiser_path(self, scene): self.report({'INFO'}, "No denoise OIDN path assigned") return {'FINISHED'} utility.check_compatible_naming(self) prevSettings = utility.store_existing(cycles, scene, context) utility.set_settings(cycles, scene) # configure_World() objectconfig.configure_lights() print("////////////////////////////// CONFIGURING OBJECTS") objectconfig.configure_objects(self, scene) preconfig_time = sec_to_hours((time() - total_time)) # Baking print("////////////////////////////// BAKING LIGHTMAPS") lightbake.bake_objects(scene) bake_time = sec_to_hours((time() - total_time)) # Post configuration print("////////////////////////////// MANAGING LIGHTMAPS") utility.postmanage_materials(scene) postconfig_time = sec_to_hours((time() - total_time)) # Denoise lightmaps print("////////////////////////////// DENOISING LIGHTMAPS") denoise.denoise_lightmaps(scene) denoise_time = sec_to_hours((time() - total_time)) # Filter lightmaps print("////////////////////////////// FILTERING LIGHTMAPS") cfilter.filter_lightmaps(self, scene, module_opencv) filter_time = sec_to_hours((time() - total_time)) # Encode lightmaps print("////////////////////////////// ENCODING LIGHTMAPS") encoding.encode_lightmaps(scene) encode_time = sec_to_hours((time() - total_time)) # Apply lightmaps print("////////////////////////////// APPLY LIGHTMAPS") utility.apply_materials(self, scene) utility_time = sec_to_hours((time() - total_time)) # //////////// POSTCONFIGURATION utility.restore_settings(cycles, scene, prevSettings) # TODO! STORE SELECTION AND ACTIVE OBJECT # TODO! RESTORE SELECTION AND ACTIVE OBJECT print("////////////////////////////// LIGHTMAPS BUILT") # BEGIN AO Baking here... ambientbake.TLM_Build_AO() ao_time = sec_to_hours((time() - total_time)) # SAVE AO! # TODO: EXPOSE AO STRENGTH AND THRESHOLD ttime = sec_to_hours((time() - total_time)) stats.extend([ preconfig_time, bake_time, postconfig_time, denoise_time, filter_time, encode_time, utility_time, ao_time, ttime ]) scene.TLM_SceneProperties["stats"] = stats print("Baking finished in: {}".format(ttime)) dirpath = os.path.join(os.path.dirname(bpy.data.filepath), scene.TLM_SceneProperties.tlm_lightmap_savedir) if scene.TLM_SceneProperties.tlm_compile_statistics: f = open(dirpath + "/stats.txt", "w") f.write("Preconfig time after: " + str(preconfig_time) + "\n") f.write("Bake time after: " + str(bake_time) + "\n") f.write("Postconfig time after: " + str(postconfig_time) + "\n") f.write("Denoise time after: " + str(denoise_time) + "\n") f.write("Filter time after: " + str(filter_time) + "\n") f.write("Encode time after: " + str(encode_time) + "\n") f.write("Utility time after: " + str(utility_time) + "\n") f.write("AO time after: " + str(ao_time) + "\n") f.write("Total time: " + str(ttime) + "\n") f.close() # print("Preconfig time after: " + str(preconfig_time)) # print("Bake time after: " + str(bake_time)) # print("Postconfig time after: " + str(postconfig_time)) # print("Denoise time after: " + str(denoise_time)) # print("Filter time after: " + str(filter_time)) # print("Encode time after: " + str(encode_time)) # print("Utility time after: " + str(utility_time)) # print("AO time after: " + str(ao_time)) # print("Total time: " + str(ttime)) if scene.TLM_SceneProperties.tlm_play_sound: scriptDir = os.path.dirname(os.path.realpath(__file__)) sound_path = os.path.abspath( os.path.join(scriptDir, '..', 'Assets/sound.ogg')) device = aud.Device() sound = aud.Sound.file(sound_path) device.play(sound) process = False
def play(bpm=300, freq=220): dev = aud.Device() h = dev.play(tetris(bpm, freq, dev.rate)) h.loop_count = -1 return h
def manage_build(background_pass=False): scene = bpy.context.scene sceneProperties = scene.TLM_SceneProperties if sceneProperties.tlm_lightmap_engine == "Cycles": if background_pass: nodes.apply_lightmaps() nodes.apply_materials() #From here the name is changed... end = "_baked" if sceneProperties.tlm_denoise_use: end = "_denoised" if sceneProperties.tlm_filtering_use: end = "_filtered" formatEnc = ".hdr" if sceneProperties.tlm_encoding_use: if sceneProperties.tlm_encoding_mode == "HDR": if sceneProperties.tlm_format == "EXR": formatEnc = ".exr" if sceneProperties.tlm_encoding_mode == "LogLuv": formatEnc = "_encoded.png" if sceneProperties.tlm_encoding_mode == "RGBM": formatEnc = "_encoded.png" if not background_pass: nodes.exchangeLightmapsToPostfix("_baked", end, formatEnc) if sceneProperties.tlm_lightmap_engine == "LuxCoreRender": pass if sceneProperties.tlm_lightmap_engine == "OctaneRender": pass if bpy.context.scene.TLM_EngineProperties.tlm_bake_mode == "Background": pass #bpy.ops.wm.save_as_mainfile(filepath=bpy.data.filepath + "baked") #Crashes Blender if scene.TLM_EngineProperties.tlm_setting_supersample == "2x": supersampling_scale = 2 elif scene.TLM_EngineProperties.tlm_setting_supersample == "4x": supersampling_scale = 4 else: supersampling_scale = 1 # for image in bpy.data.images: # if image.name.endswith("_baked"): # resolution = image.size[0] # rescale = resolution / supersampling_scale # image.scale(rescale, rescale) # image.save() for image in bpy.data.images: if image.users < 1: bpy.data.images.remove(image) if scene.TLM_SceneProperties.tlm_headless: filepath = bpy.data.filepath dirpath = os.path.join(os.path.dirname(bpy.data.filepath), scene.TLM_EngineProperties.tlm_lightmap_savedir) for obj in bpy.data.objects: if obj.type == "MESH": if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: cache.backup_material_restore(obj) for obj in bpy.data.objects: if obj.type == "MESH": if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: cache.backup_material_rename(obj) for mat in bpy.data.materials: if mat.users < 1: bpy.data.materials.remove(mat) for mat in bpy.data.materials: if mat.name.startswith("."): if "_Original" in mat.name: bpy.data.materials.remove(mat) for obj in bpy.data.objects: if obj.type == "MESH": if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use: img_name = obj.name + '_baked' Lightmapimage = bpy.data.images[img_name] obj["Lightmap"] = Lightmapimage.filepath_raw for image in bpy.data.images: if image.name.endswith("_baked"): bpy.data.images.remove(image, do_unlink=True) total_time = sec_to_hours((time() - start_time)) print(total_time) reset_settings(previous_settings["settings"]) if scene.TLM_SceneProperties.tlm_alert_on_finish: alertSelect = scene.TLM_SceneProperties.tlm_alert_sound if alertSelect == "dash": soundfile = "dash.ogg" elif alertSelect == "pingping": soundfile = "pingping.ogg" elif alertSelect == "gentle": soundfile = "gentle.ogg" else: soundfile = "noot.ogg" scriptDir = os.path.dirname(os.path.realpath(__file__)) sound_path = os.path.abspath( os.path.join(scriptDir, '..', 'assets/' + soundfile)) device = aud.Device() sound = aud.Sound.file(sound_path) device.play(sound)
def execute(self, context): sound = context.node.get_sound() if sound != None: aud.Device().play(sound) return {"FINISHED"}