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

Annotation of /linuxsampler/trunk/src/linuxsampler.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 207 - (hide annotations) (download)
Thu Jul 15 21:51:15 2004 UTC (19 years, 8 months ago) by schoenebeck
File size: 10878 byte(s)
* src/linuxsampler.cpp: print out LinuxSampler version and show all
  registered MIDI input drivers
* renamed class 'InputOutputDevice' -> 'Device'

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

  ViewVC Help
Powered by ViewVC