annotate native/FloatConversion.h @ 151:5a6b8f4be9b9 tracks tip

Docs
author Chris Cannam
date Fri, 21 Apr 2017 14:33:57 +0100
parents 2370b942cd32
children
rev   line source
Chris@48 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@48 2
Chris@48 3 /*
Chris@48 4 VampyHost
Chris@48 5
Chris@48 6 Use Vamp audio analysis plugins in Python
Chris@48 7
Chris@48 8 Gyorgy Fazekas and Chris Cannam
Chris@48 9 Centre for Digital Music, Queen Mary, University of London
Chris@117 10 Copyright 2008-2015 Queen Mary, University of London
Chris@48 11
Chris@48 12 Permission is hereby granted, free of charge, to any person
Chris@48 13 obtaining a copy of this software and associated documentation
Chris@48 14 files (the "Software"), to deal in the Software without
Chris@48 15 restriction, including without limitation the rights to use, copy,
Chris@48 16 modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@48 17 of the Software, and to permit persons to whom the Software is
Chris@48 18 furnished to do so, subject to the following conditions:
Chris@48 19
Chris@48 20 The above copyright notice and this permission notice shall be
Chris@48 21 included in all copies or substantial portions of the Software.
Chris@48 22
Chris@48 23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@48 24 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@48 25 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@48 26 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
Chris@48 27 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@48 28 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@48 29 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@48 30
Chris@48 31 Except as contained in this notice, the names of the Centre for
Chris@48 32 Digital Music; Queen Mary, University of London; and the authors
Chris@48 33 shall not be used in advertising or otherwise to promote the sale,
Chris@48 34 use or other dealings in this Software without prior written
Chris@48 35 authorization.
Chris@48 36 */
Chris@48 37
Chris@48 38 #ifndef VAMPYHOST_FLOAT_CONVERSION_H
Chris@48 39 #define VAMPYHOST_FLOAT_CONVERSION_H
Chris@48 40
Chris@48 41 class FloatConversion
Chris@48 42 {
Chris@48 43 public:
Chris@48 44 static bool check(PyObject *pyValue) {
Chris@48 45 if (pyValue && PyFloat_Check(pyValue)) {
Chris@48 46 return true;
Chris@48 47 }
Chris@48 48 if (pyValue && PyLong_Check(pyValue)) {
Chris@48 49 return true;
Chris@48 50 }
Chris@102 51 #if PY_MAJOR_VERSION < 3
Chris@48 52 if (pyValue && PyInt_Check(pyValue)) {
Chris@48 53 return true;
Chris@48 54 }
Chris@102 55 #endif
Chris@48 56 return false;
Chris@48 57 }
Chris@48 58
Chris@48 59 static float convert(PyObject* pyValue) {
Chris@48 60 if (pyValue && PyFloat_Check(pyValue)) {
Chris@48 61 return (float) PyFloat_AS_DOUBLE(pyValue);
Chris@48 62 }
Chris@48 63 if (pyValue && PyLong_Check(pyValue)) {
Chris@48 64 return (float) PyLong_AsDouble(pyValue);
Chris@48 65 }
Chris@102 66 #if PY_MAJOR_VERSION < 3
Chris@48 67 if (pyValue && PyInt_Check(pyValue)) {
Chris@48 68 return (float) PyInt_AsLong(pyValue);
Chris@48 69 }
Chris@102 70 #endif
Chris@48 71 return 0.0;
Chris@48 72 }
Chris@48 73 };
Chris@48 74
Chris@48 75 #endif
Chris@48 76