svcore  1.9
SamplePlayer.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _SAMPLE_PLAYER_H_
00017 #define _SAMPLE_PLAYER_H_
00018 
00019 #define DSSI_API_LEVEL 2
00020 
00021 #include "../api/ladspa.h"
00022 #include "../api/dssi.h"
00023 
00024 #include <seq_event.h>
00025 
00026 #include <QMutex>
00027 #include <QString>
00028 #include <vector>
00029 
00030 class SamplePlayer
00031 {
00032 public:
00033     static const DSSI_Descriptor *getDescriptor(unsigned long index);
00034 
00035 private:
00036     SamplePlayer(int sampleRate);
00037     ~SamplePlayer();
00038 
00039     enum {
00040         OutputPort    = 0,
00041         RetunePort    = 1,
00042         BasePitchPort = 2,
00043         ConcertAPort  = 3,
00044         SustainPort   = 4,
00045         ReleasePort   = 5,
00046         PortCount     = 6
00047     };
00048 
00049     enum {
00050         Polyphony = 128
00051     };
00052 
00053     static const char *const portNames[PortCount];
00054     static const LADSPA_PortDescriptor ports[PortCount];
00055     static const LADSPA_PortRangeHint hints[PortCount];
00056     static const LADSPA_Properties properties;
00057     static const LADSPA_Descriptor ladspaDescriptor;
00058     static const DSSI_Descriptor dssiDescriptor;
00059     static const DSSI_Host_Descriptor *hostDescriptor;
00060 
00061     static LADSPA_Handle instantiate(const LADSPA_Descriptor *, unsigned long);
00062     static void connectPort(LADSPA_Handle, unsigned long, LADSPA_Data *);
00063     static void activate(LADSPA_Handle);
00064     static void run(LADSPA_Handle, unsigned long);
00065     static void deactivate(LADSPA_Handle);
00066     static void cleanup(LADSPA_Handle);
00067     static char *configure(LADSPA_Handle, const char *, const char *);
00068     static const DSSI_Program_Descriptor *getProgram(LADSPA_Handle, unsigned long);
00069     static void selectProgram(LADSPA_Handle, unsigned long, unsigned long);
00070     static int getMidiController(LADSPA_Handle, unsigned long);
00071     static void runSynth(LADSPA_Handle, unsigned long,
00072                          snd_seq_event_t *, unsigned long);
00073     static void receiveHostDescriptor(const DSSI_Host_Descriptor *descriptor);
00074     static void workThreadCallback(LADSPA_Handle);
00075 
00076     void searchSamples();
00077     void loadSampleData(QString path);
00078     void runImpl(unsigned long, snd_seq_event_t *, unsigned long);
00079     void addSample(int, unsigned long, unsigned long);
00080 
00081     float *m_output;
00082     float *m_retune;
00083     float *m_basePitch;
00084     float *m_concertA;
00085     float *m_sustain;
00086     float *m_release;
00087 
00088     float *m_sampleData;
00089     size_t m_sampleCount;
00090     int m_sampleRate;
00091 
00092     long m_ons[Polyphony];
00093     long m_offs[Polyphony];
00094     int m_velocities[Polyphony];
00095     long m_sampleNo;
00096 
00097     QString m_sampleDir;
00098     QString m_program;
00099     std::vector<std::pair<QString, QString> > m_samples; // program name, path
00100     bool m_sampleSearchComplete;
00101     int m_pendingProgramChange;
00102 
00103     QMutex m_mutex;
00104 };
00105 
00106 
00107 #endif