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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 61 - (show annotations) (download)
Mon May 3 19:29:44 2004 UTC (19 years, 10 months ago) by schoenebeck
File size: 10350 byte(s)
forgot to update copyright header for 2004 for following files:
src/linuxsampler.cpp,
src/Sampler.h,
src/Sampler.cpp,
src/network/lscpscanner.cpp

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

  ViewVC Help
Powered by ViewVC