miscellaneous fixes for warnings from -Wconversion

This commit is contained in:
Paul Davis 2022-07-04 22:01:25 -06:00
parent 811f625623
commit 0d70be3a05
11 changed files with 36 additions and 34 deletions

View File

@ -94,7 +94,7 @@ TransientDetector::set_sensitivity (uint32_t mode, float val)
// see libs/vamp-plugins/OnsetDetect.cpp // see libs/vamp-plugins/OnsetDetect.cpp
//plugin->selectProgram ("General purpose"); // dftype = 3, sensitivity = 50, whiten = 0 (default) //plugin->selectProgram ("General purpose"); // dftype = 3, sensitivity = 50, whiten = 0 (default)
//plugin->selectProgram ("Percussive onsets"); // dftype = 4, sensitivity = 40, whiten = 0 //plugin->selectProgram ("Percussive onsets"); // dftype = 4, sensitivity = 40, whiten = 0
plugin->setParameter ("dftype", mode); plugin->setParameter ("dftype", (float) mode);
plugin->setParameter ("sensitivity", std::min (100.f, std::max (0.f, val))); plugin->setParameter ("sensitivity", std::min (100.f, std::max (0.f, val)));
plugin->setParameter ("whiten", 0); plugin->setParameter ("whiten", 0);
} }

View File

@ -63,7 +63,7 @@ uint16_t
SMF::num_tracks() const SMF::num_tracks() const
{ {
Glib::Threads::Mutex::Lock lm (_smf_lock); Glib::Threads::Mutex::Lock lm (_smf_lock);
return _smf ? _smf->number_of_tracks : 0; return (uint16_t) (_smf ? _smf->number_of_tracks : 0);
} }
uint16_t uint16_t
@ -304,7 +304,7 @@ SMF::read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf, event_id_t* no
return 0; /* this is a meta-event */ return 0; /* this is a meta-event */
} }
int event_size = event->midi_buffer_length; uint32_t event_size = (uint32_t) event->midi_buffer_length;
assert(event_size > 0); assert(event_size > 0);
// Make sure we have enough scratch buffer // Make sure we have enough scratch buffer

View File

