void BKE_sound_init(struct Main *bmain) { AUD_DeviceSpecs specs; int device, buffersize; device = U.audiodevice; buffersize = U.mixbufsize; specs.channels = U.audiochannels; specs.format = U.audioformat; specs.rate = U.audiorate; if (force_device >= 0) device = force_device; if (buffersize < 128) buffersize = AUD_DEFAULT_BUFFER_SIZE; if (specs.rate < AUD_RATE_8000) specs.rate = AUD_RATE_44100; if (specs.format <= AUD_FORMAT_INVALID) specs.format = AUD_FORMAT_S16; if (specs.channels <= AUD_CHANNELS_INVALID) specs.channels = AUD_CHANNELS_STEREO; if (!AUD_init(device, specs, buffersize)) AUD_init(AUD_NULL_DEVICE, specs, buffersize); BKE_sound_init_main(bmain); }
void BKE_sound_init(Main *bmain) { /* Make sure no instance of the sound system is running, otherwise we get leaks. */ BKE_sound_exit(); AUD_DeviceSpecs specs; int device, buffersize; const char *device_name; device = U.audiodevice; buffersize = U.mixbufsize; specs.channels = U.audiochannels; specs.format = U.audioformat; specs.rate = U.audiorate; if (force_device == NULL) { int i; char **names = BKE_sound_get_device_names(); device_name = names[0]; /* make sure device is within the bounds of the array */ for (i = 0; names[i]; i++) { if (i == device) { device_name = names[i]; } } } else { device_name = force_device; } if (buffersize < 128) { buffersize = 1024; } if (specs.rate < AUD_RATE_8000) { specs.rate = AUD_RATE_48000; } if (specs.format <= AUD_FORMAT_INVALID) { specs.format = AUD_FORMAT_S16; } if (specs.channels <= AUD_CHANNELS_INVALID) { specs.channels = AUD_CHANNELS_STEREO; } if (!(sound_device = AUD_init(device_name, specs, buffersize, "Blender"))) { sound_device = AUD_init("Null", specs, buffersize, "Blender"); } BKE_sound_init_main(bmain); }
void BKE_sound_init(struct Main *bmain) { AUD_DeviceSpecs specs; int device, buffersize; const char *device_name; device = U.audiodevice; buffersize = U.mixbufsize; specs.channels = U.audiochannels; specs.format = U.audioformat; specs.rate = U.audiorate; if (force_device == NULL) { int i; char **names = BKE_sound_get_device_names(); device_name = names[0]; /* make sure device is within the bounds of the array */ for (i = 0; names[i]; i++) { if (i == device) { device_name = names[i]; } } } else device_name = force_device; if (buffersize < 128) buffersize = 1024; if (specs.rate < AUD_RATE_8000) specs.rate = AUD_RATE_44100; if (specs.format <= AUD_FORMAT_INVALID) specs.format = AUD_FORMAT_S16; if (specs.channels <= AUD_CHANNELS_INVALID) specs.channels = AUD_CHANNELS_STEREO; if (!(sound_device = AUD_init(device_name, specs, buffersize, "Blender"))) sound_device = AUD_init("Null", specs, buffersize, "Blender"); BKE_sound_init_main(bmain); }
static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath) { bScreen *curscreen = NULL; Scene *curscene = NULL; int recover; enum { LOAD_UI = 1, LOAD_UI_OFF, LOAD_UNDO, } mode; if (BLI_listbase_is_empty(&bfd->main->screen)) { mode = LOAD_UNDO; } else if (G.fileflags & G_FILE_NO_UI) { mode = LOAD_UI_OFF; } else { mode = LOAD_UI; } recover = (G.fileflags & G_FILE_RECOVER); /* Free all render results, without this stale data gets displayed after loading files */ if (mode != LOAD_UNDO) { RE_FreeAllRenderResults(); } /* Only make filepaths compatible when loading for real (not undo) */ if (mode != LOAD_UNDO) { clean_paths(bfd->main); } /* XXX here the complex windowmanager matching */ /* no load screens? */ if (mode != LOAD_UI) { /* Logic for 'track_undo_scene' is to keep using the scene which the active screen has, * as long as the scene associated with the undo operation is visible in one of the open windows. * * - 'curscreen->scene' - scene the user is currently looking at. * - 'bfd->curscene' - scene undo-step was created in. * * This means users can have 2+ windows open and undo in both without screens switching. * But if they close one of the screens, * undo will ensure that the scene being operated on will be activated * (otherwise we'd be undoing on an off-screen scene which isn't acceptable). * see: T43424 */ bool track_undo_scene; /* comes from readfile.c */ SWAP(ListBase, G.main->wm, bfd->main->wm); SWAP(ListBase, G.main->screen, bfd->main->screen); SWAP(ListBase, G.main->script, bfd->main->script); /* we re-use current screen */ curscreen = CTX_wm_screen(C); /* but use new Scene pointer */ curscene = bfd->curscene; track_undo_scene = (mode == LOAD_UNDO && curscreen && curscene && bfd->main->wm.first); if (curscene == NULL) curscene = bfd->main->scene.first; /* empty file, we add a scene to make Blender work */ if (curscene == NULL) curscene = BKE_scene_add(bfd->main, "Empty"); if (track_undo_scene) { /* keep the old (free'd) scene, let 'blo_lib_link_screen_restore' * replace it with 'curscene' if its needed */ } else { /* and we enforce curscene to be in current screen */ if (curscreen) { /* can run in bgmode */ curscreen->scene = curscene; } } /* clear_global will free G.main, here we can still restore pointers */ blo_lib_link_screen_restore(bfd->main, curscreen, curscene); /* curscreen might not be set when loading without ui (see T44217) so only re-assign if available */ if (curscreen) { curscene = curscreen->scene; } if (track_undo_scene) { wmWindowManager *wm = bfd->main->wm.first; if (wm_scene_is_visible(wm, bfd->curscene) == false) { curscene = bfd->curscene; curscreen->scene = curscene; BKE_screen_view3d_scene_sync(curscreen); } } } /* free G.main Main database */ // CTX_wm_manager_set(C, NULL); clear_global(); /* clear old property update cache, in case some old references are left dangling */ RNA_property_update_cache_free(); G.main = bfd->main; CTX_data_main_set(C, G.main); BKE_sound_init_main(G.main); if (bfd->user) { /* only here free userdef themes... */ BKE_userdef_free(); U = *bfd->user; /* Security issue: any blend file could include a USER block. * * Currently we load prefs from BLENDER_STARTUP_FILE and later on load BLENDER_USERPREF_FILE, * to load the preferences defined in the users home dir. * * This means we will never accidentally (or maliciously) * enable scripts auto-execution by loading a '.blend' file. */ U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE; MEM_freeN(bfd->user); } /* case G_FILE_NO_UI or no screens in file */ if (mode != LOAD_UI) { /* leave entire context further unaltered? */ CTX_data_scene_set(C, curscene); } else { G.fileflags = bfd->fileflags; CTX_wm_manager_set(C, G.main->wm.first); CTX_wm_screen_set(C, bfd->curscreen); CTX_data_scene_set(C, bfd->curscene); CTX_wm_area_set(C, NULL); CTX_wm_region_set(C, NULL); CTX_wm_menu_set(C, NULL); curscene = bfd->curscene; } /* this can happen when active scene was lib-linked, and doesn't exist anymore */ if (CTX_data_scene(C) == NULL) { /* in case we don't even have a local scene, add one */ if (!G.main->scene.first) BKE_scene_add(G.main, "Scene"); CTX_data_scene_set(C, G.main->scene.first); CTX_wm_screen(C)->scene = CTX_data_scene(C); curscene = CTX_data_scene(C); } BLI_assert(curscene == CTX_data_scene(C)); /* special cases, override loaded flags: */ if (G.f != bfd->globalf) { const int flags_keep = (G_SWAP_EXCHANGE | G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF); bfd->globalf = (bfd->globalf & ~flags_keep) | (G.f & flags_keep); } G.f = bfd->globalf; #ifdef WITH_PYTHON /* let python know about new main */ BPY_context_update(C); #endif if (!G.background) { //setscreen(G.curscreen); } /* FIXME: this version patching should really be part of the file-reading code, * but we still get too many unrelated data-corruption crashes otherwise... */ if (G.main->versionfile < 250) do_versions_ipos_to_animato(G.main); G.main->recovered = 0; /* startup.blend or recovered startup */ if (bfd->filename[0] == 0) { G.main->name[0] = 0; } else if (recover && G.relbase_valid) { /* in case of autosave or quit.blend, use original filename instead * use relbase_valid to make sure the file is saved, else we get <memory2> in the filename */ filepath = bfd->filename; G.main->recovered = 1; /* these are the same at times, should never copy to the same location */ if (G.main->name != filepath) BLI_strncpy(G.main->name, filepath, FILE_MAX); } /* baseflags, groups, make depsgraph, etc */ /* first handle case if other windows have different scenes visible */ if (mode == LOAD_UI) { wmWindowManager *wm = G.main->wm.first; if (wm) { wmWindow *win; for (win = wm->windows.first; win; win = win->next) { if (win->screen && win->screen->scene) /* zealous check... */ if (win->screen->scene != curscene) BKE_scene_set_background(G.main, win->screen->scene); } } } BKE_scene_set_background(G.main, curscene); if (mode != LOAD_UNDO) { IMB_colormanagement_check_file_config(G.main); } MEM_freeN(bfd); }