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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 61 - (hide annotations) (download)
Mon May 3 19:29:44 2004 UTC (19 years, 11 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 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 35 #include "network/lscpserver.h"
28 schoenebeck 9
29 schoenebeck 53 #if 0
30 schoenebeck 9 #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 schoenebeck 53 #endif
35 schoenebeck 9
36 schoenebeck 53 using namespace LinuxSampler;
37    
38     /*enum patch_format_t {
39 schoenebeck 9 patch_format_unknown,
40     patch_format_gig,
41     patch_format_dls
42 schoenebeck 53 } patch_format = patch_format_unknown;*/
43 schoenebeck 9
44 schoenebeck 53 Sampler* pSampler = NULL;
45 schoenebeck 35 LSCPServer* pLSCPServer = NULL;
46 schoenebeck 53 pthread_t signalhandlerthread;
47     /*AudioThread* pEngine = NULL;
48 schoenebeck 35 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 schoenebeck 53 bool run_server = false;*/
58 schoenebeck 9
59 schoenebeck 53
60 schoenebeck 9 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 schoenebeck 13 signalhandlerthread = pthread_self();
67 schoenebeck 9 signal(SIGINT, signal_handler);
68    
69     // parse and assign command line options
70 schoenebeck 53 //parse_options(argc, argv);
71 schoenebeck 9
72 schoenebeck 53 /*if (patch_format != patch_format_gig) {
73 schoenebeck 12 printf("Sorry only Gigasampler loading migrated in LinuxSampler so far, use --gig to load a .gig file!\n");
74 schoenebeck 20 printf("Use 'linuxsampler --help' to see all available options.\n");
75 schoenebeck 9 return EXIT_FAILURE;
76 schoenebeck 53 }*/
77 schoenebeck 9
78 schoenebeck 53 // create LinuxSampler instance
79     pSampler = new Sampler;
80    
81     // create an audio output device
82     /* bool no_jack = true;
83 schoenebeck 31 #if HAVE_JACK
84 schoenebeck 33 if (use_jack) {
85 schoenebeck 53 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 schoenebeck 33 }
95     #endif // HAVE_JACK
96 schoenebeck 53 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 schoenebeck 31 }
107 schoenebeck 53 dmsg(1,("OK\n"));*/
108 schoenebeck 9
109 schoenebeck 53 // start LSCP network server
110     dmsg(1,("Starting network server..."));
111     pLSCPServer = new LSCPServer(pSampler);
112     pLSCPServer->StartThread();
113 schoenebeck 12 dmsg(1,("OK\n"));
114 schoenebeck 9
115     printf("LinuxSampler initialization completed.\n");
116    
117 senoner 10 while(true) {
118 schoenebeck 53 /*printf("Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d, Unused: %3.3d)\r",
119 schoenebeck 35 pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax,
120     pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());
121 schoenebeck 53 fflush(stdout);*/
122 senoner 10 usleep(500000);
123     }
124    
125 schoenebeck 9 return EXIT_SUCCESS;
126     }
127    
128     void signal_handler(int signal) {
129 schoenebeck 20 if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {
130 schoenebeck 53 if (pLSCPServer) {
131     pLSCPServer->StopThread();
132     delete pLSCPServer;
133     }
134     if (pSampler) delete pSampler;
135 schoenebeck 9 printf("LinuxSampler stopped due to SIGINT\n");
136     exit(EXIT_SUCCESS);
137     }
138     }
139    
140 schoenebeck 53 /*void parse_options(int argc, char **argv) {
141 schoenebeck 9 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 schoenebeck 20 {"volume",1,0,0},
148 schoenebeck 9 {"dls",0,0,0},
149     {"gig",0,0,0},
150 schoenebeck 20 {"instrument",1,0,0},
151     {"inputclient",1,0,0},
152 schoenebeck 33 {"alsaout",1,0,0},
153     {"jackout",1,0,0},
154     {"samplerate",1,0,0},
155 schoenebeck 35 {"server",0,0,0},
156 schoenebeck 9 {"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 schoenebeck 33 case 0: // --numfragments
166 schoenebeck 9 num_fragments = atoi(optarg);
167     break;
168 schoenebeck 33 case 1: // --fragmentsize
169 schoenebeck 9 fragmentsize = atoi(optarg);
170     break;
171 schoenebeck 33 case 2: // --volume
172 schoenebeck 20 volume = atof(optarg);
173     break;
174 schoenebeck 33 case 3: // --dls
175 schoenebeck 9 patch_format = patch_format_dls;
176     break;
177 schoenebeck 33 case 4: // --gig
178 schoenebeck 9 patch_format = patch_format_gig;
179     break;
180 schoenebeck 33 case 5: // --instrument
181 schoenebeck 20 instrument_index = atoi(optarg);
182     break;
183 schoenebeck 33 case 6: // --inputclient
184 schoenebeck 20 input_client = optarg;
185     break;
186 schoenebeck 33 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 schoenebeck 35 case 10: // --server
214     run_server = true;
215     break;
216     case 11: // --help
217 schoenebeck 9 printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n");
218 schoenebeck 20 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 schoenebeck 9 printf("--numfragments sets the number of audio fragments\n");
223     printf("--fragmentsize sets the fragment size\n");
224 schoenebeck 20 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 schoenebeck 33 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 schoenebeck 35 printf("--server launch network server for remote control\n");
237 schoenebeck 33 exit(EXIT_SUCCESS);
238 schoenebeck 9 break;
239     }
240     }
241     }
242 schoenebeck 53 }*/

  ViewVC Help
Powered by ViewVC