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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 271 - (show annotations) (download)
Fri Oct 8 20:51:39 2004 UTC (19 years, 6 months ago) by schoenebeck
File size: 11107 byte(s)
* libgig: fixed panorama value in DimensionRegion (invalid conversion
  from signed 7 bit to signed 8 bit)
* src/linuxsampler.cpp: stacktrace is now automatically shown on fatal
  errors (that is  segmentation faults, etc.), gdb should be installed for
  this to work
* gig::Voice: tiny accuracy fix of pan calculation
* replaced old pool classes by completely new ones which now offer
  Iterator abstraction

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/midi/MidiInputDeviceFactory.h"
28 #include "drivers/audio/AudioOutputDeviceFactory.h"
29 #include "network/lscpserver.h"
30 #include "common/stacktrace.h"
31
32 using namespace LinuxSampler;
33
34 Sampler* pSampler = NULL;
35 LSCPServer* pLSCPServer = NULL;
36 pthread_t main_thread;
37
38 void parse_options(int argc, char **argv);
39 void signal_handler(int signal);
40 void kill_app();
41
42 int main(int argc, char **argv) {
43
44 // initialize the stack trace mechanism with our binary file
45 StackTraceInit(argv[0], -1);
46
47 main_thread = pthread_self();
48
49 // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
50 signal(SIGINT, signal_handler);
51
52 // register signal handler for all unusual signals
53 // (we will print the stack trace and exit)
54 struct sigaction sact;
55 sigemptyset(&sact.sa_mask);
56 sact.sa_flags = 0;
57 sact.sa_handler = signal_handler;
58 sigaction(SIGSEGV, &sact, NULL);
59 sigaction(SIGBUS, &sact, NULL);
60 sigaction(SIGILL, &sact, NULL);
61 sigaction(SIGFPE, &sact, NULL);
62 sigaction(SIGUSR1, &sact, NULL);
63 sigaction(SIGUSR2, &sact, NULL);
64
65 // parse and assign command line options
66 //parse_options(argc, argv);
67
68 dmsg(1,("LinuxSampler %s\n", VERSION));
69 dmsg(1,("Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck\n"));
70
71 // create LinuxSampler instance
72 dmsg(1,("Creating Sampler..."));
73 pSampler = new Sampler;
74 dmsg(1,("OK\n"));
75
76 dmsg(1,("Registered MIDI input drivers: %s\n", MidiInputDeviceFactory::AvailableDriversAsString().c_str()));
77 dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str()));
78
79 // start LSCP network server
80 dmsg(1,("Starting LSCP network server (on TCP port %d)...", LSCP_PORT));
81 pLSCPServer = new LSCPServer(pSampler);
82 pLSCPServer->StartThread();
83 pLSCPServer->WaitUntilInitialized();
84 dmsg(1,("OK\n"));
85
86 printf("LinuxSampler initialization completed.\n");
87
88 while(true) {
89 /*printf("Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d, Unused: %3.3d)\r",
90 pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax,
91 pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());
92 fflush(stdout);*/
93 usleep(500000);
94 }
95
96 return EXIT_SUCCESS;
97 }
98
99 void signal_handler(int iSignal) {
100 switch (iSignal) {
101 case SIGINT: {
102 if (pthread_equal(pthread_self(), main_thread)) {
103 if (pLSCPServer) {
104 pLSCPServer->StopThread();
105 delete pLSCPServer;
106 }
107 if (pSampler) delete pSampler;
108 printf("LinuxSampler stopped due to SIGINT.\n");
109 exit(EXIT_SUCCESS);
110 }
111 return;
112 }
113 case SIGSEGV:
114 std::cerr << ">>> FATAL ERROR: Segmentation fault (SIGSEGV) occured! <<<\n" << std::flush;
115 break;
116 case SIGBUS:
117 std::cerr << ">>> FATAL ERROR: Access to undefined portion of a memory object (SIGBUS) occured! <<<\n" << std::flush;
118 break;
119 case SIGILL:
120 std::cerr << ">>> FATAL ERROR: Illegal instruction (SIGILL) occured! <<<\n" << std::flush;
121 break;
122 case SIGFPE:
123 std::cerr << ">>> FATAL ERROR: Erroneous arithmetic operation (SIGFPE) occured! <<<\n" << std::flush;
124 break;
125 case SIGUSR1:
126 std::cerr << ">>> User defined signal 1 (SIGUSR1) received <<<\n" << std::flush;
127 break;
128 case SIGUSR2:
129 std::cerr << ">>> User defined signal 2 (SIGUSR2) received <<<\n" << std::flush;
130 break;
131 default: { // this should never happen, as we register for the signals we want
132 std::cerr << ">>> FATAL ERROR: Unknown signal received! <<<\n" << std::flush;
133 break;
134 }
135 }
136 signal(iSignal, SIG_DFL); // Reinstall default handler to prevent race conditions
137 std::cerr << "Showing stack trace...\n" << std::flush;
138 StackTrace();
139 sleep(2);
140 std::cerr << "Killing LinuxSampler...\n" << std::flush;
141 kill_app(); // Use abort() if we want to generate a core dump.
142 }
143
144 void kill_app() {
145 kill(main_thread, SIGKILL);
146 }
147
148 /*void parse_options(int argc, char **argv) {
149 int res;
150 int option_index = 0;
151 static struct option long_options[] =
152 {
153 {"numfragments",1,0,0},
154 {"fragmentsize",1,0,0},
155 {"volume",1,0,0},
156 {"dls",0,0,0},
157 {"gig",0,0,0},
158 {"instrument",1,0,0},
159 {"inputclient",1,0,0},
160 {"alsaout",1,0,0},
161 {"jackout",1,0,0},
162 {"samplerate",1,0,0},
163 {"server",0,0,0},
164 {"help",0,0,0},
165 {0,0,0,0}
166 };
167
168 while (true) {
169 res = getopt_long_only(argc, argv, "", long_options, &option_index);
170 if(res == -1) break;
171 if (res == 0) {
172 switch(option_index) {
173 case 0: // --numfragments
174 num_fragments = atoi(optarg);
175 break;
176 case 1: // --fragmentsize
177 fragmentsize = atoi(optarg);
178 break;
179 case 2: // --volume
180 volume = atof(optarg);
181 break;
182 case 3: // --dls
183 patch_format = patch_format_dls;
184 break;
185 case 4: // --gig
186 patch_format = patch_format_gig;
187 break;
188 case 5: // --instrument
189 instrument_index = atoi(optarg);
190 break;
191 case 6: // --inputclient
192 input_client = optarg;
193 break;
194 case 7: // --alsaout
195 alsaout = optarg;
196 use_jack = false; // If this option is specified do not connect to jack
197 break;
198 case 8: { // --jackout
199 try {
200 String arg(optarg);
201 // remove outer apostrophes
202 arg = arg.substr(arg.find('\'') + 1, arg.rfind('\'') - (arg.find('\'') + 1));
203 // split in two arguments
204 jack_playback[0] = arg.substr(0, arg.find("\' "));
205 jack_playback[1] = arg.substr(arg.find("\' ") + 2, arg.size() - (arg.find("\' ") + 2));
206 // remove inner apostrophes
207 jack_playback[0] = jack_playback[0].substr(0, jack_playback[0].find('\''));
208 jack_playback[1] = jack_playback[1].substr(jack_playback[1].find('\'') + 1, jack_playback[1].size() - jack_playback[1].find('\''));
209 // this is the default but set it up anyway in case alsa_card was also used.
210 use_jack = true;
211 }
212 catch (...) {
213 fprintf(stderr, "Invalid argument '%s' for parameter --jackout\n", optarg);
214 exit(EXIT_FAILURE);
215 }
216 break;
217 }
218 case 9: // --samplerate
219 samplerate = atoi(optarg);
220 break;
221 case 10: // --server
222 run_server = true;
223 break;
224 case 11: // --help
225 printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n");
226 printf("--gig loads a Gigasampler instrument\n");
227 printf("--dls loads a DLS instrument\n");
228 printf("--instrument index of the instrument in the instrument file if it\n");
229 printf(" contains more than one (default: 0)\n");
230 printf("--numfragments sets the number of audio fragments\n");
231 printf("--fragmentsize sets the fragment size\n");
232 printf("--volume sets global volume gain factor (a value > 1.0 means\n");
233 printf(" amplification, a value < 1.0 means attenuation,\n");
234 printf(" default: 0.25)\n");
235 printf("--inputclient connects to an Alsa sequencer input client on startup\n");
236 printf(" (e.g. 64:0 to connect to a client with ID 64 and port 0)\n");
237 printf("--alsaout connects to the given Alsa sound device on startup\n");
238 printf(" (e.g. 0,0 to connect to hw:0,0 or plughw:0,0)\n");
239 printf("--jackout connects to the given Jack playback ports on startup\n");
240 printf(" (e.g. \"\'alsa_pcm:playback_1\' \'alsa_pcm:playback_2\'\"\n");
241 printf(" in case of stereo output)\n");
242 printf("--samplerate sets sample rate if supported by audio output system\n");
243 printf(" (e.g. 44100)\n");
244 printf("--server launch network server for remote control\n");
245 exit(EXIT_SUCCESS);
246 break;
247 }
248 }
249 }
250 }*/

  ViewVC Help
Powered by ViewVC