Mercurial > audlegacy-plugins
annotate src/paranormal/misc.c @ 2138:76f9a4168708
Fix linking with libaudid3tag
Linking with libaudid3tag from /usr/lib/audacious, add rpath (affected to tta,
shnplug and madplug plugins)
| author | Vitaly Lipatov <lav@etersoft.ru> |
|---|---|
| date | Sat, 27 Oct 2007 19:34:46 -0500 |
| parents | 56bb18dd3fdd |
| children | f1b6f1b2cdb3 |
| rev | line source |
|---|---|
|
1892
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
1 /* |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
2 * paranormal: iterated pipeline-driven visualization plugin |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
3 * Copyright (c) 2006, 2007 William Pitcock <nenolod@dereferenced.org> |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
4 * Portions copyright (c) 2001 Jamie Gennis <jgennis@mindspring.com> |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
5 * |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
8 * the Free Software Foundation; under version 2 of the License. |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
9 * |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
13 * GNU General Public License for more details. |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
14 * |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
16 * along with this program; if not, write to the Free Software |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
18 */ |
|
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
19 |
|
1943
56bb18dd3fdd
paranormal: CONFIG_H removal
William Pitcock <nenolod@atheme.org>
parents:
1892
diff
changeset
|
20 #include <config.h> |
| 186 | 21 |
| 22 #include <stdlib.h> | |
| 23 #include <stdio.h> | |
| 24 | |
| 25 #include <glib.h> | |
| 26 | |
| 27 #include "paranormal.h" | |
| 28 #include "actuators.h" | |
| 29 #include "pn_utils.h" | |
| 30 | |
| 31 /* ******************** misc_floater ******************** */ | |
| 32 static struct pn_actuator_option_desc misc_floater_opts[] = | |
| 33 { | |
| 34 { "value", "The colour value for the floater.", | |
| 35 OPT_TYPE_INT, { ival: 255 } }, | |
| 188 | 36 { NULL } |
| 186 | 37 }; |
| 38 | |
| 39 typedef enum | |
| 40 { | |
| 41 float_up = 0x1, | |
| 42 float_down = 0x2, | |
| 43 float_left = 0x4, | |
| 44 float_right = 0x8, | |
| 45 } FloaterDirection; | |
| 46 | |
| 47 struct floater_state_data | |
| 48 { | |
| 49 FloaterDirection dir; | |
| 50 gint x; | |
| 51 gint y; | |
| 52 }; | |
| 53 | |
| 54 static void | |
| 55 misc_floater_init(gpointer *data) | |
| 56 { | |
| 57 struct floater_state_data *opaque_data = g_new0(struct floater_state_data, 1); | |
| 58 *data = opaque_data; | |
| 59 opaque_data->x = rand() % pn_image_data->width; | |
| 60 opaque_data->y = rand() % pn_image_data->height; | |
| 61 opaque_data->dir = (FloaterDirection) rand() % 15; /* sum of all dir values */ | |
| 62 } | |
| 63 | |
| 64 static void | |
| 65 misc_floater_cleanup(gpointer data) | |
| 66 { | |
| 67 g_free(data); | |
| 68 } | |
| 69 | |
| 70 /* | |
| 71 * This implementation isn't very great. | |
| 72 * Anyone want to improve it? :( | |
| 73 */ | |
| 74 static void | |
| 75 misc_floater_exec(const struct pn_actuator_option *opts, gpointer data) | |
| 76 { | |
| 77 struct floater_state_data *opaque_data = (struct floater_state_data *) data; | |
| 78 guchar value = (opts[0].val.ival < 0 || opts[0].val.ival > 255) ? 255 : opts[0].val.ival; | |
| 79 | |
| 80 /* determine the root coordinate first */ | |
| 81 if (opaque_data->dir & float_up) | |
| 82 opaque_data->y -= 1; | |
| 83 if (opaque_data->dir & float_down) | |
| 84 opaque_data->y += 1; | |
| 85 | |
| 86 if (opaque_data->dir & float_left) | |
| 87 opaque_data->x -= 1; | |
| 88 if (opaque_data->dir & float_right) | |
| 89 opaque_data->x += 1; | |
| 90 | |
| 91 /* make sure we're within surface boundaries. segfaults suck, afterall. */ | |
| 92 if (opaque_data->x + 1 <= pn_image_data->width && | |
| 93 opaque_data->x - 1 >= 0 && | |
| 94 opaque_data->y + 1 <= pn_image_data->height && | |
| 95 opaque_data->y - 1 >= 0) | |
| 96 { | |
| 97 /* draw it. i could use a loop here, but i don't see much reason in it, | |
| 98 * so i don't think i will at this time. -nenolod | |
| 99 */ | |
| 100 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y)] = value; | |
| 101 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x + 1, opaque_data->y)] = value; | |
| 102 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x - 1, opaque_data->y)] = value; | |
| 103 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y + 1)] = value; | |
| 104 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y - 1)] = value; | |
| 105 } | |
| 106 | |
| 107 /* check if we need to change direction yet, and if so, do so. */ | |
| 302 | 108 if (pn_new_beat == TRUE) |
| 186 | 109 opaque_data->dir = (FloaterDirection) rand() % 15; /* sum of all dir values */ |
| 110 | |
| 111 /* now adjust the direction so we stay in boundary */ | |
| 112 if (opaque_data->x - 1 <= 0 && opaque_data->dir & float_left) | |
| 113 { | |
| 114 opaque_data->dir &= ~float_left; | |
| 115 opaque_data->dir |= float_right; | |
| 116 } | |
| 117 | |
| 118 if (opaque_data->x + 1 >= pn_image_data->width && opaque_data->dir & float_right) | |
| 119 { | |
| 120 opaque_data->dir &= ~float_right; | |
| 121 opaque_data->dir |= float_left; | |
| 122 } | |
| 123 | |
| 124 if (opaque_data->y - 1 <= 0 && opaque_data->dir & float_up) | |
| 125 { | |
| 126 opaque_data->dir &= ~float_up; | |
| 127 opaque_data->dir |= float_down; | |
| 128 } | |
| 129 | |
| 130 if (opaque_data->y + 1 >= pn_image_data->height && opaque_data->dir & float_down) | |
| 131 { | |
| 132 opaque_data->dir &= ~float_down; | |
| 133 opaque_data->dir |= float_up; | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 struct pn_actuator_desc builtin_misc_floater = | |
| 138 { | |
| 139 "misc_floater", | |
| 140 "Floating Particle", | |
| 141 "A floating particle.", | |
| 142 0, misc_floater_opts, | |
| 143 misc_floater_init, misc_floater_cleanup, misc_floater_exec | |
| 144 }; | |
| 145 |
