MuseScore/synthesizer/msynthesizer.h

121 lines
3.5 KiB
C
Raw Normal View History

2013-03-26 19:59:51 +01:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2012 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#ifndef __MSYNTHESIZER_H__
#define __MSYNTHESIZER_H__
#include <atomic>
#include "effects/effect.h"
#include "libmscore/synthesizerstate.h"
2013-03-26 19:59:51 +01:00
2013-05-13 18:49:17 +02:00
namespace Ms {
2013-03-26 19:59:51 +01:00
struct MidiPatch;
class NPlayEvent;
2013-03-26 19:59:51 +01:00
class Synthesizer;
class Effect;
class Xml;
2013-03-26 19:59:51 +01:00
//---------------------------------------------------------
// MasterSynthesizer
// hosts several synthesizers
//---------------------------------------------------------
2013-04-03 12:13:23 +02:00
class MasterSynthesizer : public QObject {
Q_OBJECT
Solved all compilation errors on MSVC This commit contains changes required for MuseScore to compile under MSVC with no errors. There are several general categories of problems that resulted in errors with the compilation. Main issues: - Variable Length Arrays (VLA). This is a non-standard extension to C++, supported by clang toolchains, but not by MSVC. The initial workaround is to use std::vector<> instead of VLAs, eventually (if needed) with the original variable pointing to the beginning of the allocated array. More efficient alternatives are possible if profiling shows any code using VLAs to be timing-critical. - Floating-point constants not suffixed with "f" are doubles by default; in some instances, this leads to narrowing conversion errors (in other instances, just warnings). - MSVC does not support "or"/"and"/"not" in lieu of "||"/"&&"/"!". Changed unconditionally to use standard C++ symbols. - MSVC does not support the "__builtin_unreachable()" compiler hint. A similar, albeit not exactly equal, alternative is "__assume(0)", which is MSVC-specific. - MSVC does not support ranges in case statements. Replaced with list of cases instead of range (non-conditionally) Detailed changes, with per-file comments: - all.h: opt-in to deprecated features, include <io.h> and <process.h> instead of POSIX <unistd.h>, undefine "STRING_NONE" and "small", which Microsoft defines as macros, which result in compilation errors. - effects/compressor/zita.cpp: eliminated narrowing conversion error by appending "f" to float constants. - fluid/voice.cpp: appended "f" to float constants to eliminate narrowing conversion errors/warnings - libmscore/beam.cpp: conditionally replaced VLA - libmscore/edit.cpp: conditionally replaced VLA - libmscore/element.cpp: appended "f" to float constant - libmscore/fret.cpp: changed or -> || - libmscore/layout.cpp: conditionally replaced VLA - libmscore/mscore.cpp: conditionally replaced "__builtin_unreachable()" with "__assume(0)" for MSVC - libmscore/scorefile.coo: use correct char representation conversion for MSVC - libmscore/stringdata.cpp: conditionally replaced VLA - libmscore/system.cpp: conditionally replaced VLA - libmscroe/text.cpp: replaced range in case statement. - manual/genManual.cpp: use getopt() replacement. - midi/midifile.cpp: conditionally replaced VLA. This does not use the default replacement. - mscore/bb.cpp: replaced range in case statement. - mscore/capella.cpp: conditionally replaced VLA. Changed and -> && - mscore/driver:cpp: preclude errors due to macro redefinitions. - mscore/editstyle.cpp: conditionally replaced "__builtin_unreachable()" with "__assume(0)" for MSVC - mscore/importgtp-gp6.cpp: conditionally replaced VLA. - mscore/instrwidget.cpp: conditionally replaced VLA. - mscore/jackaudio.cpp: conditionally replaced VLA. Preclude errors due to macro redefinitions. - mscore/jackweakapi.cpp: Preclude errors due to macro redefinitions. Replacement for __atribute__((constructor)) through static object construction for MSVC. Force use of LoadLibraryA instead of LoadLibrary. - mscore/mididriver.h: Changed not -> ! - mscore/musescore.cpp: Changed not -> !. Conditionally replaced VLA. - mscore/resourceManager.cpp: conditionally replaced VLA. - mscore/timeline.cpp: conditionally replaced VLA. - omr/omrpage.cpp: conditionally replaced VLA. - synthesizer/msynthesizer.cpp: replaced UNIX sleep(1) method with MSVC Sleep(1000) (equivalent, but in ms instead of seconds) - synthesizer/msynthsizer.h: appended "f" to float constant - thirdparty/poppler/config.h: set defines for MSVC to preclude the use of inexistent libraries. - thirdparty/poppler/poppler/poppler-config.h: set defines for MSVC to preclude the use of inexistent libraries. Eliminated #defines for fmin and fmax which where causing problems. - thirdparty/poppler/poppler/PSOutputDev.cc: added #include <algorithm> for std::min() and std::max(). Note this is required per-C++ standard. - thirdparty/portmidi/pm_win/pmwinmm.c: undefined UNICODE to use char-based library functions. - thirdparty/qzip/qzip.cpp: changed or -> || - thirdparty/rtf2html/rtf_keyword.h: file format changed from Apple to UNIX, as MSVC does not supported the former. (NOT error related, just improvement on previous commit; manual/getopt/README.md: added link to source article)
2018-05-01 19:14:44 +02:00
float _gain { 0.1f }; // -20dB
2014-12-12 14:56:06 +01:00
float _boost { 10.0 }; // +20dB
double _masterTuning { 440.0 };
2013-04-03 12:49:55 +02:00
2018-12-22 11:43:23 +01:00
int _dynamicsMethod { 1 }; // Default dynamics method
int _ccToUse { 1 }; // CC2
public:
static const int MAX_BUFFERSIZE = 8192;
static const int MAX_EFFECTS = 2;
private:
2014-12-12 14:56:06 +01:00
std::atomic<bool> lock1 { false };
std::atomic<bool> lock2 { true };
std::vector<Synthesizer*> _synthesizer;
2014-12-12 14:56:06 +01:00
std::vector<Effect*> _effectList[MAX_EFFECTS];
Effect* _effect[MAX_EFFECTS] { nullptr, nullptr };
float _sampleRate;
float effect1Buffer[MAX_BUFFERSIZE];
float effect2Buffer[MAX_BUFFERSIZE];
int indexOfEffect(int ab, const QString& name);
2013-03-26 19:59:51 +01:00
2013-04-03 12:13:23 +02:00
public slots:
void sfChanged() { emit soundFontChanged(); }
2013-04-03 12:49:55 +02:00
void setGain(float f);
2013-04-03 12:13:23 +02:00
signals:
void soundFontChanged();
2013-04-03 12:49:55 +02:00
void gainChanged(float);
2013-04-03 12:13:23 +02:00
2013-03-26 19:59:51 +01:00
public:
MasterSynthesizer();
2013-03-26 19:59:51 +01:00
~MasterSynthesizer();
void registerSynthesizer(Synthesizer*);
void init();
float sampleRate() { return _sampleRate; }
void setSampleRate(float val);
2013-03-26 19:59:51 +01:00
void process(unsigned, float*);
void play(const NPlayEvent&, unsigned);
2013-03-26 19:59:51 +01:00
void setMasterTuning(double val);
double masterTuning() const { return _masterTuning; }
2013-03-26 19:59:51 +01:00
int index(const QString&) const;
QString name(unsigned) const;
2013-03-26 19:59:51 +01:00
QList<MidiPatch*> getPatchInfo() const;
fix #275313: rework mixer ui 2 Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Setting color in collapsed mode now affects all channels. Using shared_ptr to track MixerTrackItem. Part changes now affect all instruments. Creating new track UI object to handle parts. Using shard_ptr to track MixerTrackItem objects. setting port and channel data now. Changing to horizontal layout. Fixing knob display. Chaning track control appearance. Setting init slider window size. Switchong back to vertical orientation. Fixing a few UI bugs in the slider. Tracks now left aligned. Moving details panel above mixer. Now changing track selection when user clicks on sliders. Pan and volume controls now reflect track color. Showing volume and pan values in tooltips. Creating a new slider control for mixer. Switching Channel's volume, pan, reverb and chorus and chaning them to doubles with a decimal range. No longer writing out vol, pan, chor, reverb when at default values. Nolonger writing vol, pan, chorus, reverb as controler values in output file. Now testing against default values on write. More export fixes. Manually editing test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. More test changes to make Travis happy. More test changes to make Travis happy. Importing MusicXML now matches new volume, pan ranges. Changing range of pan. Fixing a few bugs with calculating MIDI. Altering test files for Travis. fix #275313: rework-mixer-ui-2 Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Setting color in collapsed mode now affects all channels. Using shared_ptr to track MixerTrackItem. Part changes now affect all instruments. Creating new track UI object to handle parts. Using shard_ptr to track MixerTrackItem objects. setting port and channel data now. Changing to horizontal layout. Fixing knob display. Chaning track control appearance. Setting init slider window size. Switchong back to vertical orientation. Fixing a few UI bugs in the slider. Tracks now left aligned. Moving details panel above mixer. Now changing track selection when user clicks on sliders. Pan and volume controls now reflect track color. Showing volume and pan values in tooltips. Creating a new slider control for mixer. Switching Channel's volume, pan, reverb and chorus and chaning them to doubles with a decimal range. No longer writing out vol, pan, chor, reverb when at default values. Nolonger writing vol, pan, chorus, reverb as controler values in output file. Now testing against default values on write. More export fixes. Manually editing test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. More test changes to make Travis happy. More test changes to make Travis happy. Importing MusicXML now matches new volume, pan ranges. Changing range of pan. Fixing a few bugs with calculating MIDI. Altering test files for Travis. Restoring the volume, pan, chorus, reverb to original char data type & range. UI now shows different 'user friendly' ranges. Overwriting tests with versions from master. mtest/libmscore/compat114/clef_missing_first-ref.mscx mtest/libmscore/compat114/hor_frame_and_mmrest-ref.mscx mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml mtest/musicxml/io/testUninitializedDivisions_ref.xml Restoring test files to original state. Restoring test files to original state. Restoring old values for importing files. Restoring part methods. mtest/importmidi/simplify_8th_dotted_no_staccato.mscx mtest/libmscore/compat114/clef_missing_first-ref.mscx mtest/libmscore/compat114/hor_frame_and_mmrest-ref.mscx mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml mtest/musicxml/io/testUninitializedDivisions_ref.xml Rearranging UI components for better feel. Improving UI. Fixed crash when changing part name. Adding support for two lighting modes. Showing part name over channel expansion. Adding master gain control to mixer. Changing color of gain slider. Adapting to latest source in main. Changing master gain slider to use decibel calculation. CSS now set on tracks whenever a Paint event received. Restoring mixer slider values to refect MIDI ranges. Fixing crash when drumkit checked. Fixing crash when closing score. Fixing alignment in mixer details. Tweaking UI for better appearance.
2018-11-13 18:43:19 +01:00
MidiPatch* getPatchInfo(QString synti, int bank, int program);
2013-03-26 19:59:51 +01:00
SynthesizerState state() const;
bool setState(const SynthesizerState&);
2013-03-26 19:59:51 +01:00
Synthesizer* synthesizer(const QString& name);
const std::vector<Effect*>& effectList(int ab) const { return _effectList[ab]; }
2013-04-03 17:18:25 +02:00
const std::vector<Synthesizer*> synthesizer() const { return _synthesizer; }
void registerEffect(int ab, Effect*);
2013-03-26 19:59:51 +01:00
void reset();
void allSoundsOff(int channel);
void allNotesOff(int channel);
void setEffect(int ab, int idx);
Effect* effect(int ab);
int indexOfEffect(int ab);
2013-04-03 12:49:55 +02:00
2014-12-12 14:56:06 +01:00
float gain() const { return _gain; }
float boost() const { return _boost; }
void setBoost(float v) { _boost = v; }
2018-12-22 11:43:23 +01:00
int dynamicsMethod() const { return _dynamicsMethod; }
void setDynamicsMethod(int val) { _dynamicsMethod = val; }
int ccToUseIndex() const { return _ccToUse; } // NOTE: this doesn't return a CC number, but returns an index instead
void setCcToUseIndex(int val) { _ccToUse = val; }
bool storeState();
2013-03-26 19:59:51 +01:00
};
2013-05-13 18:49:17 +02:00
}
2013-03-26 19:59:51 +01:00
#endif