@ -171,7 +171,7 @@ public:
uint8_t pgm_number() const { return _buf[1]; } uint8_t pgm_number() const { return _buf[1]; }
uint8_t pitch_bender_lsb() const { return _buf[1]; } uint8_t pitch_bender_lsb() const { return _buf[1]; }
uint8_t pitch_bender_msb() const { return _buf[2]; } uint8_t pitch_bender_msb() const { return _buf[2]; }
uint16_t pitch_bender_value() const { return ((0x7F & _buf[2]) << 7 | (0x7F & _buf[1])); } uint16_t pitch_bender_value() const { return (uint16_t) ((0x7F & _buf[2]) << 7 | (0x7F & _buf[1])); }
void set_channel(uint8_t channel) { _buf[0] = (0xF0 & _buf[0]) | (0x0F & channel); } void set_channel(uint8_t channel) { _buf[0] = (0xF0 & _buf[0]) | (0x0F & channel); }
void set_type(uint8_t type) { _buf[0] = (0x0F & _buf[0]) | (0xF0 & type); } void set_type(uint8_t type) { _buf[0] = (0x0F & _buf[0]) | (0xF0 & type); }
@ -183,7 +183,7 @@ public:
void scale_velocity (float factor) { void scale_velocity (float factor) {
factor = std::max (factor, 0.0f); factor = std::max (factor, 0.0f);
set_velocity (std::min (127L, lrintf (velocity() * factor))); set_velocity ((uint8_t) (std::min (127L, lrintf (velocity() * factor))));
} }
uint16_t value() const { uint16_t value() const {

View File

@ -72,8 +72,10 @@ public:
private: private:
const Note<Time>& operator=(const Note<Time>& copy); // undefined (unsafe) const Note<Time>& operator=(const Note<Time>& copy); // undefined (unsafe)
inline int clamp(int val, int low, int high) { inline uint8_t clamp(int val, int low, int high) {
return std::min (std::max (val, low), high); const int r = std::min (std::max (val, low), high);
assert (r < 256 && r >= 0);
return (uint8_t) r;
} }
public: public:

View File

@ -349,7 +349,7 @@ inline int8_t string_to (const std::string& str)
{ {
int16_t tmp; int16_t tmp;
string_to_int16 (str, tmp); string_to_int16 (str, tmp);
return tmp; return (int8_t) tmp;
} }
template <> template <>
@ -357,7 +357,7 @@ inline uint8_t string_to (const std::string& str)
{ {
uint16_t tmp; uint16_t tmp;
string_to_uint16 (str, tmp); string_to_uint16 (str, tmp);
return tmp; return (uint8_t) tmp;
} }
template <> template <>

View File

@ -186,7 +186,7 @@ public:
min = _min; min = _min;
max = _max; max = _max;
avg = _avg / (double)_cnt; avg = _avg / (double)_cnt;
dev = sqrt (_vs / (_cnt - 1.0)); dev = sqrt (_vs / ((double) _cnt - 1.0));
return true; return true;
} }
@ -195,7 +195,7 @@ private:
{ {
const microseconds_t diff = elapsed (); const microseconds_t diff = elapsed ();
_avg += diff; _avg += (double) diff;
if (diff > _max) { if (diff > _max) {
_max = diff; _max = diff;
@ -205,11 +205,11 @@ private:
} }
if (_cnt == 0) { if (_cnt == 0) {
_vm = diff; _vm = (double) diff;
} else { } else {
const double ela = diff; const double ela = (double) diff;
const double var_m1 = _vm; const double var_m1 = _vm;
_vm = _vm + (ela - _vm) / (1.0 + _cnt); _vm = _vm + (ela - _vm) / (1.0 + (double) _cnt);
_vs = _vs + (ela - _vm) * (ela - var_m1); _vs = _vs + (ela - _vm) * (ela - var_m1);
} }
++_cnt; ++_cnt;
@ -289,7 +289,7 @@ public:
void reserve (uint32_t reserve_size) void reserve (uint32_t reserve_size)
{ m_reserve_size = reserve_size; reset (); } { m_reserve_size = reserve_size; reset (); }
uint32_t size () const std::vector<microseconds_t>::size_type size () const
{ return m_elapsed_values.size(); } { return m_elapsed_values.size(); }
private: private:

View File

@ -62,7 +62,7 @@ PBD::stacktrace (std::ostream& out, int levels, size_t start)
if (start == 0) { if (start == 0) {
out << "-- Stacktrace Thread: " << pthread_name () << std::endl; out << "-- Stacktrace Thread: " << pthread_name () << std::endl;
} }
strings = backtrace_symbols (array, size); strings = backtrace_symbols (array, (int) size);
if (strings) { if (strings) {

View File

@ -33,8 +33,8 @@ BBT_Offset::BBT_Offset (double dbeats)
assert (dbeats >= 0); assert (dbeats >= 0);
bars = 0; bars = 0;
beats = lrint (floor (dbeats)); beats = (int32_t) lrint (floor (dbeats));
ticks = lrint (floor (Temporal::ticks_per_beat * fmod (dbeats, 1.0))); ticks = (int32_t) lrint (floor (Temporal::ticks_per_beat * fmod (dbeats, 1.0)));
} }
std::ostream& std::ostream&

View File

@ -188,9 +188,9 @@ struct LIBTEMPORAL_API BBT_Offset
} }
BBT_Offset & operator*=(double factor) { BBT_Offset & operator*=(double factor) {
bars = lrint (bars * factor); bars = (int32_t) lrint (bars * factor);
beats = lrint (beats * factor); beats = (int32_t) lrint (beats * factor);
ticks = lrint (ticks * factor); ticks = (int32_t) lrint (ticks * factor);
return *this; return *this;
} }
@ -202,9 +202,9 @@ struct LIBTEMPORAL_API BBT_Offset
} }
BBT_Offset & operator/=(double factor) { BBT_Offset & operator/=(double factor) {
bars = lrint (bars / factor); bars = (int32_t) lrint (bars / factor);
beats = lrint (beats / factor); beats = (int32_t) lrint (beats / factor);
ticks = lrint (ticks / factor); ticks = (int32_t) lrint (ticks / factor);
return *this; return *this;
} }

View File

