~ubuntu-branches/ubuntu/breezy/muse/breezy

« back to all changes in this revision

Viewing changes to node.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2004-02-07 15:18:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040207151822-es27xxkzbcxkebjm
Tags: 0.6.3-1
* New upstream version.
* Added patches:
  + [10_alsa_init_fix] New, from upstream CVS.
    Initialize direction variable when setting Alsa parameters.
  + [10_canvas_translation_fix] New, from upstream CVS.
    Do not translate tooltips twice in canvas popup.
  + [10_checkbox_fix] New, from upstream CVS.
    Use proper set/test methods on metronome checkboxes.
  + [10_html_doc_cleanup] New.
    Fix links and HTML errors in documentation.
  + [20_allow_system_timer] New.
    The new upstream version fails by default if the real-time clock
    could not be accessed (usually the case when not running suid-root).
    This patch reverts the old behaviour of falling back to the more
    inaccurate system timer.
* Updated patches:
  + [11_PIC_fixes_fixup] Rediffed.
* Removed patches:
  + [20_no_atomic_asm] Merged upstream.
* debian/compat: Splice out debhelper compatibility level from rules file.
* debian/control: Build-depend on latest jack release by default.
  Closes: #228788
* debian/control: Bump standards version.
* debian/control: Use auto-generated debconf dependency via misc:Depends.
* debian/control: Minor tweaks to the long description.
* debian/control: Tighten fluidsynth build dependency to sane version.
* debian/muse.doc-base: New. Register HTML documentation with doc-base.
* debian/templates: Tiny rewording, and typo fix.
* debian/templates, debian/po/*: Switch to po-debconf for translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=========================================================
 
2
//  MusE
 
3
//  Linux Music Editor
 
4
//  $Id: node.h,v 1.2 2003/11/12 12:34:58 wschweer Exp $
 
5
//
 
6
//  (C) Copyright 2001 Werner Schweer (ws@seh.de)
 
7
//=========================================================
 
8
 
 
9
#ifndef __AUDIONODE_H__
 
10
#define __AUDIONODE_H__
 
11
 
 
12
#include <list>
 
13
#include <qstring.h>
 
14
 
 
15
#ifndef i386
 
16
#include <pthread.h>
 
17
typedef struct { pthread_mutex_t lock; int counter; } muse_atomic_t;
 
18
#else
 
19
typedef struct { int counter; } muse_atomic_t;
 
20
#endif
 
21
 
 
22
static inline int muse_atomic_read(muse_atomic_t *v) {
 
23
#ifndef i386
 
24
      int ret;
 
25
      pthread_mutex_lock(&v->lock);
 
26
      ret = v->counter;
 
27
      pthread_mutex_unlock(&v->lock);
 
28
      return ret;
 
29
#else
 
30
      return v->counter;
 
31
#endif
 
32
}
 
33
 
 
34
static inline void muse_atomic_set(muse_atomic_t *v, int i) {
 
35
#ifndef i386
 
36
      pthread_mutex_lock(&v->lock);
 
37
      v->counter = i;
 
38
      pthread_mutex_unlock(&v->lock);
 
39
#else
 
40
      v->counter = i;
 
41
#endif
 
42
}
 
43
static inline void muse_atomic_inc(muse_atomic_t *v) {
 
44
#ifndef i386
 
45
      pthread_mutex_lock(&v->lock);
 
46
      v->counter++;
 
47
      pthread_mutex_unlock(&v->lock);
 
48
#else
 
49
        __asm__ __volatile__(
 
50
                "lock ; " "incl %0"
 
51
                :"=m" (v->counter)
 
52
                :"m" (v->counter));
 
53
#endif
 
54
}
 
55
static inline void muse_atomic_dec(muse_atomic_t *v) {
 
56
#ifndef i386
 
57
      pthread_mutex_lock(&v->lock);
 
58
      v->counter--;
 
59
      pthread_mutex_unlock(&v->lock);
 
60
#else
 
61
        __asm__ __volatile__(
 
62
                "lock ; " "decl %0"
 
63
                :"=m" (v->counter)
 
64
                :"m" (v->counter));
 
65
#endif
 
66
}
 
67
static inline void muse_atomic_init(muse_atomic_t *v) {
 
68
#ifndef i386
 
69
      pthread_mutex_init(&v->lock, NULL);
 
70
#endif
 
71
}
 
72
static inline void muse_atomic_destroy(muse_atomic_t *v) {
 
73
#ifndef i386
 
74
      pthread_mutex_destroy(&v->lock);
 
75
#endif
 
76
}
 
77
 
 
78
class Xml;
 
79
class Pipeline;
 
80
class SndFile;
 
81
 
 
82
const int AUDIO_GROUPS = 4;
 
83
const int FIFO_BUFFER = 64;
 
84
 
 
85
//---------------------------------------------------------
 
86
//   Fifo
 
87
//---------------------------------------------------------
 
88
 
 
89
struct FifoBuffer {
 
90
      float* buffer;
 
91
      int size;
 
92
      int maxSize;
 
93
      int pos;
 
94
      int segs;
 
95
 
 
96
      FifoBuffer() {
 
97
            buffer  = 0;
 
98
            size    = 0;
 
99
            maxSize = 0;
 
100
            }
 
101
      };
 
102
 
 
103
class Fifo {
 
104
      int nbuffer;
 
105
      int ridx;               // read index; only touched by reader
 
106
      int widx;               // write index; only touched by writer
 
107
      muse_atomic_t count;         // buffer count; writer increments, reader decrements
 
108
      FifoBuffer** buffer;
 
109
 
 
110
   public:
 
111
      Fifo();
 
112
      ~Fifo();
 
113
      void clear() {
 
114
            ridx = 0;
 
115
            widx = 0;
 
116
            muse_atomic_set(&count, 0);
 
117
            }
 
118
      bool put(int, unsigned long, float** buffer, unsigned long pos);
 
119
      bool getWriteBuffer(int, unsigned long, float** buffer, unsigned long pos);
 
120
      void add();
 
121
      bool get(int&, unsigned long&, float** buffer, unsigned long& pos);
 
122
      void remove();
 
123
      };
 
124
 
 
125
//---------------------------------------------------------
 
126
//   SNode
 
127
//    sound node
 
128
//    common part for audio and midi tracks
 
129
//---------------------------------------------------------
 
130
 
 
131
class SNode {
 
132
      int _activity;
 
133
      int _lastActivity;      //tmp value
 
134
 
 
135
   protected:
 
136
      bool _recordFlag;
 
137
      bool _mute;
 
138
      bool _solo;
 
139
      bool _off;
 
140
 
 
141
   public:
 
142
      SNode();
 
143
      SNode(const SNode&);
 
144
      virtual void setMute(bool val);
 
145
      virtual void setOff(bool val);
 
146
      virtual void setSolo(bool val) = 0;
 
147
      bool solo() const                  { return _solo;         }
 
148
      bool mute() const                  { return _mute;         }
 
149
      bool off() const                   { return _off;          }
 
150
      virtual bool isMute() const = 0;
 
151
      virtual void addSolo() = 0;
 
152
      bool recordFlag() const            { return _recordFlag;   }
 
153
      virtual void setRecordFlag1(bool /*f*/) {}
 
