home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
369b.lha
/
MED_v2.0
/
Source
/
medsrc
/
med-files.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-03
|
17KB
|
514 lines
/* MED-files.c: V2.00 file loading/saving routines by T. Kinnunen 1990 */
#include <workbench/icon.h>
#include <workbench/workbench.h>
#include <proto/icon.h>
#include "med.h"
static BPTR fh;
extern struct Gadget far gadget1[],far gadget2[];
extern struct Kappale far tamakappale;
extern UWORD lohkoja,soittimennum,nykyinenosio;
BOOL diskerr(),AskName();
extern struct Lohko *lohko[];
extern struct Soitin *soitin[];
extern struct Window *window;
extern struct Screen *screen;
extern char kappaleennimi[];
BOOL WriteIcon(),Continue();
#define M0F_LINEMSK0F 0x1
#define M0F_LINEMSK1F 0x2
#define M0F_FXMSK0F 0x4
#define M0F_FXMSK1F 0x8
#define M0F_LINEMSK00 0x10
#define M0F_LINEMSK10 0x20
#define M0F_FXMSK00 0x40
#define M0F_FXMSK10 0x80
static BOOL FWrite(char *ptr,long len)
{
return((BOOL)(Write(fh,ptr,len) != len));
}
static BOOL FRead(BPTR fh,char *ptr,long len)
{
return((BOOL)(Read(fh,ptr,len) != len));
}
static void PutNibble(UBYTE *mem,UWORD *nbnum,UBYTE nibble)
{
UBYTE *mloc = mem + (*nbnum / 2);
if(*nbnum & 0x1) *mloc |= (nibble & 0x0f);
else *mloc |= (nibble << 4);
(*nbnum)++;
}
static UBYTE GetNibble(UBYTE *mem,UWORD *nbnum)
{
UBYTE *mloc = mem + (*nbnum / 2),res;
if(*nbnum & 0x1) res = *mloc & 0x0f;
else res = *mloc >> 4;
(*nbnum)++;
return(res);
}
static void PutNibbles(UBYTE *mem,UWORD *nbnum,UWORD nbls,UBYTE nbs)
{
switch(nbs) {
case 0x4: PutNibble(mem,nbnum,(UBYTE)(nbls >> 12));
case 0x3: PutNibble(mem,nbnum,(UBYTE)(nbls >> 8));
case 0x2: PutNibble(mem,nbnum,(UBYTE)(nbls >> 4));
case 0x1: PutNibble(mem,nbnum,(UBYTE)nbls);
}
}
static UWORD GetNibbles(UBYTE *mem,UWORD *nbnum,UBYTE nbs)
{
UWORD res = 0;
while(nbs--) { res <<= 4; res |= GetNibble(mem,nbnum); }
return(res);
}
static BOOL SaveBlock(UWORD num)
{
UBYTE *tmpfr,trkn = lohko[num]->numtracks,m0fbits = 0;
UBYTE *conv = AllocMem(ONETRKSIZE * (trkn + 2),MEMF_PUBLIC|MEMF_CLEAR),
*from,lcnt,bcnt;
ULONG linemsk0 = 0,linemsk1 = 0,*lmptr = &linemsk0;
ULONG l2msk0 = 0,l2msk1 = 0,*l2ptr = &l2msk0;
UWORD lmsk0,lmsk1,ton = 0,data;
if(!conv) return(TRUE);
from = lohko[num]->music;
for(lcnt = 0; lcnt < 64; lcnt++) {
lmsk0 = lmsk1 = 0;
if(lcnt == 32) { lmptr = &linemsk1; l2ptr = &l2msk1; }
*lmptr <<= 1; *l2ptr <<= 1;
tmpfr = from;
for(bcnt = 0; bcnt < trkn; bcnt++) {
lmsk0 <<= 1; lmsk1 <<= 1;
if(*tmpfr || (*(tmpfr+1) & 0xf0)) lmsk0 |= 1;
if((*(tmpfr+1) & 0x0f) || *(tmpfr+2)) lmsk1 |= 1;
tmpfr += 3;
}
if(lmsk0) {
*lmptr |= 1;
PutNibbles(conv,&ton,lmsk0,(UBYTE)(trkn / 4));
tmpfr = from;
for(bcnt = 0; bcnt < trkn; bcnt++) {
if(*tmpfr || (*(tmpfr+1) & 0xf0)) {
data = (UWORD)((*tmpfr << 4) |
((*(tmpfr+1) & 0xf0) >> 4));
PutNibbles(conv,&ton,data,3);
}
tmpfr += 3;
}
}
if(lmsk1) {
*l2ptr |= 1;
PutNibbles(conv,&ton,lmsk1,(UBYTE)(trkn / 4));
tmpfr = from + 1;
for(bcnt = 0; bcnt < trkn; bcnt++) {
if((*tmpfr & 0x0f) || *(tmpfr+1)) {
data = (UWORD)(((*tmpfr & 0x0f)
<< 8) | (*(tmpfr+1)));
PutNibbles(conv,&ton,data,3);
}
tmpfr += 3;
}
}
from += 3 * trkn;
}
if(FWrite((char *)(&lohko[num]->numtracks),1)) goto sberr;
data = (ton + 1) / 2; /* length of the packed block */
if(linemsk0 == 0xffffffff) m0fbits |= M0F_LINEMSK0F;
else if(linemsk0 == 0x00000000) m0fbits |= M0F_LINEMSK00;
if(linemsk1 == 0xffffffff) m0fbits |= M0F_LINEMSK1F;
else if(linemsk1 == 0x00000000) m0fbits |= M0F_LINEMSK10;
if(l2msk0 == 0xffffffff) m0fbits |= M0F_FXMSK0F;
else if(l2msk0 == 0x00000000) m0fbits |= M0F_FXMSK00;
if(l2msk1 == 0xffffffff) m0fbits |= M0F_FXMSK1F;
else if(l2msk1 == 0x00000000) m0fbits |= M0F_FXMSK10;
if(FWrite((char *)(&m0fbits),1)) goto sberr;
if(FWrite((char *)(&data),2)) goto sberr;
if(!(m0fbits & (M0F_LINEMSK00 | M0F_LINEMSK0F)))
if(FWrite((char *)(&linemsk0),4)) goto sberr;
if(!(m0fbits & (M0F_LINEMSK10 | M0F_LINEMSK1F)))
if(FWrite((char *)(&linemsk1),4)) goto sberr;
if(!(m0fbits & (M0F_FXMSK00 | M0F_FXMSK0F)))
if(FWrite((char *)(&l2msk0),4)) goto sberr;
if(!(m0fbits & (M0F_FXMSK10 | M0F_FXMSK1F)))
if(FWrite((char *)(&l2msk1),4)) goto sberr;
if(FWrite(conv,data)) goto sberr;
FreeMem(conv,ONETRKSIZE * (trkn + 2));
return(FALSE);
sberr: FreeMem(conv,ONETRKSIZE * (trkn + 2));
return(TRUE);
}
static void UnpackBlock(UWORD bnum,UBYTE *from)
{
UBYTE *to = lohko[bnum]->music,lcnt,trkn = lohko[bnum]->numtracks;
ULONG linemsk0 = *((ULONG *)from),linemsk1 = *((ULONG *)from + 1);
ULONG fxmsk0 = *((ULONG *)from + 2),fxmsk1 = *((ULONG *)from + 3);
ULONG *lmptr = &linemsk0,*fxptr = &fxmsk0;
UWORD fromn = 0,lmsk;
UBYTE *fromst = from + 16,bcnt,*tmpto;
from += 16;
for(lcnt = 0; lcnt < 64; lcnt++) {
if(lcnt == 32) { lmptr = &linemsk1; fxptr = &fxmsk1; }
if(*lmptr & 0x80000000) {
lmsk = GetNibbles(fromst,&fromn,(UBYTE)(trkn / 4));
lmsk <<= (16 - trkn);
tmpto = to;
for(bcnt = 0; bcnt < trkn; bcnt++) {
if(lmsk & 0x8000) {
*tmpto = (UBYTE)GetNibbles(fromst,
&fromn,2);
*(tmpto+1) = (GetNibble(fromst,
&fromn) << 4);
}
lmsk <<= 1; tmpto += 3;
}
}
if(*fxptr & 0x80000000) {
lmsk = GetNibbles(fromst,&fromn,(UBYTE)(trkn / 4));
lmsk <<= (16 - trkn);
tmpto = to;
for(bcnt = 0; bcnt < trkn; bcnt++) {
if(lmsk & 0x8000) {
*(tmpto+1) |= GetNibble(fromst,
&fromn);
*(tmpto+2) = (UBYTE)GetNibbles(
fromst,&fromn,2);
}
lmsk <<= 1; tmpto += 3;
}
}
to += 3 * trkn;
*lmptr <<= 1; *fxptr <<= 1;
}
}
BOOL SaveInstruments(BPTR fh)
{
ULONG imsk = 0;
UBYTE scnt;
Ilmoita("Saving samples...");
for(scnt = 0; scnt < 32; scnt++) {
imsk <<= 1;
if(soitin[scnt]) imsk |= 1;
}
if(FWrite((char *)(&imsk),4)) return(diskerr(fh,0));
for(scnt = 0; scnt < 32; scnt++) {
if(soitin[scnt] && FWrite((char *)soitin[scnt],
soitin[scnt]->length + sizeof(struct Soitin)))
return(diskerr(fh,0));
}
return(FALSE);
}
BOOL SaveSong(char *name,BOOL sinstr)
{
UBYTE scnt,oldexists = 0;
ULONG zmsk0 = 0,zmsk1 = 0,zmsk2 = 0,zmsk3 = 0,zmsk4 = 0;
extern struct ViewPort *vp;
if(*name == '\0') return(AskName());
if(IsHere(name)) {
Ilmoita("File already exists. Continue?");
oldexists = 1;
if(!Continue()) return(TRUE);
}
if(sinstr) tamakappale.liput |= LIPPU_SOITTIMETMUKANA;
else tamakappale.liput &= ~LIPPU_SOITTIMETMUKANA;
fh = Open2(name,MODE_NEWFILE);
if(!fh) return(diskerr(fh,0));
Ilmoita("Saving song...");
for(scnt = 0; scnt < 8; scnt++)
tamakappale.rgb[scnt] = GetRGB4(vp->ColorMap,scnt);
if(FWrite("MED\x03",4)) return(diskerr(fh,0));
for(scnt = 0; scnt < 32; scnt++) {
zmsk0 <<= 1; zmsk1 <<= 1; zmsk2 <<= 1; zmsk3 <<= 1;
zmsk4 <<= 1;
if(FWrite(tamakappale.soitin[scnt],strlen(tamakappale.
soitin[scnt]) + 1)) return(diskerr(fh,0));
if(tamakappale.soittimenvoimakkuus[scnt]) zmsk0 |= 1;
if(tamakappale.stoisto[scnt]) zmsk1 |= 1;
if(tamakappale.stoistonpit[scnt]) zmsk2 |= 1;
if(tamakappale.midikanava[scnt]) zmsk3 |= 1;
if(tamakappale.midipreset[scnt]) zmsk4 |= 1;
}
if(FWrite((char *)(&zmsk0),4)) return(diskerr(fh,0));
for(scnt = 0; scnt < 32; scnt++) {
if(!tamakappale.soittimenvoimakkuus[scnt]) continue;
if(FWrite(&tamakappale.soittimenvoimakkuus[scnt],1)) return(diskerr(fh,0));
}
if(FWrite((char *)(&zmsk1),4)) return(diskerr(fh,0));
for(scnt = 0; scnt < 32; scnt++) {
if(!tamakappale.stoisto[scnt]) continue;
if(FWrite((char *)(&tamakappale.stoisto[scnt]),2)) return(diskerr(fh,0));
}
if(FWrite((char *)(&zmsk2),4)) return(diskerr(fh,0));
for(scnt = 0; scnt < 32; scnt++) {
if(!tamakappale.stoistonpit[scnt]) continue;
if(FWrite((char *)(&tamakappale.stoistonpit[scnt]),2)) return(diskerr(fh,0));
}
if(FWrite((char *)(&lohkoja),2)) return(diskerr(fh,0));
if(FWrite((char *)(&tamakappale.kappaleen_pituus),2)) return(diskerr(fh,0));
if(FWrite(tamakappale.soittojarjestys,tamakappale.kappaleen_pituus)) return(diskerr(fh,0));
if(FWrite((char *)(&tamakappale.tempo),26)) return(diskerr(fh,0));
if(FWrite((char *)(&zmsk3),4)) return(diskerr(fh,0));
for(scnt = 0; scnt < 32; scnt++) {
if(!tamakappale.midikanava[scnt]) continue;
if(FWrite(&tamakappale.midikanava[scnt],1)) return(diskerr(fh,0));
}
if(FWrite((char *)(&zmsk4),4)) return(diskerr(fh,0));
for(scnt = 0; scnt < 32; scnt++) {
if(!tamakappale.midipreset[scnt]) continue;
if(FWrite(&tamakappale.midipreset[scnt],1)) return(diskerr(fh,0));
}
for(scnt = 0; scnt < lohkoja; scnt++)
if(SaveBlock((UWORD)scnt)) return(diskerr(fh,0));
if(sinstr) SaveInstruments(fh);
Close(fh);
if(!oldexists) InsertSavedFile(name);
if(gadget2[25].GadgetID & 0x1000) {
Ilmoita("Creating icon...");
if(WriteIcon(name)) return(FALSE);
}
Ilmoita("Song is now saved.");
return(FALSE);
}
BOOL Load200Song(BPTR fh)
{
ULONG zmsk,*conv = 0;
UWORD convsz;
UBYTE scnt,*nameptr,blkcnt,midifound = 0;
Ilmoita("Loading MED2.00-song...");
if(FRead(fh,(char *)(&zmsk),4)) return(diskerr(fh,0)); /* MED\x03 */
for(scnt = 0; scnt < 32; scnt++) {
nameptr = &tamakappale.soitin[scnt][0];
for(;;) {
if(FRead(fh,nameptr,1)) return(diskerr(fh,0));
if(*nameptr++ == '\0') break;
}
}
if(FRead(fh,(char *)(&zmsk),4)) return(diskerr(fh,0));
for(scnt = 0; scnt < 32; scnt++) {
if(zmsk & 0x80000000) {
if(FRead(fh,&tamakappale.soittimenvoimakkuus[scnt],1)) return(diskerr(fh,0));
} else tamakappale.soittimenvoimakkuus[scnt] = 0;
zmsk <<= 1;
}
if(FRead(fh,(char *)(&zmsk),4)) return(diskerr(fh,0));
for(scnt = 0; scnt < 32; scnt++) {
if(zmsk & 0x80000000) {
if(FRead(fh,(char *)(&tamakappale.stoisto[scnt]),2)) return(diskerr(fh,0));
} else tamakappale.stoisto[scnt] = 0;
zmsk <<= 1;
}
if(FRead(fh,(char *)(&zmsk),4)) return(diskerr(fh,0));
for(scnt = 0; scnt < 32; scnt++) {
if(zmsk & 0x80000000) {
if(FRead(fh,(char *)(&tamakappale.stoistonpit[scnt]),2)) return(diskerr(fh,0));
} else tamakappale.stoistonpit[scnt] = 0;
zmsk <<= 1;
}
if(FRead(fh,(char *)(&tamakappale.lohkoja),2)) return(diskerr(fh,0));
if(FRead(fh,(char *)(&tamakappale.kappaleen_pituus),2)) return(diskerr(fh,0));
if(FRead(fh,tamakappale.soittojarjestys,tamakappale.kappaleen_pituus)) return(diskerr(fh,0));
if(FRead(fh,(char *)(&tamakappale.tempo),26)) return(diskerr(fh,0));
if(FRead(fh,(char *)(&zmsk),4)) return(diskerr(fh,0));
for(scnt = 0; scnt < 32; scnt++) {
if(zmsk & 0x80000000) {
if(FRead(fh,&tamakappale.midikanava[scnt],1)) return(diskerr(fh,0));
midifound = 1;
} else tamakappale.midikanava[scnt] = 0;
zmsk <<= 1;
}
if(FRead(fh,(char *)(&zmsk),4)) return(diskerr(fh,0));
for(scnt = 0; scnt < 32; scnt++) {
if(zmsk & 0x80000000) {
if(FRead(fh,&tamakappale.midipreset[scnt],1)) return(diskerr(fh,0));
} else tamakappale.midipreset[scnt] = 0;
zmsk <<= 1;
}
lohkoja = 0;
for(blkcnt = 0; blkcnt < tamakappale.lohkoja; blkcnt++) {
if(FRead(fh,&scnt,1)) return(diskerr(fh,0));
if(AllocBlock(blkcnt,scnt)) return(diskerr(fh,"No mem."));
lohkoja++;
if(FRead(fh,&scnt,1)) return(diskerr(fh,0));
if(FRead(fh,(char *)(&convsz),2)) return(diskerr(fh,0));
if(!(conv = AllocMem(convsz+16,MEMF_PUBLIC|MEMF_CLEAR))) return(diskerr(fh,"Memory..."));
if(scnt & M0F_LINEMSK00) *conv = 0L;
else if(scnt & M0F_LINEMSK0F) *conv = 0xffffffff;
else if(FRead(fh,(UBYTE *)conv,4)) return(diskerr(fh,0));
if(scnt & M0F_LINEMSK10) *(conv+1) = 0L;
else if(scnt & M0F_LINEMSK1F) *(conv+1) = 0xffffffff;
else if(FRead(fh,(UBYTE *)(conv + 1),4)) return(diskerr(fh,0));
if(scnt & M0F_FXMSK00) *(conv+2) = 0L;
else if(scnt & M0F_FXMSK0F) *(conv+2) = 0xffffffff;
else if(FRead(fh,(UBYTE *)(conv + 2),4)) return(diskerr(fh,0));
if(scnt & M0F_FXMSK10) *(conv+3) = 0L;
else if(scnt & M0F_FXMSK1F) *(conv+3) = 0xffffffff;
else if(FRead(fh,(UBYTE *)(conv + 3),4)) return(diskerr(fh,0));
if(FRead(fh,(UBYTE *)(conv + 4),convsz)) return(diskerr(fh,0));
UnpackBlock((UWORD)blkcnt,(UBYTE *)conv);
FreeMem(conv,convsz+16); conv = 0;
}
if(midifound) MIDIon();
return(FALSE);
}
static UWORD chip icondata[] = {
0xffff,0xffff,0xff80,0xc000,0x0,0x180,0xc020,0xbfbe,0x180,0xc031,0x999b,0x180,
0xc03b,0x9819,0x8180,0xc03f,0x9e19,0x8180,0xc035,0x9819,0x8180,0xc031,0x999b,0x180,
0xc031,0xbfbe,0x180,0xc3c0,0x0,0x180,0xc660,0x0,0x180,0xc703,0xc7c3,0xb180,
0xc386,0x6666,0x6180,0xc0e6,0x6666,0x6180,0xc666,0x6663,0xc180,0xc3c3,0xc66c,0x6180,
0xc000,0x7,0xc180,0xc000,0x0,0x180,0xc000,0x0,0x180,0xffff,0xffff,0xff80,
0x0,0x0,0x0, /*------ plane # 1: --------*/
0x0,0x0,0x0,0x3fff,0xffff,0xfe60,0x3020,0xbfbe,0x60,0x3039,0xbfff,0x8060,
0x303f,0xfe7f,0xc060,0x303f,0xfe1f,0xe060,0x303f,0xff9f,0xe060,0x303d,0xff9f,0x6060,
0x303d,0xfffe,0xc060,0x33cc,0x6fef,0x8060,0x36f0,0x0,0x60,0x379b,0xc7c3,0xb060,
0x33c6,0xf7f6,0xec60,0x30e7,0xffff,0xf860,0x367f,0xfffb,0xd860,0x33db,0xdffc,0xf060,
0x30f0,0xf19f,0xd860,0x3000,0x1,0xf060,0x3000,0x0,0x60,0x0,0x0,0x60,
0x3fff,0xffff,0xffe0 };
BOOL WriteIcon(char *name)
{
static struct Image dimg = {
0,0,43,21,2,icondata,0x3,0x0,NULL };
static struct DiskObject dobj = {
WB_DISKMAGIC,WB_DISKVERSION,{
NULL,0,0,43,21,GADGIMAGE|GADGHCOMP,
GADGIMMEDIATE|RELVERIFY,BOOLGADGET,(APTR)&dimg,
NULL,NULL,NULL,NULL,0,NULL
},WBPROJECT,"MEDPlayer",NULL,NO_ICON_POSITION,
NO_ICON_POSITION,NULL,NULL,NULL
}; /* vv - This wouldn't work without <proto/icon.h> */
struct Library *IconBase = OpenLibrary(ICONNAME,0);
LONG status;
if(!IconBase) {
Ilmoita("No icon.library: no icon.");
return(TRUE);
}
status = PutDiskObject(name,&dobj);
CloseLibrary(IconBase);
if(!status) {
Ilmoita("Failed to create icon.");
return(TRUE);
}
return(FALSE);
}
static UWORD chip contdata[] = {
0x7fff,0xffff,0xffff,0xffff,0x3fff,0xffff,0xffff,0xffff,0x3fff,0xffff,0xffff,0xffff,
0x3fff,0xffff,0xffff,0xffff,0x2000,0x0,0x80,0x7,0x3fff,0xffff,0xfeff,0xfff7,
0x3ccd,0xa2b5,0xa2f2,0x3337,0x3bb4,0xb695,0xaeef,0x6d57,0x3bb5,0x36a5,0xa6f3,0x6d37,
0x3bb5,0xb6b5,0xaefd,0x6d77,0x3ccd,0xb6b6,0x62e3,0x7377,0x3fff,0xffff,0xfeff,0xfff7,
0x3fff,0xffff,0xfeff,0xfff7,0x3fff,0xffff,0xffff,0xffff,0x3fff,0xffff,0xffff,0xffff,
0x0,0x0,0x0,0x3,0x0,0x0,0x0,0x1, /*------ plane # 1: --------*/
0x8000,0x0,0x0,0x0,0xc000,0x0,0x0,0x0,0xffff,0xffff,0xffff,0xfffc,
0xffff,0xffff,0xffff,0xfffc,0xffff,0xffff,0xffff,0xfffc,0xefff,0xffff,0xffbf,0xfffc,
0xeccd,0xa2b5,0xa3b2,0x333c,0xebb4,0xb695,0xafaf,0x6d5c,0xebb5,0x36a5,0xa7b3,0x6d3c,
0xebb5,0xb6b5,0xafbd,0x6d7c,0xeccd,0xb6b6,0x63a3,0x737c,0xefff,0xffff,0xffbf,0xfffc,
0xe000,0x0,0x180,0xc,0xffff,0xffff,0xffff,0xfffc,0xffff,0xffff,0xffff,0xfffc,
0xffff,0xffff,0xffff,0xfffc,0xffff,0xffff,0xffff,0xfffe };
BOOL Continue()
{
static struct Image contimg = { 0,0,64,17,2,contdata,0x3,0x0,NULL };
static struct Gadget cgadg[] = {
{ &cgadg[1],4,5,35,7,GADGHCOMP,RELVERIFY,BOOLGADGET,NULL,NULL,
NULL,NULL,NULL,0,NULL },
{ NULL,42,5,18,7,GADGHCOMP,RELVERIFY,BOOLGADGET,NULL,NULL,
NULL,NULL,NULL,0,NULL } };
static struct NewWindow cneww = { 160,20,64,17,0,0,GADGETUP|RAWKEY,
SMART_REFRESH|BORDERLESS|ACTIVATE|RMBTRAP,&cgadg[0],
NULL,NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN };
struct Window *cwin;
struct IntuiMessage *msg;
UWORD res = 0;
cneww.Screen = screen;
if(!(cwin = OpenWindow(&cneww))) return(FALSE);
DrawImage(cwin->RPort,&contimg,0,0);
for(;;) {
WaitPort(cwin->UserPort);
msg = (struct IntuiMessage *)GetMsg(cwin->UserPort);
if(msg->Class == GADGETUP) {
if(msg->IAddress == (APTR)&cgadg[0]) res = 1;
else res = 2;
} else if(msg->Class == RAWKEY) {
if(msg->Code == 0x33) res = 1;
else if(msg->Code == 0x21) res = 2;
}
ReplyMsg((struct Message *)msg);
if(res) break;
}
CloseWindow(cwin);
if(res == 1) return(TRUE);
return(FALSE);
}
BOOL AskName()
{
Ilmoita("Type in the name:");
OsionValinta(&gadget1[0]);
ActivateGadget(&gadget2[9],window,NULL);
return(TRUE);
}
BOOL LoadAttachedInstrs(BPTR fh)
{
ULONG imsk;
struct Soitin loaded;
if(FRead(fh,(char *)(&imsk),4)) return(diskerr(0,0));
soittimennum = 0;
while(soittimennum < 31) {
imsk <<= 1; /* There's no instrument #0 */
SeurSoitin();
if(imsk & 0x80000000) {
if(FRead(fh,(char *)(&loaded),sizeof(struct Soitin)))
return(diskerr(0,0));
if(NewInstrument(loaded.length,soittimennum))
return(diskerr(0,"Help...no memory!!!"));
soitin[soittimennum]->type = loaded.type;
if(FRead(fh,((char *)soitin[soittimennum]) +
sizeof(struct Soitin),loaded.length))
return(diskerr(0,0));
}
}
return(FALSE);
}
BOOL SaveRawSample(char *name)
{
UBYTE oldexists = 0;
if(!soitin[soittimennum]) {
Ilmoita("There's no sample to save!!");
return(TRUE);
}
if(*name == '\0') {
UWORD pos;
if(nykyinenosio == 2) pos = RemoveGadget(window,&gadget2[9]);
strcpy(kappaleennimi,tamakappale.soitin[soittimennum]);
if(nykyinenosio == 2) {
AddGadget(window,&gadget2[9],pos);
RefreshGList(&gadget2[9],window,NULL,1);
}
return(TRUE);
}
if(IsHere(name)) {
Ilmoita("File already exists. Continue?");
oldexists = 1;
if(!Continue()) return(TRUE);
}
if(!(fh = Open2(name,MODE_NEWFILE))) return(diskerr(0,0));
if(FWrite(((char *)(soitin[soittimennum])) + sizeof(struct Soitin),
soitin[soittimennum]->length & 0xfffffffe)) return(diskerr(fh,0));
Close(fh);
if(!oldexists) InsertSavedFile(name);
Ilmoita("Sample is now saved.");
return(FALSE);
}