summaryrefslogtreecommitdiffstats
path: root/noatun-plugins/tyler/main.cpp
blob: 40f639dddfade06316f11dbe3a83b2d745fcad74 (plain)
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
// Copyright (C) 2000 Julien Carme
// Copyright (C) 2001 Charles Samuels <charles@kde.org>
// Copyright (C) 2001 Neil Stevens <neil@qualityassistant.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2, as
// published by the Free Software Foundation.
//
// 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

#include <kinstance.h>

extern "C"
{
#include <SDL.h>
#include <SDL_syswm.h>
#include <SDL_thread.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>

#include "renderer.h"
#include "display.h"
}

// stuff in main.h
extern "C"
{
typedef struct t_config {
    int xres,yres,sres;
    int teff,tcol;
} t_config;

t_config config = {512, 352, 1, 100, 100};
//t_config config = {640, 480, 1, 100, 100};

bool finished;
SDL_Thread *thread;
SDL_mutex *synchro_mutex, *access_mutex;
short pcm_data[2][512];
SDL_Surface *screen;
}

int winID(void)
{
	SDL_SysWMinfo info;
	info.version.major = SDL_MAJOR_VERSION;
	info.subsystem = SDL_SYSWM_X11;

	SDL_GetWMInfo(&info);
	return info.info.x11.wmwindow;
}

int main(int, char **)
{
	fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL) & ~O_NONBLOCK);

	atexit(SDL_Quit);

	TDEInstance in("noatuntyler");

	finished = false;
	access_mutex = SDL_CreateMutex();

	init_renderer1();
	printf("%u\n", winID());
	fflush(stdout);
	init_renderer2();
	thread = SDL_CreateThread((int (*)(void *))renderer, NULL);

	fd_set set;
	struct timeval tv;
	while(check_finished() != 1)
	{
		FD_ZERO(&set);
		FD_SET(STDIN_FILENO, &set);
		tv.tv_sec = 0;
		tv.tv_usec = 250;
		if(0 < select(STDIN_FILENO + 1, &set, 0, 0, &tv))
		{
			SDL_mutexP(access_mutex);
			read(STDIN_FILENO, (void *)pcm_data, sizeof(short) * 2 * 512);
			SDL_mutexV(access_mutex);
		}
		usleep(5);
	}
	/*fprintf(stderr,"exiting main()\n");*/
	SDL_WaitThread(thread, NULL);
}