154
      virtual void setRecordFlag2(bool f) { _recordFlag = f;      }
 
155
      int activity()                     { return _activity;     }
 
156
      void setActivity(int v)            { _activity = v;        }
 
157
      int lastActivity()                 { return _lastActivity; }
 
158
      void setLastActivity(int v)        { _lastActivity = v;    }
 
159
      void addActivity(int v)            { _activity += v;       }
 
160
 
 
161
      virtual bool soloMode() = 0;
 
162
      bool readProperty(Xml& xml, const QString& tag);
 
163
      };
 
164
 
 
165
//---------------------------------------------------------
 
166
//   MidiNode
 
167
//---------------------------------------------------------
 
168
 
 
169
class MidiNode : public SNode {
 
170
      static bool _soloMode;
 
171
      static std::list<MidiNode*> nodeList;
 
172
 
 
173
   public:
 
174
      MidiNode();
 
175
      virtual ~MidiNode();
 
176
      virtual bool isMute() const;
 
177
      virtual void setSolo(bool val);
 
178
      virtual void addSolo();
 
179
      virtual bool soloMode() { return _soloMode;     }
 
180
      };
 
181
 
 
182
//---------------------------------------------------------
 
183
//   AudioNode
 
184
//    a managed collection of audio ports
 
185
//    synth, track, group
 
186
//---------------------------------------------------------
 
