1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/* WMix 3.0 -- a mixer using the OSS mixer API.
* Copyright (C) 2000, 2001
* Daniel Richard G. <skunk@mit.edu>,
* timecop <timecop@japan.co.jp>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "include/common.h"
#include "include/misc.h"
typedef struct {
int enable;
int x;
int y;
int width;
int height;
} MRegion;
MRegion mr[16];
extern Config config;
/* Converts separate left and right channel volumes (each in [0, 1]) to
* volume and balance values. (Volume is in [0, 1], balance is in [-1, 1])
*/
void lr_to_vb(float left, float right, float *volume, float *balance)
{
assert((left >= 0.0) && (right >= 0.0));
*volume = MAX(left, right);
if (left > right)
*balance = -1.0 + right / left;
else if (right > left)
*balance = 1.0 - left / right;
else
*balance = 0.0;
}
/* Performs the reverse calculation of lr_to_vb()
*/
void vb_to_lr(float volume, float balance, float *left, float *right)
{
/* *left = volume; *right = volume; return; // XXX */
*left = volume * (1.0 - MAX(0.0, balance));
*right = volume * (1.0 + MIN(0.0, balance));
}
double get_current_time(void)
{
struct timeval tv;
double t;
gettimeofday(&tv, NULL);
t = (double)tv.tv_sec;
t += (double)tv.tv_usec / 1.0e6;
return t;
}
void add_region(int index, int x, int y, int width, int height)
{
mr[index].enable = 1;
mr[index].x = x;
mr[index].y = y;
mr[index].width = width;
mr[index].height = height;
}
int check_region(int x, int y)
{
register int i;
bool found = false;
for (i = 0; i < 16 && !found; i++) {
if (mr[i].enable && x >= mr[i].x &&
x <= mr[i].x + mr[i].width &&
y >= mr[i].y && y <= mr[i].y + mr[i].height)
found = true;
}
if (!found)
return -1;
return (i - 1);
}
void config_read(void)
{
FILE *fp;
char buf[512];
char *ptr;
if (config.file == NULL)
return;
fp = fopen(config.file, "r");
if (!fp)
return;
while (fgets(buf, 512, fp)) {
if ((ptr = strstr(buf, "mousewheel="))) {
ptr += 11;
config.mousewheel = atoi(ptr);
}
if ((ptr = strstr(buf, "scrolltext="))) {
ptr += 11;
config.scrolltext = atoi(ptr);
}
if ((ptr = strstr(buf, "osd="))) {
ptr += 4;
config.osd = atoi(ptr);
}
if ((ptr = strstr(buf, "osdcolor="))) {
char *end;
ptr += 9;
end = strchr(ptr, '\n');
ptr[end - ptr] = '\0';
if (config.osd_color)
free(config.osd_color);
config.osd_color = strdup(ptr);
}
if ((ptr = strstr(buf, "wheelstep="))) {
ptr += 10;
/* detect old style config */
if (atoi(ptr) > 1)
config.scrollstep = (float)atoi(ptr) / 100.0;
else
config.scrollstep = atof(ptr);
}
if ((ptr = strstr(buf, "wheelbtn1="))) {
ptr += 10;
config.wheel_button_up = atoi(ptr);
}
if ((ptr = strstr(buf, "wheelbtn2="))) {
ptr += 10;
config.wheel_button_down = atoi(ptr);
}
}
fclose(fp);
}
|