Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@0: 
Chris@0: /*
Chris@52:     Sonic Visualiser
Chris@52:     An audio file viewer and annotation editor.
Chris@52:     Centre for Digital Music, Queen Mary, University of London.
Chris@52:     This file copyright 2006 Chris Cannam.
Chris@0:     
Chris@52:     This program is free software; you can redistribute it and/or
Chris@52:     modify it under the terms of the GNU General Public License as
Chris@52:     published by the Free Software Foundation; either version 2 of the
Chris@52:     License, or (at your option) any later version.  See the file
Chris@52:     COPYING included with this distribution for more information.
Chris@0: */
Chris@0: 
Chris@0: #ifndef _SAMPLE_PLAYER_H_
Chris@0: #define _SAMPLE_PLAYER_H_
Chris@0: 
Chris@0: #define DSSI_API_LEVEL 2
Chris@0: 
Chris@0: #include <ladspa.h>
Chris@0: #include <dssi.h>
Chris@0: #include <seq_event.h>
Chris@0: 
Chris@0: #include <QMutex>
Chris@0: #include <QString>
Chris@0: #include <vector>
Chris@0: 
Chris@0: class SamplePlayer
Chris@0: {
Chris@0: public:
Chris@0:     static const DSSI_Descriptor *getDescriptor(unsigned long index);
Chris@0: 
Chris@0: private:
Chris@0:     SamplePlayer(int sampleRate);
Chris@0:     ~SamplePlayer();
Chris@0: 
Chris@0:     enum {
Chris@0: 	OutputPort    = 0,
Chris@0: 	RetunePort    = 1,
Chris@0: 	BasePitchPort = 2,
Chris@143:         ConcertAPort  = 3,
Chris@143: 	SustainPort   = 4,
Chris@143: 	ReleasePort   = 5,
Chris@143: 	PortCount     = 6
Chris@0:     };
Chris@0: 
Chris@0:     enum {
Chris@0: 	Polyphony = 128
Chris@0:     };
Chris@0: 
Chris@0:     static const char *const portNames[PortCount];
Chris@0:     static const LADSPA_PortDescriptor ports[PortCount];
Chris@0:     static const LADSPA_PortRangeHint hints[PortCount];
Chris@0:     static const LADSPA_Properties properties;
Chris@0:     static const LADSPA_Descriptor ladspaDescriptor;
Chris@0:     static const DSSI_Descriptor dssiDescriptor;
Chris@0:     static const DSSI_Host_Descriptor *hostDescriptor;
Chris@0: 
Chris@0:     static LADSPA_Handle instantiate(const LADSPA_Descriptor *, unsigned long);
Chris@0:     static void connectPort(LADSPA_Handle, unsigned long, LADSPA_Data *);
Chris@0:     static void activate(LADSPA_Handle);
Chris@0:     static void run(LADSPA_Handle, unsigned long);
Chris@0:     static void deactivate(LADSPA_Handle);
Chris@0:     static void cleanup(LADSPA_Handle);
Chris@75:     static char *configure(LADSPA_Handle, const char *, const char *);
Chris@0:     static const DSSI_Program_Descriptor *getProgram(LADSPA_Handle, unsigned long);
Chris@0:     static void selectProgram(LADSPA_Handle, unsigned long, unsigned long);
Chris@0:     static int getMidiController(LADSPA_Handle, unsigned long);
Chris@0:     static void runSynth(LADSPA_Handle, unsigned long,
Chris@0: 			 snd_seq_event_t *, unsigned long);
Chris@0:     static void receiveHostDescriptor(const DSSI_Host_Descriptor *descriptor);
Chris@0:     static void workThreadCallback(LADSPA_Handle);
Chris@0: 
Chris@0:     void searchSamples();
Chris@0:     void loadSampleData(QString path);
Chris@0:     void runImpl(unsigned long, snd_seq_event_t *, unsigned long);
Chris@0:     void addSample(int, unsigned long, unsigned long);
Chris@0: 
Chris@0:     float *m_output;
Chris@0:     float *m_retune;
Chris@0:     float *m_basePitch;
Chris@143:     float *m_concertA;
Chris@0:     float *m_sustain;
Chris@0:     float *m_release;
Chris@0: 
Chris@0:     float *m_sampleData;
Chris@0:     size_t m_sampleCount;
Chris@0:     int m_sampleRate;
Chris@0: 
Chris@0:     long m_ons[Polyphony];
Chris@0:     long m_offs[Polyphony];
Chris@0:     int m_velocities[Polyphony];
Chris@0:     long m_sampleNo;
Chris@0: 
Chris@83:     QString m_sampleDir;
Chris@0:     QString m_program;
Chris@0:     std::vector<std::pair<QString, QString> > m_samples; // program name, path
Chris@0:     bool m_sampleSearchComplete;
Chris@0:     int m_pendingProgramChange;
Chris@0: 
Chris@0:     QMutex m_mutex;
Chris@0: };
Chris@0: 
Chris@0: 
Chris@0: #endif