home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Audio 4.94 - Over 11,000 Files
/
audio-11000.iso
/
amiga
/
midi
/
med210.lhw
/
in.adf
/
Source
/
med210src.lzh
/
med-files.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-17
|
24KB
|
762 lines
/* MED - music editor ⌐ 1989, 1990 by Teijo Kinnunen */
/* MED-files.c: some file loading/saving routines */
#include <workbench/icon.h>
#include <workbench/workbench.h>
#include <proto/icon.h>
#include "med.h"
#include "medproto.h"
extern BPTR fh;
extern struct Gadget far gadget1[],far gadget2[];
extern struct Kappale far song;
extern UBYTE blocks,samplenum;
extern UWORD nykyinenosio;
extern struct Lohko *lohko[];
extern struct Soitin *sample[];
extern struct Window *window;
extern struct Screen *screen;
extern char kappaleennimi[];
#define HLMSK0ZERO 0x1
#define HLMSK1ZERO 0x2
#define HLMSK2ZERO 0x4
#define HLMSK3ZERO 0x8
struct SCMask { /* finally, something use for bit fields!! */
unsigned free0 : 1;
unsigned strans0 : 1;
unsigned svol64 : 1;
unsigned svol0 : 1;
unsigned midipres0 : 1;
unsigned midich0 : 1;
unsigned replen0 : 1;
unsigned rep0 : 1;
unsigned free1 : 2;
unsigned snamelen : 6;
};
static BOOL __regargs FWrite(char *,long);
static BOOL __regargs FRead(char *,long);
static void __regargs PutNibble(UBYTE *,UWORD *,UBYTE);
static UBYTE __regargs GetNibble(UBYTE *,UWORD *);
static void __regargs PutNibbles(UBYTE *,UWORD *,UWORD,UBYTE);
static UWORD __regargs GetNibbles(UBYTE *,UWORD *,UBYTE);
static BOOL __regargs SaveBlock(UWORD);
static void __regargs UnpackData(ULONG *,ULONG *,UBYTE *,UBYTE *,UWORD,UBYTE);
static char * __regargs Read200Block(UBYTE);
static char * __regargs Read210Block(UBYTE);
static char * __regargs LoadBlocks(BOOL);
static BOOL __regargs FWrite(char *ptr,long len)
{
return((BOOL)(Write(fh,ptr,len) != len));
}
static BOOL __regargs FRead(char *ptr,long len)
{
return((BOOL)(Read(fh,ptr,len) != len));
}
static void __regargs 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 __regargs 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 __regargs 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 __regargs GetNibbles(UBYTE *mem,UWORD *nbnum,UBYTE nbs)
{
UWORD res = 0;
while(nbs--) { res <<= 4; res |= GetNibble(mem,nbnum); }
return(res);
}
/* MED File Format (V2.10) -- block header:
UBYTE header size length of the remaining part of header
UBYTE numtracks (number of tracks in this block [4,8,12,16])
UBYTE lines lines in this block (default = 63)
UWORD blocklen length of the packed block (in bytes)
UBYTE lmskmsks[1..4] masks for linemasks (if they're 0xffff.. or 0L)
ULONG linemasks[0..8] the masks for lines (first linemsk, then cmdmsk)
UBYTE hlmaskmsk mask for highlightmasks
ULONG hlmask[0..4] masks for line highlighting
Note: longwords/words are fetched nibble at a time, no alignment needed
and finally the packed block:
if the line mask is for example,
10000010001011000000000000001000001000010000000010000001000000
| | |
there are notes in line 0,6,10 etc. (bit is 1), if bit is 0 the notes of the
line will be filled with zeros.
Effect (command) mask works in the same way.
line:
first a nibble (when there are only 4 tracks)
0101
| |
there are notes in tracks 1 and 3. If the numbers of the notes were 0x12
and 0x22, and sample numbers would be 0xF and 0x7, the data for one line
would look like (hex): 512F227
bin 0101 = hex 5 ----^
simple, isn't it?? (No!!) */
static BOOL __regargs SaveBlock(UWORD num)
{
UBYTE *tmpfr,trkn = lohko[num]->numtracks,hlbits = 0;
UWORD lmsk0,lmsk1,ton = 0,data,hdr[40],hdrnn = 0,lcnt;
UBYTE *conv = AllocMem(3 * (lohko[num]->lines + 1) * (trkn + 2),MEMF_PUBLIC|MEMF_CLEAR),
*from,bcnt,*hdrs = (UBYTE *)hdr,hdrsz;
ULONG linemsk[8] = { 0 },*lmptr = &linemsk[0];
ULONG cmdmsk[8] = { 0 },*cmptr = &cmdmsk[0];
if(!conv) return(TRUE);
from = lohko[num]->music;
for(lcnt = 0; lcnt < lohko[num]->lines + 1; lcnt++) {
lmsk0 = lmsk1 = 0;
if(!(lcnt % 32)) { /* we need new mask lw */
lmptr = &linemsk[lcnt / 32];
cmptr = &cmdmsk[lcnt / 32];
}
*lmptr <<= 1; *cmptr <<= 1; /* shift left masks */
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) {
*cmptr |= 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;
}
for(lcnt = lohko[num]->lines + 1; lcnt % 32; lcnt++) {
*lmptr <<= 1; *cmptr <<= 1;
}
memset((void *)hdr,0,80);
hdrnn = 2; /* leave 1 byte for header size */
PutNibbles(hdrs,&hdrnn,(UWORD)(lohko[num]->numtracks),2);
PutNibbles(hdrs,&hdrnn,(UWORD)(lohko[num]->lines),2);
PutNibbles(hdrs,&hdrnn,(UWORD)((ton + 1) / 2),4); /* len of packed data */
bcnt = (lohko[num]->lines /á32) + 1; /* # of masks */
data = 0;
for(lcnt = 0; lcnt < bcnt; lcnt++) {
if(linemsk[lcnt] == 0xffffffff) data |= 8;
else if(linemsk[lcnt] == 0x00000000) data |= 4;
if(cmdmsk[lcnt] == 0xffffffff) data |= 2;
else if(cmdmsk[lcnt] == 0x00000000) data |= 1;
PutNibble(hdrs,&hdrnn,(UBYTE)data);
data = 0;
}
if(bcnt & 0x1) PutNibble(hdrs,&hdrnn,(UBYTE)data); /* zero */
for(lcnt = 0; lcnt < bcnt; lcnt++) {
if(linemsk[lcnt] != 0xffffffff && linemsk[lcnt] != 0L) {
PutNibbles(hdrs,&hdrnn,(UWORD)(linemsk[lcnt] >> 16),4);
PutNibbles(hdrs,&hdrnn,(UWORD)(linemsk[lcnt] & 0xffff),4);
}
if(cmdmsk[lcnt] != 0xffffffff && cmdmsk[lcnt] != 0L) {
PutNibbles(hdrs,&hdrnn,(UWORD)(cmdmsk[lcnt] >> 16),4);
PutNibbles(hdrs,&hdrnn,(UWORD)(cmdmsk[lcnt] & 0xffff),4);
}
}
for(lcnt = 0; lcnt < 8; lcnt++)
if(!lohko[num]->hlmask[lcnt]) hlbits |= 0x80 >> lcnt;
PutNibbles(hdrs,&hdrnn,(UWORD)hlbits,2);
for(lcnt = 0; lcnt < 8; lcnt++) {
ULONG msk = lohko[num]->hlmask[lcnt];
if(msk) {
PutNibbles(hdrs,&hdrnn,(UWORD)(msk >> 16),4);
PutNibbles(hdrs,&hdrnn,(UWORD)(msk & 0xffff),4);
}
}
hdrsz = hdrnn /á2;
hdrnn = 0;
PutNibbles(hdrs,&hdrnn,(UWORD)(hdrsz - 1),2);
if(FWrite((char *)hdrs,hdrsz)) goto sberr;
if(FWrite(conv,(ton + 1) / 2)) goto sberr;
FreeMem(conv,3 * (lohko[num]->lines + 1) * (trkn + 2));
return(FALSE);
sberr: FreeMem(conv,3 * (lohko[num]->lines + 1) * (trkn + 2));
return(TRUE);
}
static void __regargs UnpackData(ULONG *lmptr,ULONG *cmptr,UBYTE *from,UBYTE *to,UWORD lines,UBYTE trkn)
{
UBYTE *fromst = from,*tmpto,bcnt;
UWORD fromn = 0,lmsk,lcnt;
for(lcnt = 0; lcnt < lines; lcnt++) {
if(!(lcnt % 32) && lcnt) { lmptr++; cmptr++; }
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(*cmptr & 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; *cmptr <<= 1;
}
}
static char * __regargs Read210Block(UBYTE num)
{
UBYTE hdrsz,hdr[80],trks,lines,mskmsks[8],msks,msk2,msk3 = 0,*conv = 0L;
UWORD hdrsn = 0,convsz;
ULONG lmsk[8],cmmsk[8];
if(FRead(&hdrsz,1)) return(DISKERR);
if(FRead(hdr,hdrsz)) return(DISKERR);
trks = GetNibbles(hdr,&hdrsn,2);
lines = GetNibbles(hdr,&hdrsn,2);
if(AllocBlock((UWORD)num,trks,(UWORD)((UWORD)lines + 1))) return(nomem);
convsz = GetNibbles(hdr,&hdrsn,4);
if(convsz && !(conv = AllocMem(convsz,MEMF_CLEAR))) return(nomem);
msk2 = msks = (lines /á32) + 1; /* # of masks */
while(msks--) mskmsks[msk3++] = GetNibble(hdr,&hdrsn);
if(msk2 & 0x1) (void)GetNibble(hdr,&hdrsn); /* empty */
for(msks = 0; msks < msk2; msks++) {
if(mskmsks[msks] & 8) lmsk[msks] = 0xffffffff;
else if(mskmsks[msks] & 4) lmsk[msks] = 0L;
else lmsk[msks] = (GetNibbles(hdr,&hdrsn,4) << 16) |
GetNibbles(hdr,&hdrsn,4);
if(mskmsks[msks] & 2) cmmsk[msks] = 0xffffffff;
else if(mskmsks[msks] & 1) cmmsk[msks] = 0L;
else cmmsk[msks] = (GetNibbles(hdr,&hdrsn,4) << 16) |
GetNibbles(hdr,&hdrsn,4);
}
msk3 = GetNibbles(hdr,&hdrsn,2);
for(msks = 0; msks < 8; msks++) {
if(msk3 & 0x80) lohko[num]->hlmask[msks] = 0L;
else lohko[num]->hlmask[msks] = (GetNibbles(hdr,&hdrsn,4)
<< 16) | GetNibbles(hdr,&hdrsn,4);
msk3 <<= 1;
}
if(FRead(conv,convsz)) return(DISKERR);
UnpackData(lmsk,cmmsk,conv,lohko[num]->music,(UWORD)(lines + 1),trks);
if(conv) FreeMem(conv,convsz);
return(NOERR);
}
static char * __regargs Read200Block(UBYTE num)
{
ULONG lmsk[2],cmdmsk[2];
UWORD convsz;
UBYTE *conv,trks,mask;
if(FRead(&trks,1)) return(DISKERR);
if(AllocBlock((UWORD)num,trks,64)) return(nomem);
if(FRead(&mask,1)) return(DISKERR);
if(FRead((char *)(&convsz),2)) return(DISKERR);
if(mask & 0x10) lmsk[0] = 0L;
else if(mask & 0x1) lmsk[0] = 0xffffffff;
else if(FRead((UBYTE *)lmsk,4)) return(DISKERR);
if(mask & 0x20) lmsk[1] = 0L;
else if(mask & 2) lmsk[1] = 0xffffffff;
else if(FRead((UBYTE *)(&lmsk[1]),4)) return(DISKERR);
if(mask & 0x40) cmdmsk[0] = 0L;
else if(mask & 0x4) cmdmsk[0] = 0xffffffff;
else if(FRead((UBYTE *)cmdmsk,4)) return(DISKERR);
if(mask & 0x80) cmdmsk[1] = 0L;
else if(mask & 0x8) cmdmsk[1] = 0xffffffff;
else if(FRead((UBYTE *)(&cmdmsk[1]),4)) return(DISKERR);
conv = 0;
if(convsz) {
if(!(conv = AllocMem(convsz,MEMF_CLEAR))) return(nomem);
if(FRead(conv,convsz)) {
FreeMem(conv,convsz);
return(DISKERR);
}
} /* if convsz = 0, this block is empty, just pass "mask" (dummy) */
UnpackData(lmsk,cmdmsk,conv ? conv : &mask,lohko[num]->music,64,trks);
if(conv) FreeMem(conv,convsz);
return(NOERR);
}
static char * __regargs LoadBlocks(BOOL v210)
{
UBYTE blkcnt;
char *res;
blocks = 0;
for(blkcnt = 0; blkcnt < song.numblocks; blkcnt++) {
if(v210) res = Read210Block(blkcnt);
else res = Read200Block(blkcnt);
if(lohko[blocks]) blocks++;
TulostaLohkoJaSoitin();
if(res) return(res);
}
return(NOERR);
}
char *SaveInstruments()
{
ULONG imsk[2] = { 0,0 },*mskptr = imsk;
UBYTE scnt;
Ilmoita("Saving samples...");
*mskptr |= 1; /* bit #0 of first mask means 63 samples */
for(scnt = 0; scnt < 63; scnt++) {
if(scnt == 31) mskptr++;
*mskptr <<= 1;
if(sample[scnt]) *mskptr |= 1;
}
if(FWrite((char *)imsk,8)) return(DISKERR);
for(scnt = 0; scnt < 63; scnt++) {
if(sample[scnt] && FWrite((char *)sample[scnt],
sample[scnt]->length + sizeof(struct Soitin)))
return(DISKERR);
}
return(NOERR);
}
/* MED File format (V2.10) -- Song header:
"MED\x04" id
Mask1 (1 byte: mask for sample mask, 1 bit = 8 samples)
SampleMask0 Both 1 longword, if bit is 1, there's Sample-structure for
SampleMask1 this sample. Bit #0 of SampleMask1 is 0
For each sample:
SCMask (1 word: bit0-6 length of sample name, if bit8=1 rep = 0,
if bit9=1 replen = 0, if bit10=1 midich=0, if bit11=1
midipreset = 0, if bit12=1 svol=0, if bit13=1, svol=64)
all data for that sample, sample name not 0-terminated
numblocks, songlen (both UWORD)
playseq <songlen> bytes
deftempo, playtransp,flags,sliding,jumpmask,rgb,trkvol,mastervol = 43 bytes
and blocks... (see above) */
char *SaveSong(char *name,BOOL sinstr,UBYTE icon)
{
UBYTE scnt,oldexists = 0,smskmsk = 0,*sdptr;
UWORD sdata[4] = {0};
ULONG samplemask[2] = { 0,0 },*smaskptr = samplemask;
struct SCMask scmask;
struct SongSample *ss;
extern struct ViewPort *vp;
if(*name == '\0') return(AskName());
if(IsHere(name)) {
Ilmoita(fileex);
oldexists = 1;
if(!Continue()) return(notsaved);
}
if(sinstr) song.flags |= FLAG_INSTRSATT;
else song.flags &= ~FLAG_INSTRSATT;
if(!(fh = Open2(name,MODE_NEWFILE))) return(DISKERR);
Ilmoita("Saving song...");
if(FWrite("MED\x04",4)) return(DISKERR);
for(scnt = 0; scnt < 63; scnt++) {
ss = &song.sample[scnt];
*smaskptr <<= 1;
if(ss->sname[0] || ss->svol || ss->rep || ss->replen ||
ss->midich || ss->midipreset)
*smaskptr |= 1;
if(scnt == 31) smaskptr++;
}
*smaskptr <<= 1;
for(scnt = 0; scnt < 8; scnt++) {
smskmsk <<= 1;
if(*((UBYTE *)samplemask + scnt)) smskmsk |= 1;
}
if(FWrite(&smskmsk,1)) return(DISKERR);
for(scnt = 0; scnt < 8; scnt++)
if(*((UBYTE *)samplemask + scnt))
if(FWrite((char *)samplemask + scnt,1)) return(DISKERR);
smaskptr = samplemask;
for(scnt = 0; scnt < 63; scnt++) {
if(scnt == 32) smaskptr++;
ss = &song.sample[scnt];
memset((void *)&scmask,0,sizeof(scmask));
if(*smaskptr & 0x80000000) {
if(!ss->rep) scmask.rep0 = 1;
if(!ss->replen) scmask.replen0 = 1;
if(!ss->midich) scmask.midich0 = 1;
if(!ss->midipreset) scmask.midipres0 = 1;
if(!ss->svol) scmask.svol0 = 1;
if(!ss->strans) scmask.strans0 = 1;
if(ss->svol == 64) scmask.svol64 = 1;
scmask.snamelen = strlen(ss->sname);
if(FWrite((char *)(&scmask),2)) return(DISKERR);
if(scmask.snamelen && FWrite(ss->sname,
scmask.snamelen)) return(DISKERR);
sdptr = (UBYTE *)sdata;
if(!scmask.rep0) { /* remember, no alignment */
*sdptr = ss->rep >> 8;
*(sdptr+1) = ss->rep & 0x00ff;
sdptr += 2;
}
if(!scmask.replen0) {
*sdptr = ss->replen >> 8;
*(sdptr+1) = ss->replen & 0x00ff;
sdptr += 2;
}
if(!scmask.midich0) *sdptr++ = ss->midich;
if(!scmask.midipres0) *sdptr++ = ss->midipreset;
if(!scmask.svol0 && !scmask.svol64) *sdptr++ = ss->svol;
if(!scmask.strans0) *sdptr++ = ss->strans;
if((UBYTE *)sdata < sdptr && FWrite((char *)sdata,
sdptr - (UBYTE *)sdata)) return(DISKERR);
}
*smaskptr <<= 1;
}
song.numblocks = blocks;
if(FWrite((char *)(&song.numblocks),4)) return(DISKERR);
if(FWrite(song.playseq,song.songlen)) return(DISKERR);
for(scnt = 0; scnt < 8; scnt++)
song.rgb[scnt] = GetRGB4(vp->ColorMap,scnt);
if(FWrite((char *)(&song.deftempo),43)) return(DISKERR);
for(scnt = 0; scnt < blocks; scnt++)
if(SaveBlock((UWORD)scnt)) return(DISKERR);
if(sinstr) {
char *sires = SaveInstruments();
if(sires != NOERR) return(sires);
}
if(fh) { Close(fh); fh = 0L; }
if(!oldexists) InsertSavedFile(name);
if(icon) {
Ilmoita("Creating icon...");
if(WriteIcon(name)) return(NOERR);
}
Ilmoita("Song saved.");
return(NOERR);
}
char *Load210Song()
{
ULONG samplemask[2],*smskptr = samplemask;
UBYTE smskmsk,*smptr0 = (UBYTE *)samplemask,scnt,midifound = 0;
struct SCMask scmask;
struct SongSample *ss;
Ilmoita("Loading MED2.10-song...");
if(FRead((char *)samplemask,4)) return(DISKERR); /* MED\x04 */
if(FRead(&smskmsk,1)) return(DISKERR);
for(scnt = 0; scnt < 8; scnt++) {
if(!(smskmsk & 0x80)) *(smptr0+scnt) = 0;
else if(FRead(smptr0+scnt,1)) return(DISKERR);
smskmsk <<= 1;
}
for(scnt = 0; scnt < 63; scnt++) {
if(scnt == 32) smskptr++;
ss = &song.sample[scnt];
if(*smskptr & 0x80000000) {
if(FRead((char *)&scmask,2)) return(DISKERR);
if(scmask.snamelen && FRead(ss->sname,
scmask.snamelen)) return(DISKERR);
ss->sname[scmask.snamelen] = 0;
if(scmask.rep0) ss->rep = 0;
else if(FRead((char *)&song.sample[scnt].rep,2)) return(DISKERR);
if(scmask.replen0) ss->replen = 0;
else if(FRead((char *)&(ss->replen),2)) return(DISKERR);
if(scmask.midich0) ss->midich = 0;
else if(FRead(&(ss->midich),1)) return(DISKERR);
if(scmask.midipres0) ss->midipreset = 0;
else if(FRead(&(ss->midipreset),1)) return(DISKERR);
if(scmask.svol0) ss->svol = 0;
else if(scmask.svol64) ss->svol = 64;
else if(FRead(&(ss->svol),1)) return(DISKERR);
if(scmask.strans0) ss->strans = 0;
else if(FRead(&(ss->strans),1)) return(DISKERR);
} else {
ss->sname[0] = 0;
ss->rep = 0;
ss->replen = 0;
ss->midich = 0;
ss->midipreset = 0;
ss->strans = 0;
ss->svol = 0;
}
*smskptr <<= 1;
if(ss->midich) midifound = 1;
}
DeleteSamplesNotUsed();
if(FRead((char *)(&song.numblocks),4)) return(DISKERR);
if(FRead(song.playseq,song.songlen)) return(DISKERR);
if(FRead((char *)(&song.deftempo),43)) return(DISKERR);
if(midifound) MIDIon();
return(LoadBlocks(TRUE));
}
char *Load200Song()
{
ULONG zmsk;
UBYTE scnt,*nameptr,midifound = 0,dummy;
struct SongSample *ss;
Ilmoita("Loading MED2.00-song...");
if(FRead((char *)(&zmsk),4)) return(DISKERR); /* MED\x03 */
if(FRead(&dummy,1)) return(DISKERR);
for(scnt = 0; scnt < 31; scnt++) {
ss = &song.sample[scnt];
nameptr = ss->sname;
for(;;) {
if(FRead(nameptr,1)) return(DISKERR);
if(*nameptr++ == '\0') break;
}
ss->strans = 0;
}
DeleteSamplesNotUsed();
clrxtoy(31,63);
if(FRead((char *)(&zmsk),4)) return(DISKERR);
if(zmsk & 0x80000000 && FRead(&dummy,1)) return(DISKERR);
for(scnt = 0; scnt < 31; scnt++) {
ss = &song.sample[scnt];
zmsk <<= 1;
if(zmsk & 0x80000000) {
if(FRead(&ss->svol,1)) return(DISKERR);
} else ss->svol = 0;
}
if(FRead((char *)(&zmsk),4)) return(DISKERR);
for(scnt = 0; scnt < 31; scnt++) {
ss = &song.sample[scnt];
zmsk <<= 1;
if(zmsk & 0x80000000) {
if(FRead((char *)(&ss->rep),2)) return(DISKERR);
ss->rep >>= 1;
} else ss->rep = 0;
}
if(FRead((char *)(&zmsk),4)) return(DISKERR);
for(scnt = 0; scnt < 31; scnt++) {
ss = &song.sample[scnt];
zmsk <<= 1;
if(zmsk & 0x80000000) {
if(FRead((char *)(&ss->replen),2)) return(DISKERR);
ss->replen >>= 1;
} else ss->replen = 0;
}
if(FRead((char *)(&song.numblocks),2)) return(DISKERR);
if(FRead((char *)(&song.songlen),2)) return(DISKERR);
if(FRead(song.playseq,song.songlen)) return(DISKERR);
if(FRead((char *)(&song.deftempo),26)) return(DISKERR);
song.jumpmask >>= 1;
if(FRead((char *)(&zmsk),4)) return(DISKERR);
for(scnt = 0; scnt < 31; scnt++) {
ss = &song.sample[scnt];
zmsk <<= 1;
if(zmsk & 0x80000000) {
if(FRead(&ss->midich,1)) return(DISKERR);
midifound = 1;
} else ss->midich = 0;
}
if(FRead((char *)(&zmsk),4)) return(DISKERR);
for(scnt = 0; scnt < 31; scnt++) {
ss = &song.sample[scnt];
zmsk <<= 1;
if(zmsk & 0x80000000) {
if(FRead(&ss->midipreset,1)) return(DISKERR);
} else ss->midipreset = 0;
}
if(midifound) MIDIon();
return(LoadBlocks(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;
extern BPTR currdir;
BPTR prevdir;
if(!IconBase) {
Ilmoita("No icon.library: no icon.");
return(TRUE);
}
if(currdir) prevdir = CurrentDir(currdir);
status = PutDiskObject(name,&dobj);
if(currdir) CurrentDir(prevdir);
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 = NULL;
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 || msg->Code == 0x45) res = 2;
}
ReplyMsg((struct Message *)msg);
if(res) break;
}
CloseWindow(cwin);
if(res == 1) return(TRUE);
return(FALSE);
}
char *AskName()
{
OsionValinta(&gadget1[0]);
if(nykyinenosio == 2) {
ActivateGadget(&gadget2[9],window,NULL);
return("Type in the name:");
} else return(NOERR);
}
char *LoadAttachedInstrs()
{
ULONG imsk[2] = { 0,0 },*imptr = imsk;
UBYTE snum = 0;
struct Soitin loaded;
if(FRead((char *)imsk,4)) return(DISKERR);
if((*imsk & 0x80000000) && FRead((char *)(&imsk[1]),4)) return(DISKERR);
while(snum < 63) {
*imptr <<= 1; /* There's no instrument #0 */
if(snum == 31) imptr++;
if(*imptr & 0x80000000) {
if(FRead((char *)(&loaded),sizeof(struct Soitin)))
return(DISKERR);
if(NewInstrument(loaded.length,snum)) return(nomem);
sample[snum]->type = loaded.type;
if(FRead(((char *)sample[snum]) + sizeof(struct
Soitin),loaded.length)) return(DISKERR);
}
SeurSoitin();
snum++;
}
return(NOERR);
}
char *SaveRawSample(char *name)
{
UBYTE oldexists = 0;
if(!sample[samplenum]) return("No sample in memory!!!");
if(*name == '\0') {
UWORD pos;
if(nykyinenosio == 2) pos = RemoveGadget(window,&gadget2[9]);
strcpy(kappaleennimi,song.sample[samplenum].sname);
if(nykyinenosio == 2) {
AddGadget(window,&gadget2[9],pos);
RefreshGList(&gadget2[9],window,NULL,1);
}
return(NOERR);
}
if(IsHere(name)) {
Ilmoita(fileex);
oldexists = 1;
if(!Continue()) return(notsaved);
}
if(!(fh = Open2(name,MODE_NEWFILE))) return(DISKERR);
if(FWrite(((char *)(sample[samplenum])) + sizeof(struct Soitin),
sample[samplenum]->length & 0xfffffffe)) return(DISKERR);
if(fh) Close(fh);
fh = 0L;
if(!oldexists) InsertSavedFile(name);
Ilmoita("Sample saved.");
return(NOERR);
}