3
kmidi - a midi to wav converter
5
$Id: midiapplication.cpp,v 1.17 2000/12/10 14:48:57 yoush Exp $
7
Copyright 1997, 1998 Bernd Johannes Wuebben math.cornell.edu
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2, or (at your option)
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30
#include <kuniqueapp.h>
33
#include "midiapplication.h"
34
#include "kmidiframe.h"
39
#include <kaboutdata.h>
40
#include <kcmdlineargs.h>
46
//#include "constants.h"
51
MidiApplication * thisapp;
55
static KCmdLineOptions options[] =
57
{ "o <file>", I18N_NOOP("Output to another file (or device)."), 0 },
58
{ "O <mode>", I18N_NOOP("Select output mode and format (see below for list)."), 0 },
59
{ "s <freq>", I18N_NOOP("Set sampling frequency to f (Hz or kHz)."), 0 },
60
{ "a", I18N_NOOP("Enable the antialiasing filter."), 0 },
61
{ "f", I18N_NOOP("Enable fast decay mode."), 0 },
62
{ "d", I18N_NOOP("Enable dry mode."), 0 },
63
{ "p <n>", I18N_NOOP("Allow n-voice polyphony."), 0 },
64
{ "A <n>", I18N_NOOP("Amplify volume by n percent (may cause clipping)."), 0 },
65
{ "C <n>", I18N_NOOP("Set ratio of sampling and control frequencies."), 0 },
66
{ "# <n>", I18N_NOOP("Select patch set n."), 0 },
67
{ "E", I18N_NOOP("Effects filter."), 0 },
68
{ "L <dir>", I18N_NOOP("Append dir to search path."), 0 },
69
{ "c <file>", I18N_NOOP("Read extra configuration file."), 0 },
70
{ "I <n>", I18N_NOOP("Use program n as the default."), 0 },
71
{ "P <file>", I18N_NOOP("Use patch file for all programs."), 0 },
72
{ "D <n>", I18N_NOOP("Play drums on channel n."), 0 },
73
{ "Q <n>", I18N_NOOP("Ignore channel n."), 0 },
74
{ "R <n>", I18N_NOOP("Reverb options (1)(+2)(+4) [7]."), 0 },
75
{ "k <n>", I18N_NOOP("Resampling interpolation option (0-3) [1]."), 0 },
76
{ "r <n>", I18N_NOOP("Max ram to hold patches (in megabytes) [60]."), 0 },
77
{ "X <n>", I18N_NOOP("Midi expression is linear (0) or exponential (1-2) [1]."), 0 },
78
{ "V <n>", I18N_NOOP("Midi volume is linear (0) or exponential (1-2) [1]."), 0 },
79
{ "F", I18N_NOOP("Enable fast panning."), 0 },
80
{ "U", I18N_NOOP("Unload instruments from memory between MIDI files."), 0 },
81
{ "i <letter>", I18N_NOOP("Select user interface (letter=d(umb)/n(curses)/s(lang))."), 0 },
82
{ "B <n>", I18N_NOOP("Set number of buffer fragments."), 0 },
83
{ "+[file(s)]", I18N_NOOP("MIDI file(s) to play."), 0 },
84
{ 0, 0, 0 } // End of options.
87
MidiApplication::MidiApplication()
89
//fprintf(stderr,"new MidiApplication\n");
92
MidiApplication::~MidiApplication()
94
//fprintf(stderr,"delete MidiApplication\n");
97
bool MidiApplication::process(const QCString &fun, const QByteArray &data,
98
QCString &replyType, QByteArray &replyData)
100
QDataStream stream(data, IO_ReadOnly);
101
QDataStream stream2(replyData, IO_WriteOnly);
105
//fprintf(stderr, "MidiApplication::process\n");
106
if (fun == "play(QString)") {
110
kmidi->stopClicked();
111
kmidi->playlist->clear();
112
kmidi->playlist->append(arg);
113
kmidi->redoplaybox();
114
kmidi->singleplay = true;
118
return KUniqueApplication::process(fun, data, replyType, replyData);
120
/*#define DO_IT_MYSELF*/
122
int MidiApplication::newInstance()
128
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
130
//fprintf(stderr, "newInstance\n");
132
//fprintf(stderr, "kmidi exists!\n");
134
for (int i=0; i < args->count(); i++) {
135
QString filename = args->url(i).path();
136
//printf("NI:[%s]\n", filename.latin1());
138
file.setFile(filename);
139
if (!file.isReadable()) continue;
142
if (!f.open( IO_ReadOnly )) continue;
143
if (f.readBlock(mbuff, 4) != 4) {
144
//printf("couldn't read 4 bytes\n");
149
if (strcmp(mbuff, "MThd")) {
150
//printf("is not midi file\n");
156
file.setFile(filename);
157
//kmidi->playlist->insert(0, filename);
158
kmidi->playlist->append(file.absFilePath());
163
kmidi->restartPlaybox();
166
else fprintf(stderr, "NO kmidi!\n");
173
int createKApplication(int *argc, char ***argv)
175
int deref_argc = *argc;
176
char **deref_argv = new char*[deref_argc];
177
for(int i = 0; i < deref_argc; i++)
178
deref_argv[i] = (*argv)[i];
180
//fprintf(stderr,"making about\n");
181
// This should be static, because libkdecore do access KAboutData object later
182
// so it should not be destructed on return from this function
183
static KAboutData about( "kmidi", I18N_NOOP("KMidi"), "1.3alpha");
185
//fprintf(stderr,"init deref\n");
186
KCmdLineArgs::init(deref_argc, deref_argv, &about);
188
// can't delete this now, since Krash handler need my name
189
// delete [] deref_argv;
191
//fprintf(stderr,"add options 1\n");
192
KCmdLineArgs::addCmdLineOptions( options );
194
//fprintf(stderr,"add options ?\n");
195
KUniqueApplication::addCmdLineOptions();
197
//fprintf(stderr,"starting ?\n");
198
if (!MidiApplication::start()) {
202
//fprintf(stderr,"making thisapp\n");
203
thisapp = new MidiApplication();
208
int Launch_KMidi_Process(int _pipenumber) {
210
pipenumber = _pipenumber;
212
//fprintf(stderr,"Launch\n");
213
if (thisapp->isRestored()) {
215
while (KMidiFrame::canBeRestored(n)) {
216
//fprintf(stderr,"restoring\n");
217
(new KMidiFrame)->restore(n);
222
//fprintf(stderr,"make kmidiframe\n");
223
kmidiframe = new KMidiFrame( "_kmidiframe" );
224
//// KWM::setWmCommand(kmidiframe->winId(),"_kmidiframe");
225
// kmidiframe->setCaption( i18n("Midi Player") );
226
//kmidiframe->setCaption( QString::null );
227
//kmidiframe->setFontPropagation( QWidget::AllChildren );
228
//thisapp->setFont(default_font, TRUE);
229
//kmidiframe->setFont(default_font, TRUE);
239
#include "midiapplication.moc"