Chris@48: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@48: Chris@48: /* Chris@48: VampyHost Chris@48: Chris@48: Use Vamp audio analysis plugins in Python Chris@48: Chris@48: Gyorgy Fazekas and Chris Cannam Chris@48: Centre for Digital Music, Queen Mary, University of London Chris@117: Copyright 2008-2015 Queen Mary, University of London Chris@48: Chris@48: Permission is hereby granted, free of charge, to any person Chris@48: obtaining a copy of this software and associated documentation Chris@48: files (the "Software"), to deal in the Software without Chris@48: restriction, including without limitation the rights to use, copy, Chris@48: modify, merge, publish, distribute, sublicense, and/or sell copies Chris@48: of the Software, and to permit persons to whom the Software is Chris@48: furnished to do so, subject to the following conditions: Chris@48: Chris@48: The above copyright notice and this permission notice shall be Chris@48: included in all copies or substantial portions of the Software. Chris@48: Chris@48: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Chris@48: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Chris@48: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND Chris@48: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR Chris@48: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF Chris@48: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION Chris@48: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Chris@48: Chris@48: Except as contained in this notice, the names of the Centre for Chris@48: Digital Music; Queen Mary, University of London; and the authors Chris@48: shall not be used in advertising or otherwise to promote the sale, Chris@48: use or other dealings in this Software without prior written Chris@48: authorization. Chris@48: */ Chris@48: Chris@48: #ifndef VAMPYHOST_FLOAT_CONVERSION_H Chris@48: #define VAMPYHOST_FLOAT_CONVERSION_H Chris@48: Chris@48: class FloatConversion Chris@48: { Chris@48: public: Chris@48: static bool check(PyObject *pyValue) { Chris@48: if (pyValue && PyFloat_Check(pyValue)) { Chris@48: return true; Chris@48: } Chris@48: if (pyValue && PyLong_Check(pyValue)) { Chris@48: return true; Chris@48: } Chris@102: #if PY_MAJOR_VERSION < 3 Chris@48: if (pyValue && PyInt_Check(pyValue)) { Chris@48: return true; Chris@48: } Chris@102: #endif Chris@48: return false; Chris@48: } Chris@48: Chris@48: static float convert(PyObject* pyValue) { Chris@48: if (pyValue && PyFloat_Check(pyValue)) { Chris@48: return (float) PyFloat_AS_DOUBLE(pyValue); Chris@48: } Chris@48: if (pyValue && PyLong_Check(pyValue)) { Chris@48: return (float) PyLong_AsDouble(pyValue); Chris@48: } Chris@102: #if PY_MAJOR_VERSION < 3 Chris@48: if (pyValue && PyInt_Check(pyValue)) { Chris@48: return (float) PyInt_AsLong(pyValue); Chris@48: } Chris@102: #endif Chris@48: return 0.0; Chris@48: } Chris@48: }; Chris@48: Chris@48: #endif Chris@48: