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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 211 - (hide annotations) (download)
Sun Jul 25 23:27:41 2004 UTC (19 years, 9 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 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 using namespace LinuxSampler;
32    
33 schoenebeck 211 Sampler* pSampler = NULL;
34     LSCPServer* pLSCPServer = NULL;
35     pthread_t signalhandlerthread;
36 schoenebeck 9
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 schoenebeck 13 signalhandlerthread = pthread_self();
44 schoenebeck 9 signal(SIGINT, signal_handler);
45    
46     // parse and assign command line options
47 schoenebeck 53 //parse_options(argc, argv);
48 schoenebeck 9
49 schoenebeck 207 dmsg(1,("LinuxSampler %s\n", VERSION));
50     dmsg(1,("Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck\n"));
51 schoenebeck 123
52 schoenebeck 53 // create LinuxSampler instance
53 schoenebeck 123 dmsg(1,("Creating Sampler..."));
54 schoenebeck 53 pSampler = new Sampler;
55 schoenebeck 123 dmsg(1,("OK\n"));
56 schoenebeck 53
57 schoenebeck 207 dmsg(1,("Registered MIDI input drivers: %s\n", MidiInputDeviceFactory::AvailableDriversAsString().c_str()));
58 schoenebeck 123 dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str()));
59    
60 schoenebeck 53 // start LSCP network server
61 schoenebeck 207 dmsg(1,("Starting LSCP network server..."));
62 schoenebeck 53 pLSCPServer = new LSCPServer(pSampler);
63     pLSCPServer->StartThread();
64 schoenebeck 211 pLSCPServer->WaitUntilInitialized();
65 schoenebeck 12 dmsg(1,("OK\n"));
66 schoenebeck 9
67     printf("LinuxSampler initialization completed.\n");
68    
69 senoner 10 while(true) {
70 schoenebeck 53 /*printf("Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d, Unused: %3.3d)\r",
71 schoenebeck 35 pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax,
72     pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());
73 schoenebeck 53 fflush(stdout);*/
74 senoner 10 usleep(500000);
75     }
76    
77 schoenebeck 9 return EXIT_SUCCESS;
78     }
79    
80     void signal_handler(int signal) {
81 schoenebeck 20 if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {
82 schoenebeck 53 if (pLSCPServer) {
83     pLSCPServer->StopThread();
84     delete pLSCPServer;
85     }
86     if (pSampler) delete pSampler;
87 schoenebeck 9 printf("LinuxSampler stopped due to SIGINT\n");
88     exit(EXIT_SUCCESS);
89     }
90     }
91    
92 schoenebeck 53 /*void parse_options(int argc, char **argv) {
93 schoenebeck 9 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 schoenebeck 20 {"volume",1,0,0},
100 schoenebeck 9 {"dls",0,0,0},
101     {"gig",0,0,0},
102 schoenebeck 20 {"instrument",1,0,0},
103     {"inputclient",1,0,0},
104 schoenebeck 33 {"alsaout",1,0,0},
105     {"jackout",1,0,0},
106     {"samplerate",1,0,0},
107 schoenebeck 35 {"server",0,0,0},
108 schoenebeck 9 {"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 schoenebeck 33 case 0: // --numfragments
118 schoenebeck 9 num_fragments = atoi(optarg);
119     break;
120 schoenebeck 33 case 1: // --fragmentsize
121 schoenebeck 9 fragmentsize = atoi(optarg);
122     break;
123 schoenebeck 33 case 2: // --volume
124 schoenebeck 20 volume = atof(optarg);
125     break;
126 schoenebeck 33 case 3: // --dls
127 schoenebeck 9 patch_format = patch_format_dls;
128     break;
129 schoenebeck 33 case 4: // --gig
130 schoenebeck 9 patch_format = patch_format_gig;
131     break;
132 schoenebeck 33 case 5: // --instrument
133 schoenebeck 20 instrument_index = atoi(optarg);
134     break;
135 schoenebeck 33 case 6: // --inputclient
136 schoenebeck 20 input_client = optarg;
137     break;
138 schoenebeck 33 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 schoenebeck 35 case 10: // --server
166     run_server = true;
167     break;
168     case 11: // --help
169 schoenebeck 9 printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n");
170 schoenebeck 20 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 schoenebeck 9 printf("--numfragments sets the number of audio fragments\n");
175     printf("--fragmentsize sets the fragment size\n");
176 schoenebeck 20 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 schoenebeck 33 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 schoenebeck 35 printf("--server launch network server for remote control\n");
189 schoenebeck 33 exit(EXIT_SUCCESS);
190 schoenebeck 9 break;
191     }
192     }
193     }
194 schoenebeck 53 }*/

  ViewVC Help
Powered by ViewVC