Debian Codegraph @

src/csoundoptions.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2010 Andres Cabrera
3 [email protected]
4
5 This file is part of CsoundQt.
6
7 CsoundQt is free software; you can redistribute it
8 and/or modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 CsoundQt 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 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with Csound; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA
21 */
22
23 #include "csoundoptions.h"
24 #include "configlists.h"
25 #include "types.h"
26
27 #include <QDir> // for static QDir::separator()
28 #include <QDebug>
29 #include <cstdlib> // for calloc
30
31 CsoundOptions::CsoundOptions(ConfigLists *configlists) :
32 m_configlists(configlists)
33 {
34 m_jackNameSize = 16; //a small default
35
36 rt = true;
37
38 enableFLTK = true;
39 bufferSize = 1024;
40 bufferSizeActive = false;
41 HwBufferSize = 2048;
42 HwBufferSizeActive = false;
43 dither = false;
44 newParser = false;
45 multicore = false;
46 numThreads = 1;
47 realtimeFlag = false;
48 sampleAccurateFlag = false;
49 additionalFlags = "";
50 additionalFlagsActive = false;
51
52 fileUseOptions = false;
53 fileOverrideOptions = false;
54 fileAskFilename = false;
55 filePlayFinished = false;
56 fileFileType = 0;
57 fileSampleFormat = 0;
58 fileInputFilenameActive = false;
59 fileInputFilename = "";
60 fileOutputFilenameActive = false;
61 fileOutputFilename = "";
62
63 sampleFormat = 0;
64
65 rtUseOptions = true;
66 rtOverrideOptions = false;
67 rtAudioModule = "";
68 rtInputDevice = "adc";
69 rtOutputDevice = "dac";
70 rtJackName = "*";
71 rtMidiModule = "";
72 rtMidiInputDevice = "0";
73 rtMidiOutputDevice = "0";
74 useSystemSamplerate = false;
75 overrideNumChannels = false;
76 numChannels = 2;
77 numInputChannels = 2;
78
79 useLimiter = csoundGetVersion() >= 6160;
80 limitValue = 1.0;
81
82 useCsoundMidi = false;
83 simultaneousRun = true; // Allow running various instances (tabs) simultaneously.
84 checkSyntaxOnly = false;
85 checkSyntaxBeforeRun = false;
86
87 csdocdir = "";
88 opcodedir = "";
89 opcodedirActive = false;
90 opcodedir64 = "";
91 opcodedir64Active = false;
92 opcode6dir64 = "";
93 opcode6dir64Active = false;
94 sadir = "";
95 sadirActive = false;
96 ssdir = "";
97 ssdirActive = false;
98 sfdir = "";
99 sfdirActive = false;
100 incdir = "";
101 incdirActive = false;
102 }
103
104 QString CsoundOptions::generateCmdLineFlags()
105 {
106 return generateCmdLineFlagsList().join(" ");
107 }
108
109 QStringList CsoundOptions::generateCmdLineFlagsList()
110 {
111 QStringList opts;
112 if (bufferSizeActive)
113 opts << "-b" + QString::number(bufferSize);
114 if (HwBufferSizeActive)
115 opts << "-B" + QString::number(HwBufferSize);
116 if (additionalFlagsActive && !additionalFlags.trimmed().isEmpty()) {
117 QStringList addFlags = additionalFlags.split(QRegExp("[\\s]"),QString::SkipEmptyParts);
118 foreach (QString f, addFlags) {
119 QDEBUG << "Additional Flags:" << additionalFlags;
120 opts << f;
121 }
122 }
123 if (dither)
124 opts << " -Z";
125 if (multicore)
126 opts << "-j" + QString::number(numThreads);
127 if (realtimeFlag)
128 opts << "--realtime";
129 if (sampleAccurateFlag)
130 opts << "--sample-accurate";
131 if (checkSyntaxOnly)
132 opts << "--syntax-check-only";
133 if (rt && rtUseOptions) {
134 if (rtOverrideOptions)
135 opts << "-+ignore_csopts=1";
136 if (m_configlists->rtAudioNames.indexOf(rtAudioModule) >= 0
137 && rtAudioModule != "none") {
138 opts << "-+rtaudio=" + rtAudioModule;
139 if (rtInputDevice != "") {
140 opts << "-i" + rtInputDevice;
141 }
142 opts << "-o" + (rtOutputDevice == "" ? "dac":rtOutputDevice);
143 if (rtJackName != "" && rtAudioModule == "jack") {
144 QString jackName = rtJackName;
145 if (jackName.contains("*")) {
146 // auto base = fileName1.mid(fileName1.lastIndexOf(QDir::separator())+1);
147 auto base = docName.mid(docName.lastIndexOf(QDir::separator())+1);
148 jackName.replace("*", base);
149 jackName.replace(" ", "_");
150 }
151 if (jackName.size() > m_jackNameSize) {
152 jackName = jackName.left(m_jackNameSize);
153 }
154 opts << "-+jack_client=" + jackName;
155 }
156 }
157 if (useCsoundMidi &&
158 m_configlists->rtMidiNames.indexOf(rtMidiModule) >= 0 &&
159 rtMidiModule != "none") {
160 opts << "-+rtmidi=" + rtMidiModule;
161 if (rtMidiInputDevice != "")
162 opts << "-M" + rtMidiInputDevice;
163 if (rtMidiOutputDevice != "")
164 opts << "-Q" + rtMidiOutputDevice;
165 }
166 if (useSystemSamplerate)
167 opts << "--use-system-sr";
168 else if(samplerate > 0) {
169 opts << "--sample-rate=" + QString::number(samplerate);
170 }
171 if (overrideNumChannels) {
172 if(numChannels <= 0) {
173 qDebug("Setting nchnls, but numChannels is invalid: %d", numChannels);
174 } else
175 opts << ("--nchnls=" + QString::number(numChannels));
176 if(numInputChannels < 0) {
177 qDebug("Setting nchnls_i, but numInputChannels is invalid: %d", numInputChannels);
178 } else {
179 QDEBUG << "nchnls_i" << numInputChannels;
180 opts << ("--nchnls_i=" + QString::number(numInputChannels));
181 }
182
183 }
184 if (useLimiter) {
185 opts << "--limiter="+QString::number(limitValue);
186 }
187
188 // add --print_version by default if Csound 6.17 or later
189 if ( csoundGetVersion() >=6170 ) {
190 opts << "--print_version";
191 }
192 }
193 else {
194 opts << "--format=" + m_configlists->fileTypeNames[fileFileType]
195 + ":" + m_configlists->fileFormatFlags[fileSampleFormat];
196 if (fileInputFilenameActive)
197 opts << "-i" + fileInputFilename + "";
198 if (fileOutputFilenameActive || fileAskFilename) {
199 opts << "-o" + fileOutputFilename + "";
200 }
201 }
202 // These lines break setting of variables. Are they actually needed here for some reason?
203 // if (sadirActive)
204 // list << "--env:SADIR='" + sadir + "'";
205 // if (ssdirActive)
206 // list << "--env:SSDIR='" + ssdir + "'";
207 // if (sfdirActive)
208 // list << "--env:SFDIR='" + sfdir + "'";
209 // if (incdirActive)
210 // list << "--env:INCDIR='" + incdir + "'";
211 opts << "--env:CSNOSTOP=yes";
212 qDebug() << ">>>>> Csound options: " << opts;
213 return opts;
214 }
215
216 int CsoundOptions::generateCmdLine(char **argv)
217 {
218 int index = 0;
219 argv[index] = (char *) calloc(7, sizeof(char));
220 strcpy((char *)argv[index++], "csound");
221 QStringList indFlags = generateCmdLineFlagsList();
222 foreach (QString flag, indFlags) {
223 flag = flag.simplified();
224 argv[index] = (char *) calloc(flag.size()+1, sizeof(char));
225 strcpy(argv[index], flag.toLocal8Bit());
226 index++;
227 }
228 argv[index] = (char *) calloc(fileName1.size()+1, sizeof(char));
229 strcpy(argv[index++],fileName1.toLocal8Bit());
230 if (fileName2 != "") {
231 argv[index] = (char *) calloc(fileName2.size()+1, sizeof(char));
232 strcpy(argv[index++],fileName2.toLocal8Bit());
233 }
234 return index;
235 }
236
237 void CsoundOptions::setJackNameSize(int size)
238 {
239 m_jackNameSize = size;
240 }