Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenkernel/BKE_sound.h3
-rw-r--r--source/blender/blenkernel/intern/blender.c11
-rw-r--r--source/blender/blenkernel/intern/library.c19
-rw-r--r--source/blender/blenkernel/intern/sound.c20
-rw-r--r--source/blender/blenloader/intern/readblenentry.c24
-rw-r--r--source/blender/blenloader/intern/readfile.c59
-rw-r--r--source/blender/blenloader/intern/readfile.h5
-rw-r--r--source/blender/blenloader/intern/writefile.c34
-rw-r--r--source/blender/makesdna/DNA_ID.h7
-rw-r--r--source/blender/src/buttons_scene.c50
-rw-r--r--source/blender/src/editsound.c170
11 files changed, 205 insertions, 197 deletions
diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h
index e6634bc4a6a..0a747847b11 100644
--- a/source/blender/blenkernel/BKE_sound.h
+++ b/source/blender/blenkernel/BKE_sound.h
@@ -39,8 +39,11 @@ struct bSound;
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);
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index 570f993f542..bb5f25c6907 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -73,6 +73,7 @@
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_scene.h"
+#include "BKE_sound.h"
#include "BLI_editVert.h"
@@ -166,10 +167,14 @@ void pushpop_test()
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 */
@@ -336,7 +341,7 @@ static void setup_app_data(BlendFileData *bfd, char *filename)
lib_link_screen_restore(bfd->main, curscene);
}
- clear_global();
+ clear_global(); /* free Main database */
if(mode!='u') G.save_over = 1;
@@ -351,6 +356,9 @@ static void setup_app_data(BlendFileData *bfd, char *filename)
}
+ /* samples is a global list... */
+ sound_free_all_samples();
+
/* case G_FILE_NO_UI or no screens in file */
if(mode) {
G.curscreen= curscreen;
@@ -459,6 +467,7 @@ int BKE_read_file_from_memory(char* filebuf, int filelength, void *type_r)
return (bfd?1:0);
}
+/* memfile is the undo buffer */
int BKE_read_file_from_memfile(MemFile *memfile)
{
BlendReadError bre;
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index e6aa0208a5e..6038e70f6f2 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -184,9 +184,6 @@ ListBase *wich_libbase(Main *mainlib, short type)
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:
@@ -239,12 +236,10 @@ int set_listbasepointers(Main *main, ListBase **lb)
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 *****************
@@ -325,11 +320,8 @@ static ID *alloc_libblock_notest(short type)
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");
@@ -471,9 +463,6 @@ void free_libblock(ListBase *lb, void *idv)
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;
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index 2f31dbcaa80..3b14cb8adac 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -62,7 +62,25 @@ void sound_free_sample(bSample *sample)
}
}
-
+/* 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)
{
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index 17549485025..1e602285fc0 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -54,6 +54,7 @@
#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"
@@ -98,7 +99,6 @@ static IDType idtypes[]= {
{ 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},
@@ -289,16 +289,21 @@ BlendFileData *BLO_read_from_memory(void *mem, int memsize, BlendReadError *erro
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);
@@ -311,6 +316,19 @@ BlendFileData *BLO_read_from_memfile(const char *filename, MemFile *memfile, Ble
/* 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);
}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 547b5f016e7..79ea9cc5d81 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -320,7 +320,7 @@ static void *oldnewmap_lookup_and_inc(OldNewMap *onm, void *addr)
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;
@@ -438,22 +438,27 @@ static void split_libdata(ListBase *lb, Main *first)
}
}
-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 */
@@ -1031,9 +1036,8 @@ static void *newlibadr_us(FileData *fd, void *lib, void *adr) /* increases user
{
ID *id= newlibadr(fd, lib, adr);
- if(id) {
+ if(id)
id->us++;
- }
return id;
}
@@ -1122,6 +1126,23 @@ void blo_end_image_pointer_map(FileData *fd)
}
}
+/* 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 ****************** */
@@ -3804,7 +3825,6 @@ static char *dataname(short id_code)
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";
}
@@ -4915,8 +4935,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
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;
@@ -6179,17 +6198,15 @@ BlendFileData *blo_read_file_internal(FileData *fd, BlendReadError *error_r)
*/
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);
@@ -6966,11 +6983,8 @@ void BLO_script_library_append(BlendHandle *bh, char *dir, char *name, int idcod
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);
@@ -7030,11 +7044,8 @@ void BLO_library_append(SpaceFile *sfile, char *dir, int idcode)
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);
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index a0f42769762..fd7e5c0ee00 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -99,9 +99,9 @@ typedef struct BHeadN {
#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);
@@ -111,6 +111,7 @@ FileData *blo_openblendermemfile(struct MemFile *memfile, BlendReadError *error_
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);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 56adb3b732d..00c8fc86081 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1603,20 +1603,18 @@ static void write_libraries(WriteData *wd, Main *main)
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;
}
@@ -1625,20 +1623,13 @@ static void write_libraries(WriteData *wd, Main *main)
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;
}
}
@@ -1856,19 +1847,15 @@ static void write_global(WriteData *wd)
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);
@@ -1878,7 +1865,7 @@ static int write_file_handle(int handle, MemFile *compare, MemFile *current, int
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);
@@ -1901,7 +1888,8 @@ static int write_file_handle(int handle, MemFile *compare, MemFile *current, int
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) {
@@ -1927,7 +1915,7 @@ int BLO_write_file(char *dir, int write_flags, char **error_r)
{
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);
@@ -1941,10 +1929,10 @@ int BLO_write_file(char *dir, int write_flags, char **error_r)
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!!!
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index facd0b02db7..638a225bd21 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -147,7 +147,7 @@ typedef struct Library {
#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')
@@ -171,13 +171,11 @@ typedef struct Library {
#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')
@@ -189,6 +187,9 @@ typedef struct Library {
#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 */
diff --git a/source/blender/src/buttons_scene.c b/source/blender/src/buttons_scene.c
index 19e23f23377..770261c8280 100644
--- a/source/blender/src/buttons_scene.c
+++ b/source/blender/src/buttons_scene.c
@@ -188,11 +188,7 @@ void do_soundbuts(unsigned short event)
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));
@@ -348,13 +344,32 @@ static void sound_panel_sequencer(void)
}
+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;
@@ -388,27 +403,26 @@ static void sound_panel_sound(bSound *sound)
}
/* 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");
@@ -416,6 +430,7 @@ static void sound_panel_sound(bSound *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");
@@ -427,6 +442,7 @@ static void sound_panel_sound(bSound *sound)
/* 3D settings ------------------------------------------------------------------ */
+ uiBlockBeginAlign(block);
if (sound->sample->channels == 1) {
uiDefButBitI(block, TOG, SOUND_FLAGS_3D, B_SOUND_REDRAW, "3D Sound",
diff --git a/source/blender/src/editsound.c b/source/blender/src/editsound.c
index b1ec94d123b..bd209f2d39c 100644
--- a/source/blender/src/editsound.c
+++ b/source/blender/src/editsound.c
@@ -201,7 +201,7 @@ void winqreadsoundspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
void sound_initialize_sounds(void)
{
- bSound* sound;
+ bSound *sound;
if(ghSoundScene) {
@@ -212,8 +212,7 @@ void sound_initialize_sounds(void)
/* 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;
}
@@ -221,9 +220,9 @@ void sound_initialize_sounds(void)
-bSound* sound_make_copy(bSound* originalsound)
+bSound *sound_make_copy(bSound *originalsound)
{
- bSound* sound = NULL;
+ bSound *sound = NULL;
char name[160];
int len;
@@ -273,7 +272,7 @@ bSound* sound_make_copy(bSound* originalsound)
-void sound_initialize_sample(bSound* sound)
+void sound_initialize_sample(bSound *sound)
{
if(ghSoundScene==NULL) sound_init_audio();
@@ -282,7 +281,7 @@ void sound_initialize_sample(bSound* sound)
}
-void sound_read_wav_data(bSound* sound, PackedFile* pf)
+void sound_read_wav_data(bSound *sound, PackedFile *pf)
{
int i, temp;
short shortbuf, *temps;
@@ -299,36 +298,31 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
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;
}
@@ -356,8 +350,7 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
readPackedFile(pf, &shortbuf, 2);
readPackedFile(pf, &shortbuf, 2);
- if(G.order==B_ENDIAN)
- {
+ if(G.order==B_ENDIAN) {
SWITCH_SHORT(shortbuf);
}
bits = shortbuf;
@@ -365,8 +358,7 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
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;
@@ -379,13 +371,11 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
}
/* 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);
@@ -399,21 +389,17 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
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);
}
}
@@ -428,8 +414,7 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
}
}
}
- else
- {
+ else {
sound->sample->type = SAMPLE_INVALID;
if (G.f & G_DEBUG) printf("Unsupported sound format: %s\n", sound->name);
}
@@ -438,7 +423,7 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
/* 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;
@@ -447,22 +432,19 @@ static int sound_get_filetype_from_header(bSound* sound, PackedFile* pf)
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];
@@ -470,8 +452,7 @@ static int sound_get_filetype_from_header(bSound* sound, PackedFile* pf)
p_i[1]= s_i;
}
- if (shortbuf == SND_WAVE_FORMAT_PCM)
- {
+ if (shortbuf == SND_WAVE_FORMAT_PCM) {
filetype = SAMPLE_WAV;
}
else
@@ -500,17 +481,14 @@ static int sound_get_filetype_from_header(bSound* sound, PackedFile* pf)
#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);
}
@@ -520,7 +498,7 @@ static int sound_get_filetype_from_header(bSound* sound, PackedFile* pf)
-static int check_filetype(bSound* sound, PackedFile* pf)
+static int check_filetype(bSound *sound, PackedFile *pf)
{
// char* pdest;
sound->sample->type = SAMPLE_INVALID;
@@ -550,8 +528,7 @@ static int check_filetype(bSound* sound, PackedFile* pf)
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);
@@ -576,24 +553,22 @@ static int check_filetype(bSound* sound, PackedFile* 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 */
@@ -602,14 +577,12 @@ int sound_load_sample(bSound* sound)
}
/* 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);
@@ -628,33 +601,28 @@ int sound_load_sample(bSound* sound)
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;
}
@@ -663,7 +631,7 @@ int sound_load_sample(bSound* sound)
-bSound* sound_new_sound(char* name)
+bSound *sound_new_sound(char *name)
{
bSound *sound = NULL;
int len, file;
@@ -679,8 +647,7 @@ bSound* sound_new_sound(char* name)
/* check if the sample on disk can be opened */
file = open(str, O_BINARY|O_RDONLY);
- if (file != -1)
- {
+ if (file != -1) {
close(file);
@@ -699,8 +666,7 @@ bSound* sound_new_sound(char* name)
/* 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;
}
@@ -725,13 +691,8 @@ int sound_set_sample(bSound *sound, bSample *sample)
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;
}
@@ -740,22 +701,17 @@ int sound_set_sample(bSound *sound, bSample *sample)
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;
}
}
@@ -766,14 +722,13 @@ int sound_set_sample(bSound *sound, bSample *sample)
-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 */
@@ -781,7 +736,10 @@ bSample *sound_new_sample(bSound * sound)
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;
@@ -808,9 +766,9 @@ bSample *sound_new_sample(bSound * sound)
/* 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];
@@ -820,14 +778,11 @@ bSample* sound_find_sample(bSound* sound)
/* 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;
@@ -838,16 +793,15 @@ bSample* sound_find_sample(bSound* sound)
-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);
@@ -888,7 +842,7 @@ void sound_end_all_sounds(void)
-void sound_play_sound(bSound* sound)
+void sound_play_sound(bSound *sound)
{
#if GAMEBLENDER == 1
if(ghSoundScene==NULL) sound_init_audio();