187
 
 
188
class AudioNode : public SNode {
 
189
      static bool _soloMode;
 
190
      static std::list<AudioNode*> nodeList;
 
191
 
 
192
   public:
 
193
      std::list<AudioNode*> _inRoute;
 
194
      std::list<AudioNode*> _outRoute;
 
195
 
 
196
   private:
 
197
      void readRecfile(Xml& xml);
 
198
 
 
199
   protected:
 
200
      int _ports;                   // 1 - mono, 2 - stereo
 
201
      double _volume;
 
202
      double _pan;
 
203
      bool _prefader;               // prefader metering
 
204
      Pipeline* _efxPipe;
 
205
 
 
206
      int _meter[2];
 
207
      int _peak[2];
 
208
      SndFile* _recFile;
 
209
      Fifo fifo;                    // fifo -> _recFile
 
210
 
 
211
      virtual bool getData(int, unsigned long, float**);
 
212
 
 
213
   public:
 
214
      AudioNode();
 
215
      AudioNode(const AudioNode&);
 
216
      virtual ~AudioNode();
 
217
 
 
218
      virtual bool isMute() const;
 
219
      virtual void setSolo(bool val);
 
220
      virtual void addSolo();
 
221
      virtual bool soloMode()            { return _soloMode;     }
 
222
 
 
223
      void putFifo(int channels, unsigned long n, float** bp);
 
224
 
 
225
      SndFile* recFile() const           { return _recFile; }
 
226
      void setRecFile(SndFile* sf)       { _recFile = sf;   }
 
227
      void record();
 
228
 
 
229
      virtual void setRecordFlag1(bool f);
 
230
      virtual void setRecordFlag2(bool f);
 
231
      virtual void setMute(bool val);
 
232
      virtual void setOff(bool val);
 
233
 
 
234
      int ports() const                  { return _ports; }
 
235
      void setPorts(int n);
 
236
      double volume() const              { return _volume;   }
 
237
      void setVolume(double val)         { _volume = val;    }
 
238
      double pan() const                 { return _pan;      }
 
239
      void setPan(double val)            { _pan = val;       }
 
240
      bool prefader() const              { return _prefader; }
 
241
      void setPrefader(bool val);
 
242
      Pipeline* efxPipe()                { return _efxPipe;  }
 
243
 
 
244
      void writeConfiguration(int, Xml&) const;
 
245
      void readConfiguration(Xml&);
 
246
      void readVolume(Xml& xml);
 
247
 
 
248
      void connectIn(AudioNode* p);
 
249
      void connectOut(AudioNode* p);
 
250
      void disconnectIn(AudioNode* p);
 
251
      void disconnectOut(AudioNode* p);
 
252
      void connect();
 
253
      void disconnect();
 
254
      void disconnectClear();
 
255
 
 
256
      AudioNode* route() const;
 
257
 
 
258
      void segmentSizeChanged();
 
259
 
 
260
      void resetMeter();
 
261
      void resetPeaks();
 
262
      static void resetAllMeter();
 
263
 
 
264
      int meter(int ch) const  { return _meter[ch]; }
 
265
      int peak(int ch) const   { return _peak[ch]; }
 
266
 
 
267
      virtual void addData(int, unsigned long, float**);
 
268
      virtual void copyData(int, unsigned long, float**);
 
269
 
 
270
      bool canRecord() const;
 
271
      };
 
272
 
 
273
typedef std::list<AudioNode*>::iterator iAudioNode;
 
274
typedef std::list<AudioNode*>::const_iterator ciAudioNode;
 
275
 
 
276
//---------------------------------------------------------
 
277
//   AudioPort
 
278
//---------------------------------------------------------
 
279
 
 
280
class AudioPort : public AudioNode {
 
281
   public:
 
282
      AudioPort() : AudioNode() {}
 
283
      };
 
284
 
 
285
//---------------------------------------------------------
 
286
//   AudioOutputPort
 
287
//---------------------------------------------------------
 
288
 
 
289
class AudioOutputPort : public AudioPort {
 
290
   public:
 
291
      AudioOutputPort();
 
292
      ~AudioOutputPort();
 
293
      void process(unsigned long);
 
294
      };
 
295
 
 
296
//---------------------------------------------------------
 
297
//   AudioInputPort
 
298
//---------------------------------------------------------
 
299
 
 
300
class AudioInputPort : public AudioPort {
 
301
      virtual bool getData(int, unsigned long, float**);
 
302
 
 
303
   public:
 
304
      AudioInputPort();
 
305
      };
 
306
 
 
307
extern AudioOutputPort audioOutput;  // output device node
 
308
extern AudioInputPort audioInput;    // input device node
 
309
 
 
310
extern AudioNode audioGroups[AUDIO_GROUPS];
 
311
extern int mixerGroups;
 
312
 
 
313
extern void connectNodes(AudioNode* out, AudioNode* in);
 
314
extern void disconnectNodes(AudioNode* out, AudioNode* in);
 
315
extern AudioNode* name2Node(const QString&);
 
316
extern QString node2Name(const AudioNode*);
 
317
 
 
318
#endif
 
319