ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SIDPlayer/src/soundplay.cpp
Revision: 1.1
Committed: 2001-01-14T13:17:35Z (23 years, 1 month ago) by cebix
Branch: MAIN
Log Message:
now also works as a SoundPlay plugin under BeOS

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * soundplay.cpp - SIDPlayer SoundPlay plugin
3     *
4     * SIDPlayer (C) Copyright 1996-2000 Christian Bauer
5     *
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     InitAll();
143     }
144     if (strncasecmp(filename, MY_URL_HEADER, MY_URL_HEADER_LEN) == 0) {
145     // name starts with "sid://", extract file name
146     char name[B_FILE_NAME_LENGTH];
147     char *q = strrchr(filename, '?');
148     if (q == NULL)
149     return NULL;
150     int name_len = q - (filename + MY_URL_HEADER_LEN);
151     strncpy(name, filename + MY_URL_HEADER_LEN, name_len);
152     name[name_len] = 0;
153     if(!IsPSIDFile(name))
154     return NULL;
155     } else {
156     if(!IsPSIDFile(filename))
157     return NULL;
158     }
159     return &ops;
160     }
161    
162     static void destroyplugin(void *ops,void *_sh)
163     {
164     }
165    
166     static BView* configure(BMessage *config)
167     {
168     if (prefs_window_open && prefs_window) {
169     prefs_window->Activate(true);
170     return NULL;
171     } else {
172     prefs_window = new PrefsWindow();
173     return NULL;
174     }
175     }
176    
177     /* ===========================================================
178     Implementation of the decoder_plugin_ops functions
179     */
180    
181     status_t open(void *,const char *filename, const char *header, uint32 size, BMessage *config)
182     {
183     char name[B_FILE_NAME_LENGTH];
184     bool subsong_given = false;
185     int song;
186    
187     if (strncasecmp(filename, MY_URL_HEADER, MY_URL_HEADER_LEN) == 0) {
188    
189     // name starts with "sid://", extract file name
190     char *q = strrchr(filename, '?');
191     if (q == NULL)
192     return B_ERROR;
193     subsong_given = true;
194     song = atoi(q + 1);
195     int name_len = q - (filename + MY_URL_HEADER_LEN);
196     strncpy(name, filename + MY_URL_HEADER_LEN, name_len);
197     name[name_len] = 0;
198    
199     } else
200     strcpy(name, filename);
201    
202     // Load PSID file
203     if (!LoadPSIDFile(name))
204     return B_ERROR;
205    
206     // Select subsong if subsong number given
207     if (subsong_given)
208     SelectSong(song);
209    
210     return B_OK;
211     }
212    
213    
214     static status_t info(void *_sid, file_info *info)
215     {
216     strcpy(info->name,"");
217     strcpy(info->typedesc,"SID");
218     strcpy(info->mimetype,"audio/x-psid");
219     info->samplerate=44100;
220     info->bitrate=0;
221     info->numchannels=2;
222     info->granularity=4096;
223     info->framecount=0x7fffffff;
224     info->samplesize=2;
225     if(B_HOST_IS_LENDIAN)
226     info->byteorder=B_LITTLE_ENDIAN;
227     else
228     info->byteorder=B_BIG_ENDIAN;
229     info->sampleformat=B_LINEAR_SAMPLES;
230     info->flags=PLUGIN_FILELENGTH_UNKNOWN;
231    
232     return B_OK;
233     }
234    
235    
236     int32 read(void *,char *buf, ulong numframes)
237     {
238     SIDCalcBuffer((uint8*)buf, numframes*4);
239     return numframes;
240     }
241    
242