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-buff.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-17
|
6KB
|
183 lines
/* med-buff.c: MED buffer handling routines, ⌐ 1990 by Teijo Kinnunen */
#include <math.h> /* min(), abs() */
#include "med.h"
#include "medproto.h"
static UBYTE *buffer, bufftracks;
static UBYTE markblock, marktrack, markline;
static UWORD bufflines;
extern UBYTE currtrk,blocks;
extern UWORD pblock,pline;
extern WORD actplayline;
extern struct Lohko *lohko[];
void FreeBuffer()
{
if(!buffer) return;
FreeMem((void *)buffer, bufftracks * bufflines * 3);
bufftracks = bufflines = 0;
buffer = NULL;
}
BOOL AllocBuffer(UBYTE tracks,UWORD lines) /* FALSE = ok, TRUE = error */
{
FreeBuffer(); /* free the previous buffer */
if(!(buffer = AllocMem(tracks * lines * 3,MEMF_PUBLIC))) return(TRUE);
bufftracks = tracks;
bufflines = lines;
return(FALSE);
}
void CutCopyPaste(UBYTE block,UBYTE startline,UWORD lines,UBYTE starttrack,
UBYTE tracks,UBYTE op) /* op: 0 = copy, 1 = cut, 2 = paste, 3 = swap */
{
UWORD linecnt;
UBYTE ntrks = lohko[block]->numtracks; /* tracks in the block */
UBYTE *p1 = &lohko[block]->music[startline * ntrks * 3 +
starttrack * 3],*p2,trkcnt,swb;
UBYTE *linep1,*linep2;
if(starttrack + tracks > ntrks) tracks = ntrks - starttrack;
if(startline + lines > lohko[block]->lines + 1)
lines = lohko[block]->lines + 1 - startline;
if((op == 0 || op == 1) && AllocBuffer(tracks,lines)) { Ilmoita(nomem); return; }
else if(op >= 2) {
if(lines > bufflines) lines = bufflines;
if(tracks > bufftracks) tracks = bufftracks;
}
if(!(p2 = buffer)) { Ilmoita("The buffer is empty."); return; }
for(linecnt = 0; linecnt < lines; linecnt++) {
linep1 = p1; linep2 = p2;
for(trkcnt = 0; trkcnt < tracks; trkcnt++) {
if(op == 0 || op == 1) { /* cut/copy */
*p2=*p1; *(p2+1)=*(p1+1); *(p2+2)=*(p1+2);
if(op == 1) *p1 = *(p1+1) = *(p1+2) = 0;
} else if(op == 2) { /* paste */
*p1=*p2; *(p1+1)=*(p2+1); *(p1+2)=*(p2+2);
} else if(op == 3) { /* swap */
swb = *p1; *p1 = *p2; *p2 = swb;
swb=*(p1+1); *(p1+1)=*(p2+1); *(p2+1)=swb;
swb=*(p1+2); *(p1+2)=*(p2+2); *(p2+2)=swb;
}
p1 += 3; p2 += 3; /* advance pointers one note */
}
p1 = linep1 + 3 * ntrks; /* advance blockptr one line */
p2 = linep2 + 3 * bufftracks; /* advance buffptr 1 line */
}
}
void SetMark()
{
markblock = (UBYTE)pblock;
markline = (UBYTE)pline;
marktrack = (UBYTE)currtrk;
}
void HandleMark(UBYTE code)
{
UBYTE block = pblock,line = pline,track = currtrk;
if(markblock != pblock && code != 0x34) {
Ilmoita("One block at a time, please."); return;
}
if(code == 0x34) CutCopyPaste((UBYTE)block,(UBYTE)line,
bufflines,(UBYTE)currtrk,bufftracks,2);
else CutCopyPaste((UBYTE)block,(UBYTE)min(markline,line),
(UWORD)(abs(markline-line)+1),(UBYTE)min(marktrack,track),
(UBYTE)(abs(marktrack - track) + 1),
(UBYTE)(code == 0x32 ? 1 : 0));
PaivitaNaytto(TRUE);
}
void ExpandBlock(UWORD block)
{
UBYTE tracks;
WORD linecnt,lines,oldl = lohko[block]->lines;
ULONG hlmsks[4];
if(lohko[block]->lines > 127) {
Ilmoita("Too many lines.");
return;
}
tracks = lohko[block]->numtracks;
if(ChangeBlockSize(block,(UWORD)(tracks / 4),
(UWORD)((lohko[block]->lines + 1) * 2))) {
Ilmoita(nomem); return;
}
lines = (WORD)(lohko[block]->lines);
for(linecnt = lines; linecnt >= 0; linecnt--) {
if(linecnt & 0x1) /* clear odd-numbered lines */
memset(&lohko[block]->music[linecnt * 3 * tracks],
0,3 * tracks);
else memcpy(&lohko[block]->music[linecnt * 3 * tracks],
&lohko[block]->music[linecnt / 2 *
3 * tracks], 3 * tracks);
}
for(linecnt = 0; linecnt < 4; linecnt++) hlmsks[linecnt] =
lohko[block]->hlmask[linecnt];
for(linecnt = 0; linecnt < 8; linecnt++) lohko[block]->hlmask[linecnt] = 0L;
for(linecnt = 0; linecnt <= oldl; linecnt++)
if(hlmsks[linecnt /á32] & (1 << (linecnt & 31))) HLLine(block,(UBYTE)(linecnt * 2));
PaivitaNaytto(TRUE);
TulostaLohkoJaSoitin();
}
void ShrinkBlock(UWORD block)
{
UBYTE tracks = lohko[block]->numtracks;
ULONG hlmsks[8];
WORD linecnt,lines = lohko[block]->lines;
if(!lines) { Ilmoita("Can't split a line."); return; }
for(linecnt = 0; linecnt <= lines ; linecnt++)
memcpy(&lohko[block]->music[linecnt * 3 * tracks],
&lohko[block]->music[linecnt * 6 * tracks],3 * tracks);
ChangeBlockSize(block,(UWORD)(tracks / 4),(UWORD)((lines + 1) /á2));
lines = lohko[block]->lines;
for(linecnt = 0; linecnt < 8; linecnt++) {
hlmsks[linecnt] = lohko[block]->hlmask[linecnt];
lohko[block]->hlmask[linecnt] = 0L;
}
for(linecnt = 0; linecnt <= lines * 2; linecnt += 2)
if(hlmsks[linecnt /á32] & (1 << (linecnt & 31))) HLLine(block,(UBYTE)(linecnt / 2));
PaivitaNaytto(TRUE);
TulostaLohkoJaSoitin();
}
void SplitBlock(UWORD block,UWORD line)
{
UBYTE trks = lohko[block]->numtracks;
UWORD lines = lohko[block]->lines + 1;
if(!line) return; /* can't split */
if(NewBlockHere(block,(UWORD)trks,line)) return;
memcpy(lohko[block]->music,lohko[block+1]->music,3 * line * trks);
movmem(&lohko[block+1]->music[3 * line * trks],
lohko[block+1]->music,3 * trks * (lines - line));
ChangeBlockSize((UWORD)(block+1),(UWORD)(trks /á4),(UWORD)(lines - line));
Disable();
pblock = block + 1;
pline = 0;
actplayline = -1;
Enable();
PaivitaNaytto(TRUE);
TulostaLohkoJaSoitin();
}
void JoinBlocks(UWORD block)
{
UWORD lines,l2 = lohko[block]->lines;
if(block >= blocks - 1) {
Ilmoita("This is the last block.");
return;
}
lines = l2 + lohko[block + 1]->lines + 2;
if(lines > 256) {
Ilmoita("Blocks are too long."); return;
}
if(ChangeBlockSize(block,(UWORD)(lohko[block]->numtracks /á4),lines)) {
Ilmoita(nomem);
return;
}
memcpy(&lohko[block]->music[3 * lohko[block]->numtracks *
(l2 + 1)],lohko[block+1]->music,3 * lohko[block]
->numtracks * (lohko[block+1]->lines + 1));
DelBlockHere((UWORD)(block + 1));
}