/[svn]/linuxsampler/trunk/src/linuxsampler.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/linuxsampler.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 203 - (show annotations) (download)
Tue Jul 13 22:44:13 2004 UTC (19 years, 9 months ago) by schoenebeck
File size: 10580 byte(s)
forgot to change some things which was mandatory due to the recent
directory movements ('/src/audiodriver' -> '/src/drivers/audio',
'/src/mididriver' -> '/src/drivers/midi')

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20 * MA 02111-1307 USA *
21 ***************************************************************************/
22
23 #include <getopt.h>
24 #include <signal.h>
25
26 #include "Sampler.h"
27 #include "drivers/audio/AudioOutputDeviceFactory.h"
28 #include "network/lscpserver.h"
29
30 #if 0
31 #define AUDIO_CHANNELS 2 // stereo
32 #define AUDIO_FRAGMENTS 3 // 3 fragments, if it does not work set it to 2
33 #define AUDIO_FRAGMENTSIZE 512 // each fragment has 512 frames
34 #define AUDIO_SAMPLERATE 44100 // Hz
35 #endif
36
37 using namespace LinuxSampler;
38
39 /*enum patch_format_t {
40 patch_format_unknown,
41 patch_format_gig,
42 patch_format_dls
43 } patch_format = patch_format_unknown;*/
44
45 Sampler* pSampler = NULL;
46 LSCPServer* pLSCPServer = NULL;
47 pthread_t signalhandlerthread;
48 /*AudioThread* pEngine = NULL;
49 uint instrument_index = 0;
50 double volume = 0.25;
51 int num_fragments = AUDIO_FRAGMENTS;
52 int fragmentsize = AUDIO_FRAGMENTSIZE;
53 uint samplerate = AUDIO_SAMPLERATE;
54 String input_client;
55 String alsaout = "0,0"; // default card
56 String jack_playback[2] = { "", "" };
57 bool use_jack = true;
58 bool run_server = false;*/
59
60
61 void parse_options(int argc, char **argv);
62 void signal_handler(int signal);
63
64 int main(int argc, char **argv) {
65
66 // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
67 signalhandlerthread = pthread_self();
68 signal(SIGINT, signal_handler);
69
70 // parse and assign command line options
71 //parse_options(argc, argv);
72
73 /*if (patch_format != patch_format_gig) {
74 printf("Sorry only Gigasampler loading migrated in LinuxSampler so far, use --gig to load a .gig file!\n");
75 printf("Use 'linuxsampler --help' to see all available options.\n");
76 return EXIT_FAILURE;
77 }*/
78
79
80 // create LinuxSampler instance
81 dmsg(1,("Creating Sampler..."));
82 pSampler = new Sampler;
83 dmsg(1,("OK\n"));
84
85 dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str()));
86
87 // create an audio output device
88 /* bool no_jack = true;
89 #if HAVE_JACK
90 if (use_jack) {
91 dmsg(1,("Creating audio output device (Jack)..."));
92 try {
93 pSampler->CreateAudioOutputDevice(audio_output_type_jack);
94 no_jack = false;
95 }
96 catch (AudioOutputException aoe) {
97 aoe.PrintMessage();
98 dmsg(1,("Trying to create Alsa output device instead.\n"));
99 }
100 }
101 #endif // HAVE_JACK
102 if (no_jack) {
103 dmsg(1,("Creating audio output device (Alsa)..."));
104 try {
105 pSampler->CreateAudioOutputDevice(audio_output_type_alsa);
106 }
107 catch (AudioOutputException aoe) {
108 aoe.PrintMessage();
109 dmsg(1,("Trying to create Alsa output device instead.\n"));
110 return EXIT_FAILURE;
111 }
112 }
113 dmsg(1,("OK\n"));*/
114
115 // start LSCP network server
116 dmsg(1,("Starting network server..."));
117 pLSCPServer = new LSCPServer(pSampler);
118 pLSCPServer->StartThread();
119 dmsg(1,("OK\n"));
120
121 printf("LinuxSampler initialization completed.\n");
122
123 while(true) {
124 /*printf("Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d, Unused: %3.3d)\r",
125 pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax,
126 pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());
127 fflush(stdout);*/
128 usleep(500000);
129 }
130
131 return EXIT_SUCCESS;
132 }
133
134 void signal_handler(int signal) {
135 if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {
136 if (pLSCPServer) {
137 pLSCPServer->StopThread();
138 delete pLSCPServer;
139 }
140 if (pSampler) delete pSampler;
141 printf("LinuxSampler stopped due to SIGINT\n");
142 exit(EXIT_SUCCESS);
143 }
144 }
145
146 /*void parse_options(int argc, char **argv) {
147 int res;
148 int option_index = 0;
149 static struct option long_options[] =
150 {
151 {"numfragments",1,0,0},
152 {"fragmentsize",1,0,0},
153 {"volume",1,0,0},
154 {"dls",0,0,0},
155 {"gig",0,0,0},
156 {"instrument",1,0,0},
157 {"inputclient",1,0,0},
158 {"alsaout",1,0,0},
159 {"jackout",1,0,0},
160 {"samplerate",1,0,0},
161 {"server",0,0,0},
162 {"help",0,0,0},
163 {0,0,0,0}
164 };
165
166 while (true) {
167 res = getopt_long_only(argc, argv, "", long_options, &option_index);
168 if(res == -1) break;
169 if (res == 0) {
170 switch(option_index) {
171 case 0: // --numfragments
172 num_fragments = atoi(optarg);
173 break;
174 case 1: // --fragmentsize
175 fragmentsize = atoi(optarg);
176 break;
177 case 2: // --volume
178 volume = atof(optarg);
179 break;
180 case 3: // --dls
181 patch_format = patch_format_dls;
182 break;
183 case 4: // --gig
184 patch_format = patch_format_gig;
185 break;
186 case 5: // --instrument
187 instrument_index = atoi(optarg);
188 break;
189 case 6: // --inputclient
190 input_client = optarg;
191 break;
192 case 7: // --alsaout
193 alsaout = optarg;
194 use_jack = false; // If this option is specified do not connect to jack
195 break;
196 case 8: { // --jackout
197 try {
198 String arg(optarg);
199 // remove outer apostrophes
200 arg = arg.substr(arg.find('\'') + 1, arg.rfind('\'') - (arg.find('\'') + 1));
201 // split in two arguments
202 jack_playback[0] = arg.substr(0, arg.find("\' "));
203 jack_playback[1] = arg.substr(arg.find("\' ") + 2, arg.size() - (arg.find("\' ") + 2));
204 // remove inner apostrophes
205 jack_playback[0] = jack_playback[0].substr(0, jack_playback[0].find('\''));
206 jack_playback[1] = jack_playback[1].substr(jack_playback[1].find('\'') + 1, jack_playback[1].size() - jack_playback[1].find('\''));
207 // this is the default but set it up anyway in case alsa_card was also used.
208 use_jack = true;
209 }
210 catch (...) {
211 fprintf(stderr, "Invalid argument '%s' for parameter --jackout\n", optarg);
212 exit(EXIT_FAILURE);
213 }
214 break;
215 }
216 case 9: // --samplerate
217 samplerate = atoi(optarg);
218 break;
219 case 10: // --server
220 run_server = true;
221 break;
222 case 11: // --help
223 printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n");
224 printf("--gig loads a Gigasampler instrument\n");
225 printf("--dls loads a DLS instrument\n");
226 printf("--instrument index of the instrument in the instrument file if it\n");
227 printf(" contains more than one (default: 0)\n");
228 printf("--numfragments sets the number of audio fragments\n");
229 printf("--fragmentsize sets the fragment size\n");
230 printf("--volume sets global volume gain factor (a value > 1.0 means\n");
231 printf(" amplification, a value < 1.0 means attenuation,\n");
232 printf(" default: 0.25)\n");
233 printf("--inputclient connects to an Alsa sequencer input client on startup\n");
234 printf(" (e.g. 64:0 to connect to a client with ID 64 and port 0)\n");
235 printf("--alsaout connects to the given Alsa sound device on startup\n");
236 printf(" (e.g. 0,0 to connect to hw:0,0 or plughw:0,0)\n");
237 printf("--jackout connects to the given Jack playback ports on startup\n");
238 printf(" (e.g. \"\'alsa_pcm:playback_1\' \'alsa_pcm:playback_2\'\"\n");
239 printf(" in case of stereo output)\n");
240 printf("--samplerate sets sample rate if supported by audio output system\n");
241 printf(" (e.g. 44100)\n");
242 printf("--server launch network server for remote control\n");
243 exit(EXIT_SUCCESS);
244 break;
245 }
246 }
247 }
248 }*/

  ViewVC Help
Powered by ViewVC