ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SIDPlayer/src/soundplay.cpp
Revision: 1.3
Committed: 2001-05-26T12:09:57Z (23 years, 5 months ago) by cebix
Branch: MAIN
Changes since 1.2: +3 -1 lines
Log Message:
fixed BeOS compilation problems

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * soundplay.cpp - SIDPlayer SoundPlay plugin
3     *
4 cebix 1.2 * SIDPlayer (C) Copyright 1996-2001 Christian Bauer
5 cebix 1.1 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21    
22     #include <stdio.h>
23     #include <string.h>
24     #include <stdlib.h>
25     #include <MediaDefs.h>
26     #include <Path.h>
27    
28     #include "soundplay.h"
29    
30     #include "prefs.h"
31     #include "main.h"
32     #include "psid.h"
33     #include "sid.h"
34     #include "prefs_window.h"
35    
36     static const char MY_URL_HEADER[] = "sid://";
37     const int MY_URL_HEADER_LEN = 6;
38    
39     /* ===========================================================
40     Plugin-descriptor structure.
41     This structure is used to gather information about a plugin
42     and instantiate and destroy specific instances of a plugin.
43     Since SIDPlayer is single-context, we set the single context
44     flag to make SoundPlay load additional instances of this plugin
45     when needed.
46     */
47     static plugin_descriptor plugin={
48     PLUGIN_DESCRIPTOR_MAGIC,PLUGIN_DESCRIPTOR_VERSION,
49     "sp-sidplay",1, PLUGIN_IS_DECODER|PLUGIN_IS_SINGLE_CONTEXT,
50    
51     "SIDPlayer Decoder",
52     "By Christian Bauer.\n\n"
53     "SoundPlay plugin by\nMarco Nelissen.",
54     NULL, //about,
55     configure,
56     getplugin,
57     destroyplugin
58     };
59    
60     /* ===========================================================
61     Plugin-operations structure.
62     This is used to actually perform operations on a plugin.
63     It is returned by the getplugin() function from the
64     plugin_descriptor structure above.
65     */
66     static decoder_plugin_ops ops={
67     PLUGIN_DECODER_MAGIC,PLUGIN_DECODER_VERSION,
68    
69     open,
70     NULL, // close
71     info,
72     read,
73     NULL, // play
74     NULL, // stop
75     NULL, // setvolume
76     NULL, // setpitchandspeed
77     NULL, // seek,
78     NULL, // position,
79     NULL // bufferamount
80     };
81    
82    
83     /* ===========================================================
84     Return the list of plugins in this file.
85     */
86     static plugin_descriptor *plugs[]={
87     &plugin,
88     0
89     };
90    
91     plugin_descriptor **get_plugin_list(void)
92     {
93     return plugs;
94     }
95    
96     /* ===========================================================
97     Return the list of filetypes supported by all the plugins
98     in this file
99     */
100     static supported_type supportedtypes[]=
101     {
102     {"audio/x-psid", "SIDPlayer file", "SIDPlayer file", "sid", "psid"},
103     {NULL, NULL, NULL, NULL, NULL}
104     };
105    
106     supported_type *get_supported_types(void)
107     {
108     return supportedtypes;
109     }
110    
111    
112     /* ===========================================================
113     Implementation of the plugin_descriptor functions
114     */
115    
116     static BWindow *prefs_window=NULL;
117    
118     static bool initialized=false;
119    
120     class autoinit
121     {
122     public:
123     autoinit()
124     {
125     }
126     ~autoinit()
127     {
128     if(initialized)
129     {
130     ExitAll();
131     initialized = false;
132     }
133     }
134     };
135     static autoinit autoinit;
136    
137     static void *getplugin(void **data, const char *filename, const char *header, uint32 size, plugin_info *info)
138     {
139     if(!initialized)
140     {
141     initialized = true;
142 cebix 1.3 int argc = 0;
143     char **argv = NULL;
144     InitAll(argc, argv);
145 cebix 1.1 }
146     if (strncasecmp(filename, MY_URL_HEADER, MY_URL_HEADER_LEN) == 0) {
147     // name starts with "sid://", extract file name
148     char name[B_FILE_NAME_LENGTH];
149     char *q = strrchr(filename, '?');
150     if (q == NULL)
151     return NULL;
152     int name_len = q - (filename + MY_URL_HEADER_LEN);
153     strncpy(name, filename + MY_URL_HEADER_LEN, name_len);
154     name[name_len] = 0;
155     if(!IsPSIDFile(name))
156     return NULL;
157     } else {
158     if(!IsPSIDFile(filename))
159     return NULL;
160     }
161     return &ops;
162     }
163    
164     static void destroyplugin(void *ops,void *_sh)
165     {
166     }
167    
168     static BView* configure(BMessage *config)
169     {
170     if (prefs_window_open && prefs_window) {
171     prefs_window->Activate(true);
172     return NULL;
173     } else {
174     prefs_window = new PrefsWindow();
175     return NULL;
176     }
177     }
178    
179     /* ===========================================================
180     Implementation of the decoder_plugin_ops functions
181     */
182    
183     status_t open(void *,const char *filename, const char *header, uint32 size, BMessage *config)
184     {
185     char name[B_FILE_NAME_LENGTH];
186     bool subsong_given = false;
187     int song;
188    
189     if (strncasecmp(filename, MY_URL_HEADER, MY_URL_HEADER_LEN) == 0) {
190    
191     // name starts with "sid://", extract file name
192     char *q = strrchr(filename, '?');
193     if (q == NULL)
194     return B_ERROR;
195     subsong_given = true;
196     song = atoi(q + 1);
197     int name_len = q - (filename + MY_URL_HEADER_LEN);
198     strncpy(name, filename + MY_URL_HEADER_LEN, name_len);
199     name[name_len] = 0;
200    
201     } else
202     strcpy(name, filename);
203    
204     // Load PSID file
205     if (!LoadPSIDFile(name))
206     return B_ERROR;
207    
208     // Select subsong if subsong number given
209     if (subsong_given)
210     SelectSong(song);
211    
212     return B_OK;
213     }
214    
215    
216     static status_t info(void *_sid, file_info *info)
217     {
218     strcpy(info->name,"");
219     strcpy(info->typedesc,"SID");
220     strcpy(info->mimetype,"audio/x-psid");
221     info->samplerate=44100;
222     info->bitrate=0;
223     info->numchannels=2;
224     info->granularity=4096;
225     info->framecount=0x7fffffff;
226     info->samplesize=2;
227     if(B_HOST_IS_LENDIAN)
228     info->byteorder=B_LITTLE_ENDIAN;
229     else
230     info->byteorder=B_BIG_ENDIAN;
231     info->sampleformat=B_LINEAR_SAMPLES;
232     info->flags=PLUGIN_FILELENGTH_UNKNOWN;
233    
234     return B_OK;
235     }
236    
237    
238     int32 read(void *,char *buf, ulong numframes)
239     {
240     SIDCalcBuffer((uint8*)buf, numframes*4);
241     return numframes;
242     }
243    
244