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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 211 - (show annotations) (download)
Sun Jul 25 23:27:41 2004 UTC (19 years, 8 months ago) by schoenebeck
File size: 8929 byte(s)
* src/linuxsampler.cpp: tidied up a bit, "initialization completed"
  message shown only after the server is actually running
* src/testcases/: print the name of each test suite before running the
  tests of the suite, added first tests against the LSCP server using a
  socket connection to the LSCP server (tests for the following LSCP
  commands: "ADD CHANNEL", "GET CHANNELS", "REMOVE CHANNEL")

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
31 using namespace LinuxSampler;
32
33 Sampler* pSampler = NULL;
34 LSCPServer* pLSCPServer = NULL;
35 pthread_t signalhandlerthread;
36
37 void parse_options(int argc, char **argv);
38 void signal_handler(int signal);
39
40 int main(int argc, char **argv) {
41
42 // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
43 signalhandlerthread = pthread_self();
44 signal(SIGINT, signal_handler);
45
46 // parse and assign command line options
47 //parse_options(argc, argv);
48
49 dmsg(1,("LinuxSampler %s\n", VERSION));
50 dmsg(1,("Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck\n"));
51
52 // create LinuxSampler instance
53 dmsg(1,("Creating Sampler..."));
54 pSampler = new Sampler;
55 dmsg(1,("OK\n"));
56
57 dmsg(1,("Registered MIDI input drivers: %s\n", MidiInputDeviceFactory::AvailableDriversAsString().c_str()));
58 dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str()));
59
60 // start LSCP network server
61 dmsg(1,("Starting LSCP network server..."));
62 pLSCPServer = new LSCPServer(pSampler);
63 pLSCPServer->StartThread();
64 pLSCPServer->WaitUntilInitialized();
65 dmsg(1,("OK\n"));
66
67 printf("LinuxSampler initialization completed.\n");
68
69 while(true) {
70 /*printf("Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d, Unused: %3.3d)\r",
71 pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax,
72 pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());
73 fflush(stdout);*/
74 usleep(500000);
75 }
76
77 return EXIT_SUCCESS;
78 }
79
80 void signal_handler(int signal) {
81 if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {
82 if (pLSCPServer) {
83 pLSCPServer->StopThread();
84 delete pLSCPServer;
85 }
86 if (pSampler) delete pSampler;
87 printf("LinuxSampler stopped due to SIGINT\n");
88 exit(EXIT_SUCCESS);
89 }
90 }
91
92 /*void parse_options(int argc, char **argv) {
93 int res;
94 int option_index = 0;
95 static struct option long_options[] =
96 {
97 {"numfragments",1,0,0},
98 {"fragmentsize",1,0,0},
99 {"volume",1,0,0},
100 {"dls",0,0,0},
101 {"gig",0,0,0},
102 {"instrument",1,0,0},
103 {"inputclient",1,0,0},
104 {"alsaout",1,0,0},
105 {"jackout",1,0,0},
106 {"samplerate",1,0,0},
107 {"server",0,0,0},
108 {"help",0,0,0},
109 {0,0,0,0}
110 };
111
112 while (true) {
113 res = getopt_long_only(argc, argv, "", long_options, &option_index);
114 if(res == -1) break;
115 if (res == 0) {
116 switch(option_index) {
117 case 0: // --numfragments
118 num_fragments = atoi(optarg);
119 break;
120 case 1: // --fragmentsize
121 fragmentsize = atoi(optarg);
122 break;
123 case 2: // --volume
124 volume = atof(optarg);
125 break;
126 case 3: // --dls
127 patch_format = patch_format_dls;
128 break;
129 case 4: // --gig
130 patch_format = patch_format_gig;
131 break;
132 case 5: // --instrument
133 instrument_index = atoi(optarg);
134 break;
135 case 6: // --inputclient
136 input_client = optarg;
137 break;
138 case 7: // --alsaout
139 alsaout = optarg;
140 use_jack = false; // If this option is specified do not connect to jack
141 break;
142 case 8: { // --jackout
143 try {
144 String arg(optarg);
145 // remove outer apostrophes
146 arg = arg.substr(arg.find('\'') + 1, arg.rfind('\'') - (arg.find('\'') + 1));
147 // split in two arguments
148 jack_playback[0] = arg.substr(0, arg.find("\' "));
149 jack_playback[1] = arg.substr(arg.find("\' ") + 2, arg.size() - (arg.find("\' ") + 2));
150 // remove inner apostrophes
151 jack_playback[0] = jack_playback[0].substr(0, jack_playback[0].find('\''));
152 jack_playback[1] = jack_playback[1].substr(jack_playback[1].find('\'') + 1, jack_playback[1].size() - jack_playback[1].find('\''));
153 // this is the default but set it up anyway in case alsa_card was also used.
154 use_jack = true;
155 }
156 catch (...) {
157 fprintf(stderr, "Invalid argument '%s' for parameter --jackout\n", optarg);
158 exit(EXIT_FAILURE);
159 }
160 break;
161 }
162 case 9: // --samplerate
163 samplerate = atoi(optarg);
164 break;
165 case 10: // --server
166 run_server = true;
167 break;
168 case 11: // --help
169 printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n");
170 printf("--gig loads a Gigasampler instrument\n");
171 printf("--dls loads a DLS instrument\n");
172 printf("--instrument index of the instrument in the instrument file if it\n");
173 printf(" contains more than one (default: 0)\n");
174 printf("--numfragments sets the number of audio fragments\n");
175 printf("--fragmentsize sets the fragment size\n");
176 printf("--volume sets global volume gain factor (a value > 1.0 means\n");
177 printf(" amplification, a value < 1.0 means attenuation,\n");
178 printf(" default: 0.25)\n");
179 printf("--inputclient connects to an Alsa sequencer input client on startup\n");
180 printf(" (e.g. 64:0 to connect to a client with ID 64 and port 0)\n");
181 printf("--alsaout connects to the given Alsa sound device on startup\n");
182 printf(" (e.g. 0,0 to connect to hw:0,0 or plughw:0,0)\n");
183 printf("--jackout connects to the given Jack playback ports on startup\n");
184 printf(" (e.g. \"\'alsa_pcm:playback_1\' \'alsa_pcm:playback_2\'\"\n");
185 printf(" in case of stereo output)\n");
186 printf("--samplerate sets sample rate if supported by audio output system\n");
187 printf(" (e.g. 44100)\n");
188 printf("--server launch network server for remote control\n");
189 exit(EXIT_SUCCESS);
190 break;
191 }
192 }
193 }
194 }*/

  ViewVC Help
Powered by ViewVC