/[svn]/linuxsampler/trunk/src/scriptvm/CoreVMFunctions.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/CoreVMFunctions.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3585 by schoenebeck, Fri Aug 30 17:51:24 2019 UTC revision 3590 by schoenebeck, Mon Sep 2 09:03:31 2019 UTC
# Line 982  bool CoreVMFunction_sort::acceptsArgType Line 982  bool CoreVMFunction_sort::acceptsArgType
982  // use std sort algorithms on our arrays. It might look a bit more complicated  // use std sort algorithms on our arrays. It might look a bit more complicated
983  // than it ought to be, but there is one reason for the large amount of  // than it ought to be, but there is one reason for the large amount of
984  // 'adapter' code below: the STL std algorithms rely on 'lvalues' to do their  // 'adapter' code below: the STL std algorithms rely on 'lvalues' to do their
985  // e.g. sorting) jobs, that is they expect containers to have 'localizeable'  // (e.g. sorting) jobs, that is they expect containers to have 'localizeable'
986  // data which essentially means their data should reside somewhere in memory and  // data which essentially means their data should reside somewhere in memory and
987  // directly be accessible (readable and writable) there, which is not the case  // directly be accessible (readable and writable) there, which is not the case
988  // with our VM interfaces which actually always require virtual getter and  // with our VM interfaces which actually always require virtual getter and
# Line 1318  VMFnResult* CoreVMFunction_int_to_real:: Line 1318  VMFnResult* CoreVMFunction_int_to_real::
1318      });      });
1319  }  }
1320    
1321    ///////////////////////////////////////////////////////////////////////////
1322    // built-in script function:  round()
1323    
1324    StdUnit_t CoreVMFunction_round::returnUnitType(VMFnArgs* args) {
1325        return args->arg(0)->asNumber()->unitType();
1326    }
1327    
1328    bool CoreVMFunction_round::returnsFinal(VMFnArgs* args) {
1329        return args->arg(0)->asNumber()->isFinal();
1330    }
1331    
1332    VMFnResult* CoreVMFunction_round::exec(VMFnArgs* args) {
1333        VMRealExpr* realExpr = args->arg(0)->asReal();
1334        vmfloat f = realExpr->evalReal();
1335        if (sizeof(vmfloat) == sizeof(float))
1336            f = ::roundf(f);
1337        else
1338            f = ::round(f);
1339        return successResult({
1340            .value = f,
1341            .unitFactor = realExpr->unitFactor()
1342        });
1343    }
1344    
1345    ///////////////////////////////////////////////////////////////////////////
1346    // built-in script function:  ceil()
1347    
1348    StdUnit_t CoreVMFunction_ceil::returnUnitType(VMFnArgs* args) {
1349        return args->arg(0)->asNumber()->unitType();
1350    }
1351    
1352    bool CoreVMFunction_ceil::returnsFinal(VMFnArgs* args) {
1353        return args->arg(0)->asNumber()->isFinal();
1354    }
1355    
1356    VMFnResult* CoreVMFunction_ceil::exec(VMFnArgs* args) {
1357        VMRealExpr* realExpr = args->arg(0)->asReal();
1358        vmfloat f = realExpr->evalReal();
1359        if (sizeof(vmfloat) == sizeof(float))
1360            f = ::ceilf(f);
1361        else
1362            f = ::ceil(f);
1363        return successResult({
1364            .value = f,
1365            .unitFactor = realExpr->unitFactor()
1366        });
1367    }
1368    
1369    ///////////////////////////////////////////////////////////////////////////
1370    // built-in script function:  floor()
1371    
1372    StdUnit_t CoreVMFunction_floor::returnUnitType(VMFnArgs* args) {
1373        return args->arg(0)->asNumber()->unitType();
1374    }
1375    
1376    bool CoreVMFunction_floor::returnsFinal(VMFnArgs* args) {
1377        return args->arg(0)->asNumber()->isFinal();
1378    }
1379    
1380    VMFnResult* CoreVMFunction_floor::exec(VMFnArgs* args) {
1381        VMRealExpr* realExpr = args->arg(0)->asReal();
1382        vmfloat f = realExpr->evalReal();
1383        if (sizeof(vmfloat) == sizeof(float))
1384            f = ::floorf(f);
1385        else
1386            f = ::floor(f);
1387        return successResult({
1388            .value = f,
1389            .unitFactor = realExpr->unitFactor()
1390        });
1391    }
1392    
1393    ///////////////////////////////////////////////////////////////////////////
1394    // built-in script function:  sqrt()
1395    
1396    StdUnit_t CoreVMFunction_sqrt::returnUnitType(VMFnArgs* args) {
1397        return args->arg(0)->asNumber()->unitType();
1398    }
1399    
1400    bool CoreVMFunction_sqrt::returnsFinal(VMFnArgs* args) {
1401        return args->arg(0)->asNumber()->isFinal();
1402    }
1403    
1404    VMFnResult* CoreVMFunction_sqrt::exec(VMFnArgs* args) {
1405        VMRealExpr* realExpr = args->arg(0)->asReal();
1406        vmfloat f = realExpr->evalReal();
1407        if (sizeof(vmfloat) == sizeof(float))
1408            f = ::sqrtf(f);
1409        else
1410            f = ::sqrt(f);
1411        return successResult({
1412            .value = f,
1413            .unitFactor = realExpr->unitFactor()
1414        });
1415    }
1416    
1417    ///////////////////////////////////////////////////////////////////////////
1418    // built-in script function:  log()
1419    
1420    StdUnit_t CoreVMFunction_log::returnUnitType(VMFnArgs* args) {
1421        return args->arg(0)->asNumber()->unitType();
1422    }
1423    
1424    bool CoreVMFunction_log::returnsFinal(VMFnArgs* args) {
1425        return args->arg(0)->asNumber()->isFinal();
1426    }
1427    
1428    VMFnResult* CoreVMFunction_log::exec(VMFnArgs* args) {
1429        VMRealExpr* realExpr = args->arg(0)->asReal();
1430        vmfloat f = realExpr->evalReal();
1431        if (sizeof(vmfloat) == sizeof(float))
1432            f = ::logf(f);
1433        else
1434            f = ::log(f);
1435        return successResult({
1436            .value = f,
1437            .unitFactor = realExpr->unitFactor()
1438        });
1439    }
1440    
1441    ///////////////////////////////////////////////////////////////////////////
1442    // built-in script function:  log2()
1443    
1444    StdUnit_t CoreVMFunction_log2::returnUnitType(VMFnArgs* args) {
1445        return args->arg(0)->asNumber()->unitType();
1446    }
1447    
1448    bool CoreVMFunction_log2::returnsFinal(VMFnArgs* args) {
1449        return args->arg(0)->asNumber()->isFinal();
1450    }
1451    
1452    VMFnResult* CoreVMFunction_log2::exec(VMFnArgs* args) {
1453        VMRealExpr* realExpr = args->arg(0)->asReal();
1454        vmfloat f = realExpr->evalReal();
1455        if (sizeof(vmfloat) == sizeof(float))
1456            f = ::log2f(f);
1457        else
1458            f = ::log2(f);
1459        return successResult({
1460            .value = f,
1461            .unitFactor = realExpr->unitFactor()
1462        });
1463    }
1464    
1465    ///////////////////////////////////////////////////////////////////////////
1466    // built-in script function:  log10()
1467    
1468    StdUnit_t CoreVMFunction_log10::returnUnitType(VMFnArgs* args) {
1469        return args->arg(0)->asNumber()->unitType();
1470    }
1471    
1472    bool CoreVMFunction_log10::returnsFinal(VMFnArgs* args) {
1473        return args->arg(0)->asNumber()->isFinal();
1474    }
1475    
1476    VMFnResult* CoreVMFunction_log10::exec(VMFnArgs* args) {
1477        VMRealExpr* realExpr = args->arg(0)->asReal();
1478        vmfloat f = realExpr->evalReal();
1479        if (sizeof(vmfloat) == sizeof(float))
1480            f = ::log10f(f);
1481        else
1482            f = ::log10(f);
1483        return successResult({
1484            .value = f,
1485            .unitFactor = realExpr->unitFactor()
1486        });
1487    }
1488    
1489    ///////////////////////////////////////////////////////////////////////////
1490    // built-in script function:  exp()
1491    
1492    StdUnit_t CoreVMFunction_exp::returnUnitType(VMFnArgs* args) {
1493        return args->arg(0)->asNumber()->unitType();
1494    }
1495    
1496    bool CoreVMFunction_exp::returnsFinal(VMFnArgs* args) {
1497        return args->arg(0)->asNumber()->isFinal();
1498    }
1499    
1500    VMFnResult* CoreVMFunction_exp::exec(VMFnArgs* args) {
1501        VMRealExpr* realExpr = args->arg(0)->asReal();
1502        vmfloat f = realExpr->evalReal();
1503        if (sizeof(vmfloat) == sizeof(float))
1504            f = ::expf(f);
1505        else
1506            f = ::exp(f);
1507        return successResult({
1508            .value = f,
1509            .unitFactor = realExpr->unitFactor()
1510        });
1511    }
1512    
1513    ///////////////////////////////////////////////////////////////////////////
1514    // built-in script function:  pow()
1515    
1516    bool CoreVMFunction_pow::acceptsArgUnitType(vmint iArg, StdUnit_t type) const {
1517        if (iArg == 0)
1518            return true;
1519        else
1520            return type == VM_NO_UNIT;
1521    }
1522    
1523    bool CoreVMFunction_pow::acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const {
1524        return iArg == 0;
1525    }
1526    
1527    StdUnit_t CoreVMFunction_pow::returnUnitType(VMFnArgs* args) {
1528        // pow() only allows unit for its 1st argument
1529        return args->arg(0)->asNumber()->unitType();
1530    }
1531    
1532    bool CoreVMFunction_pow::returnsFinal(VMFnArgs* args) {
1533        // pow() only allows 'final'ness for its 1st argument
1534        return args->arg(0)->asNumber()->isFinal();
1535    }
1536    
1537    VMFnResult* CoreVMFunction_pow::exec(VMFnArgs* args) {
1538        VMRealExpr* arg0 = args->arg(0)->asReal();
1539        VMRealExpr* arg1 = args->arg(1)->asReal();
1540        vmfloat a = arg0->evalReal();
1541        vmfloat b = arg1->evalReal();
1542        if (sizeof(vmfloat) == sizeof(float)) {
1543            return successResult({
1544                .value = ::powf(a,b),
1545                .unitFactor = arg0->unitFactor()
1546            });
1547        } else {
1548            return successResult({
1549                .value = ::pow(a,b),
1550                .unitFactor = arg0->unitFactor()
1551            });
1552        }
1553    }
1554    
1555    ///////////////////////////////////////////////////////////////////////////
1556    // built-in script function:  sin()
1557    
1558    StdUnit_t CoreVMFunction_sin::returnUnitType(VMFnArgs* args) {
1559        return args->arg(0)->asNumber()->unitType();
1560    }
1561    
1562    bool CoreVMFunction_sin::returnsFinal(VMFnArgs* args) {
1563        return args->arg(0)->asNumber()->isFinal();
1564    }
1565    
1566    VMFnResult* CoreVMFunction_sin::exec(VMFnArgs* args) {
1567        VMRealExpr* realExpr = args->arg(0)->asReal();
1568        vmfloat f = realExpr->evalReal();
1569        if (sizeof(vmfloat) == sizeof(float))
1570            f = ::sinf(f);
1571        else
1572            f = ::sin(f);
1573        return successResult({
1574            .value = f,
1575            .unitFactor = realExpr->unitFactor()
1576        });
1577    }
1578    
1579    ///////////////////////////////////////////////////////////////////////////
1580    // built-in script function:  cos()
1581    
1582    StdUnit_t CoreVMFunction_cos::returnUnitType(VMFnArgs* args) {
1583        return args->arg(0)->asNumber()->unitType();
1584    }
1585    
1586    bool CoreVMFunction_cos::returnsFinal(VMFnArgs* args) {
1587        return args->arg(0)->asNumber()->isFinal();
1588    }
1589    
1590    VMFnResult* CoreVMFunction_cos::exec(VMFnArgs* args) {
1591        VMRealExpr* realExpr = args->arg(0)->asReal();
1592        vmfloat f = realExpr->evalReal();
1593        if (sizeof(vmfloat) == sizeof(float))
1594            f = ::cosf(f);
1595        else
1596            f = ::cos(f);
1597        return successResult({
1598            .value = f,
1599            .unitFactor = realExpr->unitFactor()
1600        });
1601    }
1602    
1603    ///////////////////////////////////////////////////////////////////////////
1604    // built-in script function:  tan()
1605    
1606    StdUnit_t CoreVMFunction_tan::returnUnitType(VMFnArgs* args) {
1607        return args->arg(0)->asNumber()->unitType();
1608    }
1609    
1610    bool CoreVMFunction_tan::returnsFinal(VMFnArgs* args) {
1611        return args->arg(0)->asNumber()->isFinal();
1612    }
1613    
1614    VMFnResult* CoreVMFunction_tan::exec(VMFnArgs* args) {
1615        VMRealExpr* realExpr = args->arg(0)->asReal();
1616        vmfloat f = realExpr->evalReal();
1617        if (sizeof(vmfloat) == sizeof(float))
1618            f = ::tanf(f);
1619        else
1620            f = ::tan(f);
1621        return successResult({
1622            .value = f,
1623            .unitFactor = realExpr->unitFactor()
1624        });
1625    }
1626    
1627    ///////////////////////////////////////////////////////////////////////////
1628    // built-in script function:  asin()
1629    
1630    StdUnit_t CoreVMFunction_asin::returnUnitType(VMFnArgs* args) {
1631        return args->arg(0)->asNumber()->unitType();
1632    }
1633    
1634    bool CoreVMFunction_asin::returnsFinal(VMFnArgs* args) {
1635        return args->arg(0)->asNumber()->isFinal();
1636    }
1637    
1638    VMFnResult* CoreVMFunction_asin::exec(VMFnArgs* args) {
1639        VMRealExpr* realExpr = args->arg(0)->asReal();
1640        vmfloat f = realExpr->evalReal();
1641        if (sizeof(vmfloat) == sizeof(float))
1642            f = ::asinf(f);
1643        else
1644            f = ::asin(f);
1645        return successResult({
1646            .value = f,
1647            .unitFactor = realExpr->unitFactor()
1648        });
1649    }
1650    
1651    ///////////////////////////////////////////////////////////////////////////
1652    // built-in script function:  acos()
1653    
1654    StdUnit_t CoreVMFunction_acos::returnUnitType(VMFnArgs* args) {
1655        return args->arg(0)->asNumber()->unitType();
1656    }
1657    
1658    bool CoreVMFunction_acos::returnsFinal(VMFnArgs* args) {
1659        return args->arg(0)->asNumber()->isFinal();
1660    }
1661    
1662    VMFnResult* CoreVMFunction_acos::exec(VMFnArgs* args) {
1663        VMRealExpr* realExpr = args->arg(0)->asReal();
1664        vmfloat f = realExpr->evalReal();
1665        if (sizeof(vmfloat) == sizeof(float))
1666            f = ::acosf(f);
1667        else
1668            f = ::acos(f);
1669        return successResult({
1670            .value = f,
1671            .unitFactor = realExpr->unitFactor()
1672        });
1673    }
1674    
1675    ///////////////////////////////////////////////////////////////////////////
1676    // built-in script function:  atan()
1677    
1678    StdUnit_t CoreVMFunction_atan::returnUnitType(VMFnArgs* args) {
1679        return args->arg(0)->asNumber()->unitType();
1680    }
1681    
1682    bool CoreVMFunction_atan::returnsFinal(VMFnArgs* args) {
1683        return args->arg(0)->asNumber()->isFinal();
1684    }
1685    
1686    VMFnResult* CoreVMFunction_atan::exec(VMFnArgs* args) {
1687        VMRealExpr* realExpr = args->arg(0)->asReal();
1688        vmfloat f = realExpr->evalReal();
1689        if (sizeof(vmfloat) == sizeof(float))
1690            f = ::atanf(f);
1691        else
1692            f = ::atan(f);
1693        return successResult({
1694            .value = f,
1695            .unitFactor = realExpr->unitFactor()
1696        });
1697    }
1698    
1699  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.3585  
changed lines
  Added in v.3590

  ViewVC Help
Powered by ViewVC