@ -76,7 +76,7 @@ public:
static Beats from_double (double beats) { static Beats from_double (double beats) {
double whole; double whole;
const double frac = modf (beats, &whole); const double frac = modf (beats, &whole);
return Beats (whole, (int32_t) rint (frac * PPQN)); return Beats ((int64_t) whole, (int64_t) rint (frac * PPQN));
} }
/** Create from an integer number of beats. */ /** Create from an integer number of beats. */
@ -104,7 +104,7 @@ public:
int64_t to_ticks (uint32_t ppqn) const { return (_ticks * ppqn) / PPQN; } int64_t to_ticks (uint32_t ppqn) const { return (_ticks * ppqn) / PPQN; }
int64_t get_beats () const { return _ticks / PPQN; } int64_t get_beats () const { return _ticks / PPQN; }
int32_t get_ticks () const { return _ticks % PPQN; } int32_t get_ticks () const { return (int32_t) (_ticks % PPQN); }
Beats& operator=(double time) { Beats& operator=(double time) {
*this = from_double (time); *this = from_double (time);

View File

@ -98,7 +98,7 @@ class /*LIBTEMPORAL_API*/ Point : public point_hook, public MapOwned {
LIBTEMPORAL_API superclock_t sclock() const { return _sclock; } LIBTEMPORAL_API superclock_t sclock() const { return _sclock; }
LIBTEMPORAL_API Beats const & beats() const { return _quarters; } LIBTEMPORAL_API Beats const & beats() const { return _quarters; }
LIBTEMPORAL_API BBT_Time const & bbt() const { return _bbt; } LIBTEMPORAL_API BBT_Time const & bbt() const { return _bbt; }
LIBTEMPORAL_API samplepos_t sample(samplecnt_t sr) const { return superclock_to_samples (sclock(), sr); } LIBTEMPORAL_API samplepos_t sample (int sr) const { return superclock_to_samples (sclock(), sr); }
LIBTEMPORAL_API virtual timepos_t time() const = 0; LIBTEMPORAL_API virtual timepos_t time() const = 0;
@ -179,7 +179,7 @@ class LIBTEMPORAL_API Tempo {
* @param npm Note Types per minute * @param npm Note Types per minute
* @param note_type Note Type (default `4': quarter note) * @param note_type Note Type (default `4': quarter note)
*/ */
Tempo (double npm, int note_type) Tempo (double npm, int8_t note_type)
: _npm (npm) : _npm (npm)
, _enpm (npm) , _enpm (npm)
, _superclocks_per_note_type (double_npm_to_scpn (npm)) , _superclocks_per_note_type (double_npm_to_scpn (npm))
@ -192,7 +192,7 @@ class LIBTEMPORAL_API Tempo {
, _continuing (false) , _continuing (false)
{} {}
Tempo (double npm, double enpm, int note_type) Tempo (double npm, double enpm, int8_t note_type)
: _npm (npm) : _npm (npm)
, _enpm (npm) , _enpm (npm)
, _superclocks_per_note_type (double_npm_to_scpn (npm)) , _superclocks_per_note_type (double_npm_to_scpn (npm))
@ -208,11 +208,11 @@ class LIBTEMPORAL_API Tempo {
/* these five methods should only be used to show and collect information to the user (for whom /* these five methods should only be used to show and collect information to the user (for whom
* bpm as a floating point number is the obvious representation) * bpm as a floating point number is the obvious representation)
*/ */
double note_types_per_minute () const { return (superclock_ticks_per_second() * 60.0) / _superclocks_per_note_type; } double note_types_per_minute () const { return ((double) superclock_ticks_per_second() * 60.0) / (double) _superclocks_per_note_type; }
double end_note_types_per_minute () const { return (superclock_ticks_per_second() * 60.0) / _end_superclocks_per_note_type; } double end_note_types_per_minute () const { return ((double) superclock_ticks_per_second() * 60.0) / (double) _end_superclocks_per_note_type; }
double quarter_notes_per_minute() const { return (superclock_ticks_per_second() * 60.0 * 4.0) / (_note_type * _superclocks_per_note_type); } double quarter_notes_per_minute() const { return ((double) superclock_ticks_per_second() * 60.0 * 4.0) / (_note_type * (double) _superclocks_per_note_type); }
double samples_per_note_type(samplecnt_t sr) const { return superclock_to_samples (superclocks_per_note_type (), sr); } double samples_per_note_type(int sr) const { return superclock_to_samples (superclocks_per_note_type (), sr); }
double samples_per_quarter_note(samplecnt_t sr) const { return superclock_to_samples (superclocks_per_quarter_note(), sr); } double samples_per_quarter_note(int sr) const { return superclock_to_samples (superclocks_per_quarter_note(), sr); }
void set_note_types_per_minute (double npm); void set_note_types_per_minute (double npm);