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

« back to all changes in this revision

Viewing changes to synti/fluidsynth/fluidsynti.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 FLUID Synth softsynth plugin
 
3
 *
 
4
 * Copyright (C) 2002 Robert Ham (node@users.sourcforge.net)
 
5
 *
 
6
 * $Id: fluidsynti.h,v 1.1.1.1 2003/10/29 10:06:05 wschweer Exp $
 
7
 *
 
8
 */
 
9
 
 
10
#ifndef __MUSE_FLUIDSYNTI_H__
 
11
#define __MUSE_FLUIDSYNTI_H__
 
12
 
 
13
#include <string>
 
14
#include <list>
 
15
#include <map>
 
16
#include <fluidsynth.h>
 
17
#include <pthread.h>
 
18
#include "fluidsynthgui.h"
 
19
#include "mess.h"
 
20
#include "debug.h"
 
21
 
 
22
class FLUIDSynth_soundfont
 
23
{
 
24
public:
 
25
        FLUIDSynth_soundfont(): _external_id(0), _internal_id(0) {};
 
26
 
 
27
        std::string     _filename;
 
28
        std::string             _name;
 
29
        unsigned char   _external_id; //The ID the gui knows about
 
30
        unsigned char   _internal_id; //The ID for fluidsynth
 
31
};
 
32
 
 
33
// FluidSynthChannel is used to map different soundfonts to different fluid-channels
 
34
// This is to be able to select different presets from specific soundfonts, since
 
35
// Fluidsynth has a quite strange way of dealing with fontloading and channels
 
36
// We also need this since getFirstPatch and getNextPatch only tells us which channel is
 
37
// used, so this works as a connection between soundfonts and fluid-channels (one channel
 
38
// can only have one soundfont, but one soundfont can have many channels)
 
39
class FluidSynthChannel
 
40
{
 
41
private:
 
42
        unsigned char _soundfont_internal_id;
 
43
        unsigned char _soundfont_external_id;
 
44
        unsigned int  _preset_id;
 
45
 
 
46
public:
 
47
        FluidSynthChannel():
 
48
                _soundfont_internal_id(0),
 
49
                _soundfont_external_id(0),
 
50
                _preset_id(MUSE_FLUID_UNSPECIFIED_PRESET) { };
 
51
        void setInternalFontId(unsigned char int_id)    { _soundfont_internal_id = int_id; }
 
52
        void setExternalFontId(unsigned char ext_id)    { _soundfont_external_id = ext_id; }
 
53
        void setPresetId(unsigned char preset_id)               { _preset_id = preset_id; }
 
54
        unsigned char getInternalFontId() const         { return _soundfont_internal_id; }
 
55
        unsigned char getExternalFontId() const         { return _soundfont_external_id; }
 
56
        unsigned char getPresetId()                             { return _preset_id; }
 
57
};
 
58
 
 
59
class FLUIDParameterSet {
 
60
private:
 
61
  std::map <std::string, std::pair <bool, double> > _parameters;
 
62
public:
 
63
  FLUIDParameterSet () {}
 
64
  FLUIDParameterSet (const FLUIDParameterSet&);
 
65
  void setParameter (std::string param, int val) {
 
66
    _parameters[param] = std::pair<bool, double> (true, ((double)val)/128.0);
 
67
  }
 
68
  void setParameter (std::string param, double val) {
 
69
    _parameters[param] = std::pair<bool, double> (true, val);
 
70
  }
 
71
  double getParameter (std::string param) { return _parameters[param].second; }
 
72
  bool getParameterModified (std::string param) { return _parameters[param].first; }
 
73
};
 
74
 
 
75
 
 
76
class FLUIDSynth : public Mess {
 
77
private:
 
78
        double _gain;
 
79
        FLUIDParameterSet _reverbParameters;
 
80
        FLUIDParameterSet _chorusParameters;
 
81
        pthread_t fontThread;
 
82
        void setReverb ();
 
83
        void setChorus ();
 
84
        void setGain (double gain);
 
85
        virtual void write (int, float **, int);
 
86
        void decodeSysex (const unsigned char *, int);
 
87
        void processSysex (const unsigned char *, int);
 
88
        void encodeSysex(const unsigned char *, int);
 
89
        const MidiPatch * getFirstPatch (int channel) const;
 
90
        void sfChannelChange(unsigned char font_id, unsigned char channel);
 
91
        void rewriteChannelSettings(); //used because fluidsynth does some very nasty things when loading a font!
 
92
        std::string _lastDir;
 
93
 
 
94
 
 
95
 
 
96
public:
 
97
        FLUIDSynth (const char *);
 
98
        virtual ~FLUIDSynth ();
 
99
        virtual bool init ();
 
100
        virtual void processEvent (MEvent *);
 
101
        virtual const char * getPatchName (int, int, int, int, MType);
 
102
        virtual const MidiPatch * getNextPatch (int, const MidiPatch *) const;
 
103
        virtual int getMidiInitEvent(int id, RawMidiEvent* ev);
 
104
        bool pushSoundfont (const std::string&, int ext_id);
 
105
        bool popSoundfont (int ext_id);
 
106
        void sendSysexError (const char *);
 
107
        void sendSoundFontdata();
 
108
        void initSynth();
 
109
        int getNextAvailableExternalId();
 
110
        fluid_synth_t * _fluidsynth;
 
111
        pthread_mutex_t _sfloader_mutex;
 
112
        int _nrOfSoundfonts;
 
113
        int _currentlyLoadedFonts; //To know whether or not to run the init-parameters
 
114
 
 
115
        std::list<FLUIDSynth_soundfont> _soundfontStack;
 
116
        FluidSynthChannel _fluidChannels[MUSE_FLUID_MAX_NR_OF_CHANNELS];
 
117
 
 
118
int getFontInternalIdByChannel(int channel) const { return (int) _fluidChannels[channel].getInternalFontId(); }
 
119
int getFontExternalIdByChannel(int channel) { return (int) _fluidChannels[channel].getExternalFontId(); }
 
120
void setFontInternalIdByChannel(int channel, int int_id) { _fluidChannels[channel].setInternalFontId(int_id); }
 
121
void setFontExternalIdByChannel(int channel, int ext_id) { _fluidChannels[channel].setExternalFontId(ext_id); }
 
122
unsigned char getChannelPreset(int channel) { return (int) _fluidChannels[channel].getPresetId(); }
 
123
void setChannelPreset(int preset, unsigned char channel) { _fluidChannels[channel].setPresetId(preset); }
 
124
int getFontInternalIdByExtId    (int channel);
 
125
 
 
126
};
 
127
 
 
128
struct Helper //Only used to pass parameters when calling the loading thread
 
129
{
 
130
        FLUIDSynth*     fptr;
 
131
        std::string             filename;
 
132
        int                     id;
 
133
};
 
134
#endif /* __MUSE_FLUIDSYNTI_H__ */