eqgrphcs.cpp
来自「声音均衡器的源代码程序」· C++ 代码 · 共 284 行
CPP
284 行
/* Phimal Graphic Equalization System
* Graphics Functions
*
* Kamal Swamidoss
* 28 August 1996
*
* Note that this application requires the file egavga.bgi (part of the
* Borland Graphics Interface).
*/
#include <hi54x.h>
#include <stdio.h>
#include <conio.h>
#include "eqgrphcs.h"
#include <graphics.h>
/* GDRIVER and GMODE are used to initialize the graphics interface */
#define GDRIVER 9 /* VGA */
#define GMODE 2 /* HI */
/* This application requires the file egavga.bgi at run-time.
* BGI_STRING tells the program where to look for the file.
*/
#define LOGO_WIDTH 200
#define LOGO_HEIGHT 100
#define LG_BOX_X1 20
#define LG_BOX_Y1 20
#define BGI_STRING "\0"
#define PAGE_SIZE 64 /* the size of a page of data coming from the EVM */
int gdriver=GDRIVER,gmode=GMODE,errorcode;
extern int current_band;
extern int current_gain[]; /* the current gain values of each band */
extern int x_scale;
extern int y_scale;
void paint_logo(void); /* paint the application logo on the screen */
/* update()
* updates the equalizer bars on the screen
* The argument, cmd_code, tells the function to increment or decrement
* a particular band. The high byte of cmd_code contains the command
* to increment or decrement; the low byte indicates the band to which
* the function should perform the increment or decrement.
*/
void update(int cmd_code)
{
int band=0;
unsigned int tmp;
tmp = cmd_code;
band = current_band;
send_word(current_band+0x10ff,A_SEND);
switch (tmp)
{
case (UP_1) :
highlight(band,++current_gain[band]);
tmp = (int)tmp*current_gain[current_band];
send_word(tmp,D_SEND);
break;
case (DN_1) :
tmp = UP_1;
unhighlight(band,current_gain[band],0);
highlight(band,--current_gain[band]);
tmp = (int)tmp*current_gain[current_band];
send_word(tmp,D_SEND);
break;
default: break;
}
send_word(clearHINT,C_SEND);
}
/* error_message()
* outputs a message to the screen and
* waits for the user to acknowledge
*/
void error_message(char *error_string)
{
setcolor(MY_HIGHCOLOR);
outtextxy(EQ_BOX_X1,EQ_BOX_Y2+15,error_string);
outtextxy(EQ_BOX_X1,EQ_BOX_Y2+25,"Any key...");
while (!kbhit());
if (getch() == '\0'){getch();}
setcolor(MY_BKGDCOLOR);
outtextxy(EQ_BOX_X1,EQ_BOX_Y2+15,error_string);
outtextxy(EQ_BOX_X1,EQ_BOX_Y2+25,"Any key...");
setcolor(MY_HIGHCOLOR);
}
/* highlight()
* highlights a particular equalizer band
*/
void highlight(int band,int gain)
{
int xval=0;
int yval=0;
setcolor(MY_HIGHCOLOR);
xval = EQ_BOX_X1+((band+1)*(EQ_BOX_X2-EQ_BOX_X1))/(NUM_BANDS+1);
yval = EQ_BOX_Y2-5-gain*(EQ_BOX_Y2-EQ_BOX_Y1-10)/(MAX_GAIN-MIN_GAIN);
setfillstyle(SOLID_FILL,MY_HIGHCOLOR);
bar(xval-BAR_WIDTH/2,EQ_BOX_Y2-5,xval+BAR_WIDTH/2,yval);
setcolor(MY_HIGHCOLOR);
}
/* unhighlight()
* unhighlights a particular equalizer band
* The third argument, replace, indicates whether the bar should be
* unhighlighted to MY_LOWCOLOR or BLACK.
*/
void unhighlight(int band,int gain,int replace)
{
int xval=0;
int yval=0;
xval = EQ_BOX_X1+((band+1)*(EQ_BOX_X2-EQ_BOX_X1))/(NUM_BANDS+1);
yval = EQ_BOX_Y2-5-gain*(EQ_BOX_Y2-EQ_BOX_Y1-10)/(MAX_GAIN-MIN_GAIN);
if (!replace)
{
setfillstyle(SOLID_FILL,BLACK);
setcolor(BLACK);
bar(xval-BAR_WIDTH/2,EQ_BOX_Y2-5,xval+BAR_WIDTH/2,yval);
setcolor(MY_HIGHCOLOR);
}
else
{
setfillstyle(SOLID_FILL,MY_LOWCOLOR);
setcolor(MY_HIGHCOLOR);
bar(xval-BAR_WIDTH/2,EQ_BOX_Y2-5,xval+BAR_WIDTH/2,yval);
}
}
/* close_graphics()
* close the graphics interface and restore the text interface
*/
void close_graphics(void)
{
setcolor(WHITE);
closegraph();
restorecrtmode();
_setcursortype(_NORMALCURSOR);
return;
}
/* init_graphics()
* initializes the graphics interface
*/
int init_graphics(void)
{
int i;
initgraph(&gdriver, &gmode, BGI_STRING);
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
{
fputs("Error initializing graphics mode.\n",stderr);
return 0;
}
/* draw the screen */
setbkcolor(MY_BKGDCOLOR);
setcolor(MY_EQ_BOXCOLOR);
rectangle(EQ_BOX_X1,EQ_BOX_Y1,EQ_BOX_X2,EQ_BOX_Y2);
setcolor(MY_TG_BOXCOLOR);
rectangle(TG_BOX_X1,TG_BOX_Y1,TG_BOX_X2,TG_BOX_Y2);
setcolor(MY_FRAMECOLOR);
rectangle(10,10,630,470);
rectangle(15,15,625,465);
setcolor(MY_HIGHCOLOR);
paint_logo();
setcolor(MY_YCOLOR);
outtextxy(EQ_BOX_X1-40,EQ_BOX_Y1-15,"Gain");
outtextxy(EQ_BOX_X1-40,EQ_BOX_Y1, "10");
outtextxy(EQ_BOX_X1-40,EQ_BOX_Y2-5, " 0");
outtextxy(25,EQ_BOX_Y2+55,"Up/Dn/Rt/Lt - Equalize");
outtextxy(25,EQ_BOX_Y2+65,"PgUp/PgDn - Change Y-scale");
outtextxy(25,EQ_BOX_Y2+75,"P/p - Pause");
outtextxy(25,EQ_BOX_Y2+85,"Q/q/ESC - Quit");
settextjustify(CENTER_TEXT,TOP_TEXT);
setcolor(MY_XCOLOR);
outtextxy(EQ_BOX_X1+ (EQ_BOX_X2-EQ_BOX_X1)/(NUM_BANDS+1),EQ_BOX_Y2+5,"low" );
outtextxy(EQ_BOX_X1+NUM_BANDS*(EQ_BOX_X2-EQ_BOX_X1)/(NUM_BANDS+1),EQ_BOX_Y2+5,"high");
settextjustify(LEFT_TEXT,TOP_TEXT);
setfillstyle(SOLID_FILL,MY_LOWCOLOR);
/* draw the equalizer bars */
for(i=0;i<NUM_BANDS;++i){
bar(EQ_BOX_X1+((i+1)*(EQ_BOX_X2-EQ_BOX_X1))/(NUM_BANDS+1)-BAR_WIDTH/2,
EQ_BOX_Y2-5,
EQ_BOX_X1+((i+1)*(EQ_BOX_X2-EQ_BOX_X1))/(NUM_BANDS+1)+BAR_WIDTH/2,
EQ_BOX_Y2-5-(EQ_BOX_Y2-EQ_BOX_Y1-10)/2);}
/* highlight the low-pass bar */
highlight(0,(MAX_GAIN-MIN_GAIN)/2);
moveto(home_x,home_y);
setcolor(MY_HIGHCOLOR);
return 1;
}
/* paint_logo()
* paint the application logo on the screen
* The logo is stored as a Windows Monochrome Bitmap (.bmp) file
* named phimal.bmp.
*/
void paint_logo(void)
{
FILE *fp;
char logo_file[]="phimal.bmp";
int byte_count,byte_width,byte;
int pixel_width,pixel_height;
int row;
int i,j;
int image[LOGO_HEIGHT][LOGO_WIDTH];
if ((fp = fopen(logo_file,"r")) == NULL)
{
fclose(fp);
outtextxy(100,50,"Phimal's Equalizer");
return;
}
fgetc(fp);
fgetc(fp);
fgetc(fp);
for (i=0;i<15;++i)
fgetc(fp);
pixel_width = fgetc(fp);
for (i=0;i<3;++i)
fgetc(fp);
pixel_height = fgetc(fp);
for (i=0;i<39;++i)
fgetc(fp);
if ((pixel_height > LOGO_HEIGHT) || (pixel_width > LOGO_WIDTH) || (pixel_width < 32))
{
fclose(fp);
outtextxy(100,50,"Phimal's Equalizer");
return;
}
byte_width = pixel_width/8;
for (row=pixel_height-1;row>=0;--row)
{
byte_count=0;
for (byte=0;byte<byte_width;++byte)
{
i=fgetc(fp);
++byte_count;
for (j=7;j>=0;--j)
{
image[row][8*byte+j] = i & 0x01;
i = i >> 1;
}
}
if (pixel_width%8 > 0)
{
i=fgetc(fp);
++byte_count;
for (j=0;j<8-pixel_width%8;++j)
i = i >> 1;
for (j=pixel_width%8-1;j>=0;--j)
{
image[row][8*byte+j] = i & 0x01;
i = i >> 1;
}
}
if (byte_count%4 != 0)
for (i=0;i<4-byte_count%4;++i)
j=fgetc(fp);
}
fclose(fp);
for (i=0;i<pixel_width;++i)
for (j=0;j<pixel_height;++j)
if (image[j][i] == 0)
putpixel(i+LG_BOX_X1,j+LG_BOX_Y1,MY_LOGOCOLOR);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?