~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to kmidi/midiapplication.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
   kmidi - a midi to wav converter
4
 
 
5
 
   $Id: midiapplication.cpp,v 1.17 2000/12/10 14:48:57 yoush Exp $
6
 
 
7
 
   Copyright 1997, 1998 Bernd Johannes Wuebben math.cornell.edu
8
 
 
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)
12
 
   any later version.
13
 
 
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.
18
 
 
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.
22
 
 
23
 
 
24
 
 */
25
 
 
26
 
#include <stdio.h>
27
 
#include <stdlib.h>
28
 
#include <unistd.h>
29
 
 
30
 
#include <kuniqueapp.h>
31
 
 
32
 
#include "kmidi.h"
33
 
#include "midiapplication.h"
34
 
#include "kmidiframe.h"
35
 
 
36
 
#include <kstddirs.h>
37
 
#include <kglobal.h>
38
 
#include <klocale.h>
39
 
#include <kaboutdata.h>
40
 
#include <kcmdlineargs.h>
41
 
 
42
 
#include "config.h"
43
 
#include "output.h"
44
 
#include "instrum.h"
45
 
#include "playmidi.h"
46
 
//#include "constants.h"
47
 
#include "controls.h"
48
 
#include "ctl.h"
49
 
 
50
 
 
51
 
MidiApplication * thisapp;
52
 
 
53
 
int pipenumber;
54
 
 
55
 
static KCmdLineOptions options[] = 
56
 
{
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.
85
 
};
86
 
 
87
 
MidiApplication::MidiApplication()
88
 
{
89
 
//fprintf(stderr,"new MidiApplication\n");
90
 
}
91
 
 
92
 
MidiApplication::~MidiApplication()
93
 
{
94
 
//fprintf(stderr,"delete MidiApplication\n");
95
 
}
96
 
 
97
 
bool MidiApplication::process(const QCString &fun, const QByteArray &data,
98
 
                        QCString &replyType, QByteArray &replyData)
99
 
{
100
 
  QDataStream stream(data, IO_ReadOnly);
101
 
  QDataStream stream2(replyData, IO_WriteOnly);
102
 
  QString res;
103
 
//  int exitcode;
104
 
 
105
 
//fprintf(stderr, "MidiApplication::process\n");
106
 
  if (fun == "play(QString)") {
107
 
    QString arg;
108
 
    stream >> arg;
109
 
    replyType = "void";
110
 
    kmidi->stopClicked();
111
 
    kmidi->playlist->clear();
112
 
    kmidi->playlist->append(arg);
113
 
    kmidi->redoplaybox();
114
 
    kmidi->singleplay = true;
115
 
    kmidi->setSong(0);
116
 
    return true;
117
 
  } 
118
 
  return KUniqueApplication::process(fun, data, replyType, replyData);
119
 
}
120
 
/*#define DO_IT_MYSELF*/
121
 
 
122
 
int MidiApplication::newInstance()
123
 
{
124
 
#ifndef DO_IT_MYSELF
125
 
    char mbuff[5];
126
 
    int newones = 0;
127
 
    QFileInfo file;
128
 
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
129
 
 
130
 
//fprintf(stderr, "newInstance\n");
131
 
    if (kmidi) {
132
 
//fprintf(stderr, "kmidi exists!\n");
133
 
 
134
 
        for (int i=0; i < args->count(); i++) {
135
 
            QString filename = args->url(i).path();
136
 
//printf("NI:[%s]\n", filename.latin1());
137
 
 
138
 
            file.setFile(filename);
139
 
            if (!file.isReadable()) continue;
140
 
 
141
 
            QFile f(filename);
142
 
            if (!f.open( IO_ReadOnly )) continue;
143
 
            if (f.readBlock(mbuff, 4) != 4) {
144
 
//printf("couldn't read 4 bytes\n");
145
 
                f.close();
146
 
                continue;
147
 
            }
148
 
            mbuff[4] = '\0';
149
 
            if (strcmp(mbuff, "MThd")) {
150
 
//printf("is not midi file\n");
151
 
                f.close();
152
 
                continue;
153
 
            }
154
 
            f.close();
155
 
 
156
 
            file.setFile(filename);
157
 
            //kmidi->playlist->insert(0, filename);
158
 
            kmidi->playlist->append(file.absFilePath());
159
 
            newones++;
160
 
        }
161
 
 
162
 
        if (newones) {
163
 
            kmidi->restartPlaybox();
164
 
        }
165
 
    }
166
 
    else fprintf(stderr, "NO kmidi!\n");
167
 
#endif
168
 
    return 0;
169
 
}
170
 
 
171
 
 
172
 
 
173
 
int createKApplication(int *argc, char ***argv) 
174
 
{
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];
179
 
 
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");
184
 
 
185
 
//fprintf(stderr,"init deref\n");
186
 
       KCmdLineArgs::init(deref_argc, deref_argv, &about);
187
 
 
188
 
// can't delete this now, since Krash handler need my name
189
 
//       delete [] deref_argv;
190
 
 
191
 
//fprintf(stderr,"add options 1\n");
192
 
       KCmdLineArgs::addCmdLineOptions( options );
193
 
 
194
 
//fprintf(stderr,"add options ?\n");
195
 
       KUniqueApplication::addCmdLineOptions();
196
 
 
197
 
//fprintf(stderr,"starting ?\n");
198
 
       if (!MidiApplication::start()) {
199
 
            return 0;
200
 
       }
201
 
 
202
 
//fprintf(stderr,"making thisapp\n");
203
 
       thisapp = new MidiApplication();
204
 
 
205
 
       return 1;
206
 
}
207
 
    
208
 
int Launch_KMidi_Process(int _pipenumber) {
209
 
 
210
 
        pipenumber = _pipenumber;
211
 
 
212
 
//fprintf(stderr,"Launch\n");
213
 
        if (thisapp->isRestored()) {
214
 
           int n = 1;
215
 
           while (KMidiFrame::canBeRestored(n)) {
216
 
//fprintf(stderr,"restoring\n");
217
 
              (new KMidiFrame)->restore(n);
218
 
              n++;
219
 
           }
220
 
        }
221
 
        else {
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);
230
 
        }
231
 
 
232
 
        kmidiframe->show();
233
 
        thisapp->exec();
234
 
 
235
 
        return 0;
236
 
}
237
 
 
238
 
 
239
 
#include "midiapplication.moc"