Mercurial > hg > vampy-host
comparison vampyhost.cpp @ 25:5379af6bef00
Add enums &c to module dictionary
author | Chris Cannam |
---|---|
date | Wed, 26 Nov 2014 09:38:56 +0000 |
parents | 392878bea53d |
children | 014c48d6f360 |
comparison
equal
deleted
inserted
replaced
24:392878bea53d | 25:5379af6bef00 |
---|---|
611 } | 611 } |
612 | 612 |
613 //Documentation for our new module | 613 //Documentation for our new module |
614 PyDoc_STRVAR(module_doc, "This is a template module just for instruction."); | 614 PyDoc_STRVAR(module_doc, "This is a template module just for instruction."); |
615 | 615 |
616 | 616 static int |
617 setint(PyObject *d, const char *name, int value) | |
618 { | |
619 PyObject *v; | |
620 int err; | |
621 v = PyInt_FromLong((long)value); | |
622 err = PyDict_SetItemString(d, name, v); | |
623 Py_XDECREF(v); | |
624 return err; | |
625 } | |
617 | 626 |
618 /* Initialization function for the module (*must* be called initxx) */ | 627 /* Initialization function for the module (*must* be called initxx) */ |
619 | 628 |
620 //module initialization (includes extern C {...} as necessary) | 629 // module initialization (includes extern C {...} as necessary) |
621 PyMODINIT_FUNC | 630 PyMODINIT_FUNC |
622 initvampyhost(void) | 631 initvampyhost(void) |
623 { | 632 { |
624 PyObject *m; | 633 PyObject *m; |
625 | 634 |
626 /* Finalize the type object including setting type of the new type | 635 if (PyType_Ready(&RealTime_Type) < 0) return; |
627 * object; doing it here is required for portability to Windows | 636 if (PyType_Ready(&Plugin_Type) < 0) return; |
628 * without requiring C++. */ | 637 |
629 | |
630 if (PyType_Ready(&RealTime_Type) < 0) | |
631 return; | |
632 | |
633 if (PyType_Ready(&Plugin_Type) < 0) | |
634 return; | |
635 | |
636 /* Create the module and add the functions */ | |
637 m = Py_InitModule3("vampyhost", vampyhost_methods, module_doc); | 638 m = Py_InitModule3("vampyhost", vampyhost_methods, module_doc); |
638 if (!m) return; | 639 if (!m) { |
640 cerr << "ERROR: initvampyhost: Failed to initialise module" << endl; | |
641 return; | |
642 } | |
639 | 643 |
640 import_array(); | 644 import_array(); |
641 | 645 |
642 PyModule_AddObject(m, "RealTime", (PyObject *)&RealTime_Type); | 646 PyModule_AddObject(m, "RealTime", (PyObject *)&RealTime_Type); |
643 } | 647 PyModule_AddObject(m, "Plugin", (PyObject *)&Plugin_Type); |
648 | |
649 // Some enum types | |
650 PyObject *dict = PyModule_GetDict(m); | |
651 if (!dict) { | |
652 cerr << "ERROR: initvampyhost: Failed to obtain module dictionary" << endl; | |
653 return; | |
654 } | |
655 | |
656 if (setint(dict, "OneSamplePerStep", | |
657 Plugin::OutputDescriptor::OneSamplePerStep) < 0 || | |
658 setint(dict, "FixedSampleRate", | |
659 Plugin::OutputDescriptor::FixedSampleRate) < 0 || | |
660 setint(dict, "VariableSampleRate", | |
661 Plugin::OutputDescriptor::VariableSampleRate) < 0 || | |
662 setint(dict, "TimeDomain", | |
663 Plugin::TimeDomain) < 0 || | |
664 setint(dict, "FrequencyDomain", | |
665 Plugin::FrequencyDomain) < 0) { | |
666 cerr << "ERROR: initvampyhost: Failed to add enums to module dictionary" << endl; | |
667 return; | |
668 } | |
669 } |