library .blend files anymore, making it a load faster to use.
- Fixed ancient annoyance; samples were not properly freed, giving a lot
"Error Totblock" when using sound.
This fix also involves removing an ancient NaN hack, which treated the
samples as fake Library data in the Main database.
But still, the Blender Sound and Sample code is horrible... :/
struct bSample;
struct ListBase;
+/* bad bad global... */
extern struct ListBase *samples;
+void sound_free_all_samples(void);
+
/* void *sound_get_listener(void); implemented in src!also declared there now */
void sound_set_packedfile(struct bSample* sample, struct PackedFile* pf);
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_scene.h"
+#include "BKE_sound.h"
#include "BLI_editVert.h"
void free_blender(void)
{
+ /* samples are in a global list..., also sets G.main->sound->sample NULL */
+ sound_free_all_samples();
+
free_main(G.main);
G.main= NULL;
IMB_freeImBufdata(); /* imbuf lib */
+
}
void duplicatelist(ListBase *list1, ListBase *list2) /* copy from 2 to 1 */
lib_link_screen_restore(bfd->main, curscene);
}
- clear_global();
+ clear_global(); /* free Main database */
if(mode!='u') G.save_over = 1;
}
+ /* samples is a global list... */
+ sound_free_all_samples();
+
/* case G_FILE_NO_UI or no screens in file */
if(mode) {
G.curscreen= curscreen;
return (bfd?1:0);
}
+/* memfile is the undo buffer */
int BKE_read_file_from_memfile(MemFile *memfile)
{
BlendReadError bre;
return &(mainlib->script);
case ID_SO:
return &(mainlib->sound);
- case ID_SAMPLE:
- /* declared as an external in sound.h !!! */
- return (samples);
case ID_GR:
return &(mainlib->group);
case ID_AR:
lb[22]= &(main->group);
lb[23]= &(main->nodetree);
lb[24]= &(main->brush);
+ lb[25]= &(main->script);
+ lb[26]= NULL;
- lb[25]= samples;
- lb[26]= &(main->script);
- lb[27]= NULL;
-
- return 27;
+ return 26;
}
/* *********** ALLOC AND FREE *****************
case ID_SO:
id= MEM_callocN(sizeof(bSound), "sound");
break;
- case ID_SAMPLE:
- id = MEM_callocN(sizeof(bSample), "sound");
- break;
case ID_GR:
- id= MEM_callocN(sizeof(Group), "sound");
+ id= MEM_callocN(sizeof(Group), "group");
break;
case ID_AR:
id = MEM_callocN(sizeof(bArmature), "armature");
case ID_SO:
sound_free_sound((bSound *)id);
break;
- case ID_SAMPLE:
- sound_free_sample((bSample *)id);
- break;
case ID_GR:
free_group((Group *)id);
break;
}
}
-
+/* this is called after file reading or undos */
+void sound_free_all_samples(void)
+{
+ bSample *sample;
+ bSound *sound;
+
+ /* ensure no sample pointers exist, and check packedfile */
+ for(sound= G.main->sound.first; sound; sound= sound->id.next) {
+ if(sound->sample && sound->sample->packedfile==sound->newpackedfile)
+ sound->newpackedfile= NULL;
+ sound->sample= NULL;
+ }
+
+ /* now free samples */
+ for(sample= samples->first; sample; sample= sample->id.next)
+ sound_free_sample(sample);
+ BLI_freelistN(samples);
+
+}
void sound_set_packedfile(bSample *sample, PackedFile *pf)
{
#include "BKE_utildefines.h" // for ENDB
#include "BKE_main.h"
+#include "BKE_global.h"
#include "BKE_library.h" // for free_main
#include "BLO_readfile.h"
{ ID_ME, "Mesh", IDTYPE_FLAGS_ISLINKABLE},
{ ID_NT, "NodeTree", IDTYPE_FLAGS_ISLINKABLE},
{ ID_OB, "Object", IDTYPE_FLAGS_ISLINKABLE},
- { ID_SAMPLE, "Sample", 0},
{ ID_SCE, "Scene", IDTYPE_FLAGS_ISLINKABLE},
{ ID_SCR, "Screen", 0},
{ ID_SEQ, "Sequence", 0},
return bfd;
}
-
BlendFileData *BLO_read_from_memfile(const char *filename, MemFile *memfile, BlendReadError *error_r)
{
BlendFileData *bfd = NULL;
FileData *fd;
-
+ ListBase mainlist;
+
fd = blo_openblendermemfile(memfile, error_r);
if (fd) {
strcpy(fd->filename, filename);
+ /* separate libraries from G.main */
+ blo_split_main(&mainlist, G.main);
+ /* add the library pointers in oldmap lookup */
+ blo_add_library_pointer_map(&mainlist, fd);
+
/* makes lookup of existing images in G.main */
blo_make_image_pointer_map(fd);
/* ensures relinked images are not freed */
blo_end_image_pointer_map(fd);
+ /* move libraries from G.main to new main */
+ if(bfd && mainlist.first!=mainlist.last) {
+
+ /* Library structs themselves */
+ bfd->main->library= G.main->library;
+ G.main->library.first= G.main->library.last= NULL;
+
+ /* add the Library mainlist to the new main */
+ BLI_remlink(&mainlist, G.main);
+ BLI_addhead(&mainlist, bfd->main);
+ }
+ blo_join_main(&mainlist);
+
blo_freefiledata(fd);
}
return NULL;
}
-/* for libdate, nr has ID code, no increment */
+/* for libdata, nr has ID code, no increment */
static void *oldnewmap_liblookup(OldNewMap *onm, void *addr, void *lib)
{
int i;
}
}
-void blo_split_main(ListBase *mainlist)
+void blo_split_main(ListBase *mainlist, Main *main)
{
- Main *mainl= mainlist->first;
ListBase *lbarray[MAX_LIBARRAY];
Library *lib;
int i;
- for (lib= mainl->library.first; lib; lib= lib->id.next) {
+ mainlist->first= mainlist->last= main;
+ main->next= NULL;
+
+ if(main->library.first==NULL)
+ return;
+
+ for (lib= main->library.first; lib; lib= lib->id.next) {
Main *libmain= MEM_callocN(sizeof(Main), "libmain");
libmain->curlib= lib;
BLI_addtail(mainlist, libmain);
}
- i= set_listbasepointers(mainl, lbarray);
+ i= set_listbasepointers(main, lbarray);
while(i--)
- split_libdata(lbarray[i], mainl->next);
+ split_libdata(lbarray[i], main->next);
}
/* removes things like /blah/blah/../../blah/ etc, then writes in *name the full path */
{
ID *id= newlibadr(fd, lib, adr);
- if(id) {
+ if(id)
id->us++;
- }
return id;
}
}
}
+/* undo file support: add all library pointers in lookup */
+void blo_add_library_pointer_map(ListBase *mainlist, FileData *fd)
+{
+ Main *main= mainlist->first;
+ ListBase *lbarray[MAX_LIBARRAY];
+
+ for(main= main->next; main; main= main->next) {
+ int i= set_listbasepointers(main, lbarray);
+ while(i--) {
+ ID *id;
+ for(id= lbarray[i]->first; id; id= id->next)
+ oldnewmap_insert(fd->libmap, id, id, GS(id->name));
+ }
+ }
+}
+
+
/* ********** END OLD POINTERS ****************** */
/* ********** READ FILE ****************** */
case ID_VF: return "Data from VF";
case ID_TXT : return "Data from TXT";
case ID_SO: return "Data from SO";
- case ID_SAMPLE: return "Data from SAMPLE";
case ID_NT: return "Data from NT";
case ID_BR: return "Data from BR";
}
Mesh *me;
bScreen *sc;
- for (sound=main->sound.first; sound; sound=sound->id.next)
- {
+ for (sound=main->sound.first; sound; sound=sound->id.next) {
if (sound->packedfile) {
if (sound->newpackedfile == NULL) {
sound->newpackedfile = sound->packedfile;
*/
bhead = read_libblock(fd, fd->mainlist.last, bhead, LIB_READ+LIB_EXTERN, NULL);
break;
-// case ID_GR:
-// bhead = blo_nextbhead(fd, bhead);
-// break;
default:
bhead = read_libblock(fd, bfd->main, bhead, LIB_LOCAL, NULL);
}
}
- /* before read_libraries */
- do_versions(fd, NULL, bfd->main);
+ /* do before read_libraries, but skip undo case */
+// if(fd->memfile==NULL) (the mesh shuffle hacks don't work yet? ton)
+ do_versions(fd, NULL, bfd->main);
read_libraries(fd, &fd->mainlist);
blo_join_main(&fd->mainlist);
Main *mainl;
FileData *fd = (FileData *)bh;
- mainlist.first= mainlist.last= G.main;
- G.main->next= NULL;
-
/* make mains */
- blo_split_main(&mainlist);
+ blo_split_main(&mainlist, G.main);
/* which one do we need? */
mainl = blo_find_main(&mainlist, dir, G.sce);
if(sfile->flag & FILE_AUTOSELECT) scene_deselect_all(G.scene);
- fd->mainlist.first= fd->mainlist.last= G.main;
- G.main->next= NULL;
-
/* make mains */
- blo_split_main(&fd->mainlist);
+ blo_split_main(&fd->mainlist, G.main);
/* which one do we need? */
mainl = blo_find_main(&fd->mainlist, dir, G.sce);
#define SIZEOFBLENDERHEADER 12
/***/
-
+struct Main;
void blo_join_main(ListBase *mainlist);
-void blo_split_main(ListBase *mainlist);
+void blo_split_main(ListBase *mainlist, struct Main *main);
BlendFileData *blo_read_file_internal( FileData *fd, BlendReadError *error_r);
void blo_make_image_pointer_map(FileData *fd);
void blo_end_image_pointer_map(FileData *fd);
+void blo_add_library_pointer_map(ListBase *mainlist, FileData *fd);
void blo_freefiledata( FileData *fd);
ID *id;
int a, tot, foundone;
- while(main) {
+ for(; main; main= main->next) {
a=tot= set_listbasepointers(main, lbarray);
/* test: is lib being used */
foundone= 0;
while(tot--) {
- id= lbarray[tot]->first;
- while(id) {
+ for(id= lbarray[tot]->first; id; id= id->next) {
if(id->us>0 && (id->flag & LIB_EXTERN)) {
foundone= 1;
break;
}
- id= id->next;
}
if(foundone) break;
}
writestruct(wd, ID_LI, "Library", 1, main->curlib);
while(a--) {
- id= lbarray[a]->first;
- while(id) {
- if(G.rt==127 && GS(id->name)!=ID_GR) break;
-
+ for(id= lbarray[a]->first; id; id= id->next) {
if(id->us>0 && (id->flag & LIB_EXTERN)) {
-
writestruct(wd, ID_ID, "ID", 1, id);
}
- id= id->next;
}
}
}
-
- main= main->next;
}
}
writestruct(wd, GLOB, "FileGlobal", 1, &fg);
}
-/* if *mem there's filesave to memory */
+/* if MemFile * there's filesave to memory */
static int write_file_handle(int handle, MemFile *compare, MemFile *current, int write_user_block, int write_flags)
{
BHead bhead;
ListBase mainlist;
char buf[13];
WriteData *wd;
-/* int data; */ /*unused*/
-
- mainlist.first= mainlist.last= G.main;
- G.main->next= NULL;
- blo_split_main(&mainlist);
+ blo_split_main(&mainlist, G.main);
wd= bgnwrite(handle, compare, current, write_flags);
write_renderinfo(wd);
if(current==NULL)
- write_screens (wd, &G.main->screen); // no UI save
+ write_screens (wd, &G.main->screen); /* no UI save in undo */
write_scenes (wd, &G.main->scene);
write_curves (wd, &G.main->curve);
write_mballs (wd, &G.main->mball);
write_meshs (wd, &G.main->mesh);
write_nodetrees(wd, &G.main->nodetree);
write_brushes (wd, &G.main->brush);
- write_libraries(wd, G.main->next);
+ if(current==NULL)
+ write_libraries(wd, G.main->next); /* no library save in undo */
write_global(wd);
if (write_user_block) {
{
char userfilename[FILE_MAXDIR+FILE_MAXFILE];
char tempname[FILE_MAXDIR+FILE_MAXFILE];
- int file, fout, write_user_block;
+ int file, err, write_user_block;
sprintf(tempname, "%s@", dir);
write_user_block= BLI_streq(dir, userfilename);
- fout= write_file_handle(file, NULL,NULL, write_user_block, write_flags);
+ err= write_file_handle(file, NULL,NULL, write_user_block, write_flags);
close(file);
- if(!fout) {
+ if(!err) {
if(write_flags & G_FILE_COMPRESS)
{
// compressed files have the same ending as regular files... only from 2.4!!!
#define BLITTLE_ENDIAN
#endif
-/* ID */
+/* ID from database */
#define ID_SCE MAKE_ID2('S', 'C')
#define ID_LI MAKE_ID2('L', 'I')
#define ID_OB MAKE_ID2('O', 'B')
#define ID_VF MAKE_ID2('V', 'F')
#define ID_TXT MAKE_ID2('T', 'X')
#define ID_SO MAKE_ID2('S', 'O')
-#define ID_SAMPLE MAKE_ID2('S', 'A')
#define ID_GR MAKE_ID2('G', 'R')
#define ID_ID MAKE_ID2('I', 'D')
#define ID_AR MAKE_ID2('A', 'R')
#define ID_AC MAKE_ID2('A', 'C')
#define ID_SCRIPT MAKE_ID2('P', 'Y')
-#define ID_FLUIDSIM MAKE_ID2('F', 'S')
#define ID_NT MAKE_ID2('N', 'T')
#define ID_BR MAKE_ID2('B', 'R')
#define ID_PO MAKE_ID2('A', 'C')
/* used in outliner... */
#define ID_NLA MAKE_ID2('N', 'L')
+ /* fluidsim Ipo */
+#define ID_FLUIDSIM MAKE_ID2('F', 'S')
+
/*#ifdef WITH_VERSE*/
#define ID_VS MAKE_ID2('V', 'S') /* fake id for VerseSession, needed for outliner */
break;
case B_SOUND_MENU_SAMPLE:
- if (G.buts->menunr == -2) {
- if (sound) {
- activate_databrowse((ID *)sound->sample, ID_SAMPLE, 0, B_SOUND_MENU_SAMPLE, &G.buts->menunr, do_soundbuts);
- }
- } else if (G.buts->menunr > 0) {
+ if (G.buts->menunr > 0) {
sample = BLI_findlink(samples, G.buts->menunr - 1);
if (sample && sound) {
BLI_strncpy(sound->name, sample->name, sizeof(sound->name));
}
+static char *make_sample_menu(void)
+{
+ int len= BLI_countlist(samples); /* BKE_sound.h */
+
+ if(len) {
+ bSample *sample;
+ char *str;
+ int nr, a=0;
+
+ str= MEM_callocN(32*len, "menu");
+
+ for(nr=1, sample= samples->first; sample; sample= sample->id.next, nr++) {
+ a+= sprintf(str+a, "|%s %%x%d", sample->id.name+2, nr);
+ }
+ return str;
+ }
+ return NULL;
+}
+
static void sound_panel_sound(bSound *sound)
{
static int packdummy=0;
ID *id, *idfrom;
uiBlock *block;
bSample *sample;
- char *strp, str[32], ch[256];
+ char *strp, ch[256];
block= uiNewBlock(&curarea->uiblocks, "sound_panel_sound", UI_EMBOSS, UI_HELV, curarea->win);
if(uiNewPanel(curarea, block, "Sound", "Sound", 0, 0, 318, 204)==0) return;
}
/* sample browse buttons */
-
- id= (ID *)sound->sample;
- IDnames_to_pupstring(&strp, NULL, NULL, samples, id, &(G.buts->menunr));
- if (strp[0]) uiDefButS(block, MENU, B_SOUND_MENU_SAMPLE, strp, 10,120,23,20, &(G.buts->menunr), 0, 0, 0, 0, "Select another loaded sample");
- MEM_freeN(strp);
-
- uiDefBut(block, TEX, B_SOUND_NAME_SAMPLE, "", 35,120,225,20, sound->name, 0.0, 79.0, 0, 0, "The sample file used by this Sound");
-
- sprintf(str, "%d", sample->id.us);
- uiDefBut(block, BUT, B_SOUND_UNLINK_SAMPLE, str, 260,120,25,20, 0, 0, 0, 0, 0, "The number of users");
+ uiBlockBeginAlign(block);
+ strp= make_sample_menu();
+ if (strp) {
+ uiDefButS(block, MENU, B_SOUND_MENU_SAMPLE, strp, 10,120,23,20, &(G.buts->menunr), 0, 0, 0, 0, "Select another loaded sample");
+ MEM_freeN(strp);
+ }
+ uiDefBut(block, TEX, B_SOUND_NAME_SAMPLE, "", 35,120,250,20, sound->name, 0.0, 79.0, 0, 0, "The sample file used by this Sound");
if (sound->sample->packedfile) packdummy = 1;
else packdummy = 0;
uiDefIconButBitI(block, TOG, 1, B_SOUND_UNPACK_SAMPLE, ICON_PACKAGE,
- 285, 120,25,24, &packdummy, 0, 0, 0, 0,"Pack/Unpack this sample");
+ 285, 120,25,20, &packdummy, 0, 0, 0, 0,"Pack/Unpack this sample");
+ uiBlockBeginAlign(block);
uiDefBut(block, BUT, B_SOUND_LOAD_SAMPLE, "Load sample", 10, 95,150,24, 0, 0, 0, 0, 0, "Load a different sample file");
uiDefBut(block, BUT, B_SOUND_PLAY_SAMPLE, "Play", 160, 95, 150, 24, 0, 0.0, 0, 0, 0, "Playback sample using settings below");
+ uiBlockBeginAlign(block);
uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
10,70,150,20, &sound->volume, 0.0, 1.0, 0, 0, "Game engine only: Set the volume of this sound");
160,70,150,20, &sound->pitch, -12.0, 12.0, 0, 0, "Game engine only: Set the pitch of this sound");
/* looping */
+ uiBlockBeginAlign(block);
uiDefButBitI(block, TOG, SOUND_FLAGS_LOOP, B_SOUND_REDRAW, "Loop",
10, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Game engine only: Toggle between looping on/off");
/* 3D settings ------------------------------------------------------------------ */
+ uiBlockBeginAlign(block);
if (sound->sample->channels == 1) {
uiDefButBitI(block, TOG, SOUND_FLAGS_3D, B_SOUND_REDRAW, "3D Sound",
void sound_initialize_sounds(void)
{
- bSound* sound;
+ bSound *sound;
if(ghSoundScene) {
/* initialize sample blocks (doesnt call audio system, needs to be done once after load */
sound = G.main->sound.first;
- while (sound)
- {
+ while (sound) {
sound_sample_is_null(sound);
sound = (bSound *) sound->id.next;
}
-bSound* sound_make_copy(bSound* originalsound)
+bSound *sound_make_copy(bSound *originalsound)
{
- bSound* sound = NULL;
+ bSound *sound = NULL;
char name[160];
int len;
-void sound_initialize_sample(bSound* sound)
+void sound_initialize_sample(bSound *sound)
{
if(ghSoundScene==NULL) sound_init_audio();
}
-void sound_read_wav_data(bSound* sound, PackedFile* pf)
+void sound_read_wav_data(bSound *sound, PackedFile *pf)
{
int i, temp;
short shortbuf, *temps;
rewindPackedFile(pf);
/* check to see if it is a file in "RIFF WAVE fmt" format */
- if (readPackedFile(pf, buffer, 16) != 16)
- {
+ if (readPackedFile(pf, buffer, 16) != 16) {
if (G.f & G_DEBUG) printf("File too short\n");
return;
}
- if(!(memcmp(buffer, "RIFF", 4) && memcmp(&(buffer[8]), "WAVEfmt ", 8)))
- {
+ if(!(memcmp(buffer, "RIFF", 4) && memcmp(&(buffer[8]), "WAVEfmt ", 8))) {
readPackedFile(pf, &i, 4);// start of data
if(G.order==B_ENDIAN)
SWITCH_INT(i);
/* read the sampleformat */
readPackedFile(pf, &shortbuf, 2);
- if(G.order==B_ENDIAN)
- {
+ if(G.order==B_ENDIAN) {
SWITCH_SHORT(shortbuf);
}
/* read the number of channels */
readPackedFile(pf, &shortbuf, 2);
- if(G.order==B_ENDIAN)
- {
+ if(G.order==B_ENDIAN) {
SWITCH_SHORT(shortbuf);
}
/* check the number of channels */
- if(shortbuf != 1 && shortbuf != 2)
- {
+ if(shortbuf != 1 && shortbuf != 2) {
if (G.f & G_DEBUG) printf("Unsupported number of channels\n");
return;
}
readPackedFile(pf, &shortbuf, 2);
readPackedFile(pf, &shortbuf, 2);
- if(G.order==B_ENDIAN)
- {
+ if(G.order==B_ENDIAN) {
SWITCH_SHORT(shortbuf);
}
bits = shortbuf;
seekPackedFile(pf, i-16, SEEK_CUR);
readPackedFile(pf, buffer, 4);
/* check if we have a 'data' chunk */
- while(memcmp(buffer, "data", 4)!=0)
- {
+ while(memcmp(buffer, "data", 4)!=0) {
if (readPackedFile(pf, &i, 4) != 4)
break;
}
/* guess not */
- if (memcmp(buffer, "data", 4) !=0)
- {
+ if (memcmp(buffer, "data", 4) !=0) {
if (G.f & G_DEBUG) printf("No data found\n");
}
/* or maybe we do! */
- else
- {
+ else {
readPackedFile(pf, &longbuf, 4);
if(G.order==B_ENDIAN) SWITCH_INT(longbuf);
len = longbuf /*/ 4.0*/; /* for some strange reason the sample length is off by a factor of 4... */
/* intrr's comment: Funny eh, how one 16-bit stereo sample is 4 bytes? :-) */
- if(data)
- {
+ if(data) {
readPackedFile(pf, data, len);
/* data is only used to draw! */
- if (bits == 8)
- {
+ if (bits == 8) {
temps = (short *) data;
tempc = (char *) data;
for (i = len - 1; i >= 0; i--)
temps[i] = tempc[i] << 8;
}
- else
- {
- if(G.order==B_ENDIAN)
- {
+ else {
+ if(G.order==B_ENDIAN) {
swab(data, data, len);
}
}
}
}
}
- else
- {
+ else {
sound->sample->type = SAMPLE_INVALID;
if (G.f & G_DEBUG) printf("Unsupported sound format: %s\n", sound->name);
}
/* ugly, but it works (for now) */
-static int sound_get_filetype_from_header(bSound* sound, PackedFile* pf)
+static int sound_get_filetype_from_header(bSound *sound, PackedFile *pf)
{
int filetype = SAMPLE_INVALID;
int i;
rewindPackedFile(pf);
- if (readPackedFile(pf, buffer, 16) != 16)
- {
+ if (readPackedFile(pf, buffer, 16) != 16) {
if (G.f & G_DEBUG) printf("File too short\n");
return filetype;
}
- if(!(memcmp(buffer, "RIFF", 4) && memcmp(&(buffer[8]), "WAVEfmt ", 8)))
- {
+ if(!(memcmp(buffer, "RIFF", 4) && memcmp(&(buffer[8]), "WAVEfmt ", 8))) {
readPackedFile(pf, &i, 4);
if(G.order==B_ENDIAN)
SWITCH_INT(i);
/* read the sampleformat */
readPackedFile(pf, &shortbuf, 2);
- if(G.order==B_ENDIAN)
- {
+ if(G.order==B_ENDIAN) {
char s_i, *p_i;
p_i= (char *)&(shortbuf);
s_i= p_i[0];
p_i[1]= s_i;
}
- if (shortbuf == SND_WAVE_FORMAT_PCM)
- {
+ if (shortbuf == SND_WAVE_FORMAT_PCM) {
filetype = SAMPLE_WAV;
}
else
#ifdef USE_FMOD
}
}
- else if (!memcmp(buffer, "OggS", 4))
- {
+ else if (!memcmp(buffer, "OggS", 4)) {
filetype = SAMPLE_OGG_VORBIS;
}
- else if ((!memcmp(buffer, "ID3", 3)) || (!memcmp(buffer, "", 2)))
- {
+ else if ((!memcmp(buffer, "ID3", 3)) || (!memcmp(buffer, "", 2))) {
filetype = SAMPLE_MP3;
}
#endif
- else
- {
+ else {
filetype = SAMPLE_INVALID;
if (G.f & G_DEBUG) printf("Unsupported sound format: %s\n", sound->name);
}
-static int check_filetype(bSound* sound, PackedFile* pf)
+static int check_filetype(bSound *sound, PackedFile *pf)
{
// char* pdest;
sound->sample->type = SAMPLE_INVALID;
sound->sample->type = sound_get_filetype_from_header(sound, pf);
/* get some info from the sample */
- switch (sound->sample->type)
- {
+ switch (sound->sample->type) {
case SAMPLE_WAV:
{
sound_read_wav_data(sound, pf);
-int sound_load_sample(bSound* sound)
+int sound_load_sample(bSound *sound)
{
int result = FALSE;
- PackedFile* pf;
+ PackedFile *pf;
int freePF = FALSE;
int buffer = -1;
if(ghSoundScene==NULL) sound_init_audio();
/* check the sample (valid?) */
- if (sound->sample->type == SAMPLE_UNKNOWN || sound->snd_sound == NULL)
- {
+ if (sound->sample->type == SAMPLE_UNKNOWN || sound->snd_sound == NULL) {
/* find... */
pf = sound_find_packedfile(sound);
/* ...or create a (temp)packedfile */
- if (pf == NULL)
- {
+ if (pf == NULL) {
pf = newPackedFile(sound->name);
/* if autopack is off, free the pf afterwards */
}
/* if we have a valid pf... */
- if (pf)
- {
+ if (pf) {
/* check the content of the pf */
check_filetype(sound, pf);
/* check if the sampletype is supported */
- if (sound->sample->type != SAMPLE_INVALID && sound->sample->type != SAMPLE_UNKNOWN)
- {
+ if (sound->sample->type != SAMPLE_INVALID && sound->sample->type != SAMPLE_UNKNOWN) {
/* register the sample at the audiodevice */
buffer = SND_AddSample(ghSoundScene, sound->sample->name, pf->data, pf->size);
result = TRUE;
}
/* if not, free the pf */
- else
- {
+ else {
freePF = TRUE;
}
/* if you want it freed, make it so */
- if (freePF)
- {
+ if (freePF) {
freePackedFile(pf);
pf = NULL;
}
/* or else connect the pf to the sound and sample */
-// else
-// {
+// else {
sound->newpackedfile = pf;
sound->sample->packedfile = pf;
// }
}
- else
- {
+ else {
if (G.f & G_DEBUG) printf("%s: File not found!\n", sound->name);
sound->sample->type = SAMPLE_INVALID;
}
}
/* if the sample ain't invalid, we're ready to go! */
- else if (sound->sample->type != SAMPLE_INVALID)
- {
+ else if (sound->sample->type != SAMPLE_INVALID) {
result = TRUE;
}
-bSound* sound_new_sound(char* name)
+bSound *sound_new_sound(char *name)
{
bSound *sound = NULL;
int len, file;
/* check if the sample on disk can be opened */
file = open(str, O_BINARY|O_RDONLY);
- if (file != -1)
- {
+ if (file != -1) {
close(file);
/* load the sample & check if this blender supports the sound format */
// sound_load_sample(sound);
- if (sound->sample->type == SAMPLE_INVALID)
- {
+ if (sound->sample->type == SAMPLE_INVALID) {
free_libblock(&G.main->sound, sound);
sound = NULL;
}
if(ghSoundScene==NULL) sound_init_audio();
- /* decrease the usernumber for this sample */
- if (sound->sample)
- sound->sample->id.us--;
-
/* delete the soundobject */
- if (sound->snd_sound)
- {
+ if (sound->snd_sound) {
SND_RemoveSound(ghSoundScene, sound->snd_sound);
sound->snd_sound = NULL;
}
sound->sample = sample;
sound->newpackedfile = NULL;
- /* increase the usercount */
- if (sound->sample)
- {
- sound->sample->id.us++;
+ if (sound->sample) {
/* and set the right pf */
sound->newpackedfile = sample->packedfile;
/* if the sampletype is unknown initialize it */
- if (sound->sample->type == SAMPLE_UNKNOWN)
- {
+ if (sound->sample->type == SAMPLE_UNKNOWN) {
sound_initialize_sample(sound);
/* load the sample & check if this blender supports the sound format */
- if (!sound_load_sample(sound))
- {
+ if (!sound_load_sample(sound)) {
result = FALSE;
}
}
-bSample *sound_new_sample(bSound * sound)
+bSample *sound_new_sample(bSound *sound)
{
bSample *sample = NULL;
int len;
char *name;
- if (sound != NULL)
- {
+ if (sound != NULL) {
name = sound->name;
len = strlen(name);
/* do some name magic */
len--;
/* allocate the memory for the sample */
- sample = alloc_libblock(samples, ID_SAMPLE, name + len);
+ sample = MEM_callocN(sizeof(bSample), "sample");
+ BLI_strncpy(sample->id.name+2, name+len, 20);
+ BLI_addtail(samples, sample); /* samples is ugly global */
+
sample->data = &sample->fakedata[0];
sample->type = SAMPLE_UNKNOWN;
/* find a sample that might already be loaded */
-bSample* sound_find_sample(bSound* sound)
+bSample *sound_find_sample(bSound *sound)
{
- bSample* sample;
+ bSample *sample;
char name[FILE_MAXDIR + FILE_MAXFILE];
char samplename[FILE_MAXDIR + FILE_MAXFILE];
/* search through the list of loaded samples */
sample = samples->first;
-
- while (sample)
- {
+ while (sample) {
strcpy(samplename, sample->name);
BLI_convertstringcode(samplename, G.sce, G.scene->r.cfra);
- if (strcmp(name, samplename) == 0)
- {
+ if (strcmp(name, samplename) == 0) {
break;
}
sample = sample->id.next;
-int sound_sample_is_null(bSound* sound)
+int sound_sample_is_null(bSound *sound)
{
int result = FALSE;
- bSample* sample;
+ bSample *sample;
if(ghSoundScene==NULL) sound_init_audio();
/* find the right sample or else create one */
- if (sound->sample == NULL)
- {
+ if (sound->sample == NULL) {
/* find... */
sample = sound_find_sample(sound);
-void sound_play_sound(bSound* sound)
+void sound_play_sound(bSound *sound)
{
#if GAMEBLENDER == 1
if(ghSoundScene==NULL) sound_init_audio();