Debian Codegraph @

sfconvert.cpp

raw symbols SCIP
1 //=============================================================================
2 // MuseScore sftools
3 //
4 // Copyright (C) 2010 Werner Schweer and others
5 //
6 // This work is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Library General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
10 //
11 // In addition, as a special exception, licensor gives permission to
12 // link the code of this work with the OpenSSL Library (or with modified
13 // versions of OpenSSL that use the same license as OpenSSL), and
14 // distribute linked combinations including the two. You must obey the
15 // GNU General Public License in all respects for all of the code used
16 // other than OpenSSL. If you modify this file, you may extend this
17 // exception to your version of the file, but you are not obligated to
18 // do so. If you do not wish to do so, delete this exception statement
19 // from your version. (This exception is necessary should this work be
20 // included in a GPL-licenced work.)
21 //
22 // See COPYING.LIB for the licence text and disclaimer of warranty.
23 //=============================================================================
24
25 #include <stdio.h>
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <QtCore/QFile>
30 #include <QtCore/QTime>
31 #include "sfont.h"
32
33 bool smallSf = false;
34
35 //---------------------------------------------------------
36 // usage
37 //---------------------------------------------------------
38
39 static void usage(const char* pname)
40 {
41 fprintf(stderr, "usage: %s [-flags] soundfont [outfile]\n", pname);
42 fprintf(stderr, " -z compress sf\n");
43 fprintf(stderr, " -q qq ogg quality\n");
44 fprintf(stderr, " -a nn amplification in dB before ogg compression\n");
45 fprintf(stderr, " -x xml output\n");
46 fprintf(stderr, " -c c output\n");
47 fprintf(stderr, " -p nn preset\n");
48 fprintf(stderr, " -d dump presets\n");
49 fprintf(stderr, " -s create small sf (one instrument/preset), pan to 0\n");
50 fprintf(stderr, " -S nn ogg serial number\n");
51 }
52
53 //---------------------------------------------------------
54 // main
55 //---------------------------------------------------------
56
57 int main(int argc, char* argv[])
58 {
59 bool xml = false;
60 bool code = false;
61 bool dump = false;
62 bool compress = false;
63 double oggQuality = 0.3;
64 double oggAmp = -1.0;
65 qint64 oggSerial = std::numeric_limits<qint64>::max();
66
67 QList<int> presets;
68
69 QTime t;
70 t.start();
71 fprintf(stderr, "%s: convert sound file\n", argv[0]);
72
73 int c;
74 while ((c = getopt(argc, argv, "xcp:dS:szq:a:")) != EOF) {
75 switch(c) {
76 case 'x':
77 xml = true;
78 break;
79 case 'c':
80 code = true;
81 break;
82 case 'p':
83 presets.append(atoi(optarg));
84 break;
85 case 'd':
86 dump = true;
87 break;
88 case 'S':
89 oggSerial = atoi(optarg);
90 break;
91 case 's':
92 smallSf = true;
93 break;
94 case 'z':
95 compress = true;
96 break;
97 case 'q':
98 oggQuality = atof(optarg);
99 break;
100 case 'a':
101 oggAmp = atof(optarg);
102 break;
103 default:
104 usage(argv[0]);
105 exit(1);
106 }
107 }
108 const char* pname = argv[0];
109
110 argc -= optind;
111 argv += optind;
112 if (xml && (argc != 2)) {
113 usage(pname);
114 exit(2);
115 }
116 if ((code && (argc != 1)) || (dump && argc != 1)) {
117 usage(pname);
118 exit(3);
119 }
120 if (!xml && !code && !dump && !compress) {
121 usage(pname);
122 exit(4);
123 }
124
125 SoundFont sf(argv[0]);
126
127 if (!sf.read()) {
128 fprintf(stderr, "sf read error\n");
129 exit(3);
130 }
131
132 if (code) {
133 if (presets.isEmpty())
134 sf.writeCode();
135 else
136 sf.writeCode(presets);
137 }
138 else if (dump)
139 sf.dumpPresets();
140 else if (compress) {
141 QFile fo(argv[1]);
142 if (!fo.open(QIODevice::WriteOnly)) {
143 fprintf(stderr, "cannot open <%s>\n", argv[2]);
144 exit(2);
145 }
146 if (xml)
147 sf.writeXml(&fo);
148 else
149 sf.write(&fo, oggQuality, oggAmp, oggSerial);
150 fo.close();
151 }
152 qDebug("Soundfont converted in: %d ms", t.elapsed());
153 return 0;
154 }