Files
lmms/include/panning.h
Fawn 9aa937d391 Use templates for common geometric constants (#7558)
* add templates for common geometric constants

* oops missed one

* LD_2PI -> LD_PI

i re-added the wrong constant ffs

* CamelCase names and also verify compilation without -DLMMS_MINIMAL

* C++20 stuff

Updated to account for `<numbers>` and C++20:
- Marked all `lmms_constants.h` constants with an exact equivalent in `<numbers>` as deprecated
- Removed all `lmms_constants.h` constants where no variant is currently in use
- Using `inline constexpr`
- Using `std::floating_point` concept instead of `typename`

* add lmms::numbers namespace

* Remove panning_constants.h

Moves the four constants in panning_constants.h into panning.h, then
removes panning.h.

* Use std::exp(n) instead of powf(numbers::e, n)

* Use C++ std math functions

Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>

* Use overloaded std math functions

An attempt to fix compiler warnings on some platforms

* Remove uses of __USE_XOPEN

And also update two functions I missed from the previous commit

* Missed a few

* Fix ANOTHER std math function use

Of course there's another one

---------

Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
2025-02-03 11:52:13 -05:00

65 lines
1.8 KiB
C++

/*
* panning.h - declaration of some types, concerning the
* panning of a note
*
* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef LMMS_PANNING_H
#define LMMS_PANNING_H
#include "lmms_basics.h"
#include "Midi.h"
#include "volume.h"
#include <cmath>
namespace lmms
{
inline constexpr panning_t PanningRight = 100;
inline constexpr panning_t PanningLeft = -PanningRight;
inline constexpr panning_t PanningCenter = 0;
inline constexpr panning_t DefaultPanning = PanningCenter;
inline StereoVolumeVector panningToVolumeVector( panning_t _p,
float _scale = 1.0f )
{
StereoVolumeVector v = { { _scale, _scale } };
const float pf = _p / 100.0f;
v.vol[_p >= PanningCenter ? 0 : 1] *= 1.0f - std::abs(pf);
return v;
}
inline int panningToMidi( panning_t _p )
{
return MidiMinPanning + (int) (
( (float)( _p - PanningLeft ) ) /
( (float)( PanningRight - PanningLeft ) ) *
( (float)( MidiMaxPanning - MidiMinPanning ) ) );
}
} // namespace lmms
#endif // LMMS_PANNING_H