Commit 86f4013e authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Adding initial project (merge from SVN)

parent e13bf5b8
cmake_minimum_required( VERSION 2.8 )
project( VALua )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
# dependencies
vista_use_package( ITABase REQUIRED FIND_DEPENDENCIES )
vista_use_package( VANet REQUIRED FIND_DEPENDENCIES )
vista_use_package( VABase REQUIRED FIND_DEPENDENCIES )
vista_use_package( Lua REQUIRED )
# includes
include_directories( "include" )
# Including the source files of all source subfolders recursively
include( "include/_SourceFiles.cmake" )
include( "src/_SourceFiles.cmake" )
# compiler
add_definitions( -DITA_BASE_DLL -_DVA_BASE_DLL -_DVA_NET_DLL )
# linker
add_library( VALua ${ProjectSources} )
target_link_libraries( VALua ${VISTA_USE_PACKAGE_LIBRARIES} )
# config
vista_configure_lib( VALua )
vista_install( VALua )
set( VALUA_INCLUDE_OUTDIR "${CMAKE_CURRENT_SOURCE_DIR}/include" )
vista_create_cmake_configs( VALua )
vista_create_default_info_file( VALua )
set_property( TARGET VALua PROPERTY FOLDER "ITACoreLibs" )
/*
* VAShell - Eine Shell (Kommandozeilen) zur Steuerung von VA mittels Lua
*/
#include <iostream>
#include <ITAException.h>
#include <VACore.h>
#include <VACoreFactory.h>
#include <VACoreVersion.h>
#include <VAException.h>
#include <VALuaShell.h>
using namespace std;
int main(int argc, char* argv[]) {
IVACore* pVACore(nullptr);
IVALuaShell* pShell(nullptr);
try {
pVACore = VACore::CreateCoreInstance();
// TODO: Ntig? pVACore->SetDebugStream(&std::cout);
pShell = IVALuaShell::Create();
pShell->SetCoreInstance(pVACore);
CVACoreVersionInfo ver;
pVACore->GetVersionInfo(&ver);
cout << ver.ToString() << " initializing ..." << endl << endl;
pVACore->Initialize();
cout << endl << "VACore Ready." << endl << endl;
if (argc > 1) {
// Skript ausfhren
for (int i=1; i<argc; i++) {
std::string sExecLine = argv[i];
pShell->ExecuteLuaScript(sExecLine);
}
} else {
// Shell-Modus
cout << "> ";
std::string sLine;
while (true) {
getline(cin, sLine);
// DEBUG: cout << "Got line >" << sLine << "<" << endl;
if (sLine == "exit") break;
if (sLine == "quit") break;
pShell->HandleInputLine(sLine);
cout << "> ";
}
}
delete pShell;
delete pVACore;
return 0;
} catch (CVAException& e) {
delete pShell;
delete pVACore;
cerr << "Error: " << e << endl;
return 255;
} catch (...) {
delete pShell;
delete pVACore;
cerr << "Error: An unknown error occured" << endl;
return 255;
}
}
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "..\\Res\\VAShell.ico"
int GetState() const;
void Initialize();
void Finalize();
void Reset();
# Directivities
int LoadDirectivity(const std::string sFilename, const std::string sName="")=0;
bool FreeDirectivity(int iDirID);
# $Id:$
set( RelativeDir "Generation" )
set( RelativeSourceGroup "Generation" )
set( DirFiles
template.cpp
_SourceFiles.cmake
)
set( DirFiles_SourceGroup "${RelativeSourceGroup}" )
set( LocalSourceGroupFiles )
foreach( File ${DirFiles} )
list( APPEND LocalSourceGroupFiles "${RelativeDir}/${File}" )
list( APPEND ProjectSources "${RelativeDir}/${File}" )
endforeach()
source_group( ${DirFiles_SourceGroup} FILES ${LocalSourceGroupFiles} )
#
# Info: Only input parameters via call by value possible!
#
$INTERFACE_DEFINITION = "VACore.interface.txt";
$CODE_TEMPLATE = "template.cpp";
@RETURN_TYPES = ("void",
"bool",
"int",
"double",
"std::string");
@INPUT_TYPES = ("void",
"bool",
"int",
"double",
"const std::string&");
@FUNCTION_MODIFIERS = ("const");
# Read a file into a scalar
sub readFile {
($filename) = @_;
open (FILE, "<$filename") || die $!;
$data = do { local $/; <FILE> };
close FILE;
return $data;
}
# Parse interface definition
open (in, "<$INTERFACE_DEFINITION") || die $!;
$n=0;
@functions = ();
while (<in>){
# in $_ steht die aktuelle Zeile
$n++;
chomp($_);
#print "$n: $_\n";
# Skip comments and empty lines
next if ($_ =~ /(^\#.*)|^\w*$/);
#print "Parsing line: $n: $_\n";
# Parse method definition
# Format: RETURN_TYPE METHOD_NAME(MODIFIER PARAM_TYPE (REFSYMBOL)*) MODIFIER
if ($_ =~ /^(.*)\s+(\w+?)\s*\((.*)\)\s*(.*)\s*\;\s*/) {
$return_type = $1;
$function_name = $2;
@input_defs = split(/,/, $3);
$function_modifier = $4;
# Check the return type
$return_type =~ s/^\s+//;
$return_type =~ s/\s+$//;
if (! grep /$return_type/, @RETURN_TYPES) {
print STDERR "Invalid return type \"$return_type\" in line $n\n";
exit 255;
}
# Parse the input parameters
undef @input_params;
foreach $input_def (@input_defs) {
# Remove whitespaces
$input_def =~ s/^\s+//;
$input_def =~ s/\s+$//;
#print "Input def: >$input_def<\n";
# Check the input type
if (! grep /$input_def/, @INPUT_TYPES) {
print STDERR "Invalid input type \"$input_def\" in line $n\n";
exit 255;
}
push(@input_params, $input_def);
# Format: INPUT_TYPE (NAME)?
#if ($input =~ /^\s*(\w+)(\s+\w+)?\s*$/) {
# if ($input =~ /^(\.*)$/) {
# print "TYPE = $1\n";
# print "NAME = $2\n";
# print "3 = $3\n";
# } else {
# print "NOmatch\n";
# }
}
print "Input params: >".join(",", @input_params)."<\n";
# Check the modifier (may only be const)
$function_modifier =~ s/^\s+//;
$function_modifier =~ s/\s+$//;
if ($function_modifier && ! grep /$function_modifier/, @FUNCTION_MODIFIERS) {
print STDERR "Invalid function modifier \"$function_modifier\" in line $n\n";
exit 255;
}
print "Modifier: >$function_modifier<\n";
# Store function description
push(@functions, { return_type => $return_type,
name => $function_name,
input_types => \@input_params,
modifier => $function_modifier } );
}
}
close in;
# Print parsing results
print "Found ".scalar(@functions)." functions\n\n";
foreach $function (@functions) {
# print "Function:\t".$function->{'name'}."\n";
# print "Returns: \t".$function->{'return_type'}."\n";
# print "Params: \t".join(",", @{$function->{'input_types'}})."\n";
# print "Modifier:\t".$function->{'modifier'}."\n";
print $function->{'return_type'}." ".$function->{'name'}."(".join(",", @{$function->{'input_types'}}).") ".$function->{'modifier'}."\n";
}
# for $i (0..$#functions) {
# @a = $functions[$i]{'input_types'};
# print "a = @a\n";
# print scalar(@a);
# print $functions[$i]{'return_type'}." ".$functions[$i]{'name'}."(".join(",", $functions[$i]{'input_types'}).") ".$functions[$i]{'modifier'}."\n";
# }
#exit 0;
# -------------------------------------
sub generateMethodDeclaration {
my %function = @_;
# Format int NAME(lua_State* L);
return sprintf("\tint %s(lua_State* L);\n", $function->{'name'});
}
sub generateMethodRegistration {
my %function = @_;
# Format method(CVALuaCoreObject, NAME),
return sprintf("\tmethod(CVALuaCoreObject, %s),\n", $function->{'name'});
}
sub generateMethodImplementation {
my %function = @_;
# int CVALuaCoreObject::LoadDirectivity(lua_State *L) {
# /* [int] core:LoadDirectivity( filename, name ) */
# VASHELL_TRY();
# std::string sFilename;
# std::string sName;
# int argc = lua_gettop(L);
# sFilename = luaL_checkstring(L, 1);
# if (argc >= 2) sName = luaL_checkstring(L, 2);
# lua_pushinteger(L, m_pCore->LoadDirectivity(sFilename, sName));
# return 1;
# VASHELL_CATCH();
# }
$rt = $function->{'return_type'};
$n = $function->{'name'};
$m = " ".$function->{'modifier'} if ($function->{'modifier'});
$z = join(",", @{$function->{'input_types'}});
# Signature
$x .= sprintf("int CVALuaCoreObject::%s(lua_State* L) {\n", $n);
# Comment
$x .= sprintf("\t/* %s %s(%s)%s; */\n", $function->{'return_type'}, $n, $z, $m);
$x .= sprintf("\n\tVASHELL_TRY();\n\n");
# Input parameters
$k=0;
undef @y;
foreach $t (@{$function->{'input_types'}}) {
$k++;
if ($t eq "bool") {
$x .= sprintf("\t%s bParam%d = (luaL_checkint(L, %d) != 0);\n", $t, $k, $k);
push(@y, sprintf("bParam%d", $k));
}
if ($t eq "int") {
$x .= sprintf("\t%s iParam%d = luaL_checkint(L, %d);\n", $t, $k, $k);
push(@y, sprintf("iParam%d", $k));
}
if ($t eq "double") {
$x .= sprintf("\t%s dParam%d = luaL_checknumber(L, %d);\n", $t, $k, $k);
push(@y, sprintf("dParam%d", $k));
}
if (($t eq "const std::string&") || ($t eq "std::string")) {
$x .= sprintf("\tstd::string sParam%d = luaL_checkstring(L, %d);\n", $k, $k);
push(@y, sprintf("sParam%d", $k));
}
}
# No return value
if ($rt eq "void") {
$x .= sprintf("\tm_pCore->%s(%s);\n", $n, join(", ", @y));
$x .= sprintf("\treturn 0;\n");
}
# Boolean return value
if ($rt eq "bool") {
$x .= sprintf("\tlua_pushboolean(L, m_pCore->%s(%s) );\n", $n, join(", ", @y));
$x .= sprintf("\treturn 1;\n");
}
# Integer return value
if ($rt eq "int") {
$x .= sprintf("\tlua_pushinteger(L, m_pCore->%s(%s) );\n", $n, join(", ", @y));
$x .= sprintf("\treturn 1;\n");
}
# Double return value
if ($rt eq "double") {
$x .= sprintf("\tlua_pushnumber(L, m_pCore->%s(%s) );\n", $n, join(", ", @y));
$x .= sprintf("\treturn 1;\n");
}
# String return value
if ($rt eq "std::string") {
$x .= sprintf("\tlua_pushnumber(L, m_pCore->%s(%s) );\n", $n, join(", ", @y));
$x .= sprintf("\treturn 1;\n");
}
$x .= sprintf("\n\tVASHELL_CATCH();\n");
$x .= sprintf("}\n\n");
return $x;
}
# Build the code blocks
foreach $function (@functions) {
$decl = $decl.generateMethodDeclaration($function);
$regs = $regs.generateMethodRegistration($function);
$impl = $impl.generateMethodImplementation($function);
}
# Load the template and substitute the macros
$out = readFile($CODE_TEMPLATE);
$out =~ s/\/\*\*\* GENERATE_METHOD_DECLARATIONS \*\*\*\//$decl/g;
$out =~ s/\/\*\*\* GENERATE_METHOD_REGISTRATIONS \*\*\*\//$regs/g;
$out =~ s/\/\*\*\* GENERATE_METHOD_IMPLEMENTATIONS \*\*\*\//$impl/g;
print "$out\n";
#ifndef __VACVALuaCoreObject_H__
#define __VACVALuaCoreObject_H__
#include "luna.h"
#include <VACore.h>
#include <VACoreVersion.h>
#include <VAException.h>
// Vorwrtsdeklarationen
class IVACore;
/**
* Diese abstrakte Klasse realisiert ein Lua-Objekt, welches die gleiche Schnittstelle
* anbietet wie IVACore und Methoden-Aufrufe aus Lua an eine Instanz des IVACore delegiert.
* Sie fungiert also als Adapterklasse zwischen Lua und C++.
*/
class CVALuaCoreObject {
public:
static const char className[]; // Klassenname in Lua
static Luna<CVALuaCoreObject>::RegType methods[]; // Methoden-Bindings
// Konstruktor. Nimmt als Argument den Pointer zum Core vom Lua-Stack
CVALuaCoreObject(lua_State *L);
~CVALuaCoreObject();
int GetVersionInfo(lua_State *L);
int GetState(lua_State *L);
int Reset(lua_State *L);
/*** GENERATE_METHOD_DECLARATIONS ***/
private:
IVACore* m_pCore;
};
const char CVALuaCoreObject::className[] = "VACore";
#define method(class, name) {#name, &class::name}
Luna<CVALuaCoreObject>::RegType CVALuaCoreObject::methods[] = {
/*** GENERATE_METHOD_REGISTRATIONS ***/
{0,0}
};
// Makros fr Try-/Catch-Blcke in den Funktionsumsetzern (Erspart Tipparbeit)
// Hierbei werden C++ Exceptions abgefangen und in Lua-Errors umgesetzt
#define VASHELL_TRY(); try {
#define VASHELL_CATCH(); } \
catch (CVAException& e) { luaL_error(L, e.ToString().c_str()); return 1; } \
catch (...) { luaL_error(L, "Unknown error occured"); return 1; }
/*** GENERATE_METHOD_IMPLEMENTATIONS ***/
#endif // __VACVALuaCoreObject_H__
#ifndef __VALUA_DEFS_H__
#define __VALUA_DEFS_H__
// Bindungskonventionen
#ifdef VALUA_DLL
// Dynamische Bibliothek
#ifdef VALUA_EXPORTS
#define VALUA_API __declspec(dllexport)
#else
#define VALUA_API __declspec(dllimport)
#endif
#else
// Statische Bibliothek
#define VALUA_API
#endif
// Disable STL template-instantiiation warning with DLLs for Visual C++
#if defined (_MSC_VER)
#pragma warning(disable: 4251)
#endif
// --= Version =-----------------------------------------------
#define VALUA_VERSION_MAJOR 1
#define VALUA_VERSION_MINOR 21
#define VALUA_SVN_DATE "$Date: 2012-06-26 15:42:59 +0200 (Di, 26 Jun 2012) $"
#define VALUA_SVN_REVISION "$Revision: 2734 $"
#endif // __VALUA_DEFS_H__
#ifndef __VALUA_SHELL_H__
#define __VALUA_SHELL_H__
#include <VALuaDefs.h>
#include <iostream>
#include <ostream>
#include <string>
// Vorwrtsdeklarationen
class IVACore;
/**
* Diese abstrakte Klasse definiert die Schnittstelle fr eine Shell
* welche einen Lua-Interpreter beherbergt und es erlaubt einen VACore
* mittels Lua anzusprechen und zu steuern.
*
* Konkrete Instanzen der Klasse mssen mit der Factory method erzeugt werden.
*/
class VALUA_API IVALuaShell {
public:
//! Factory method
static IVALuaShell* Create();
//! Version
static std::string GetVersionStr();
virtual ~IVALuaShell();
// Kern-Instanz setzen
virtual void SetCoreInstance(IVACore* pVACore)=0;
// Ausgabe-Stream setzen
virtual void SetOutputStream(std::ostream* posStdOut)=0;
// Fehler-Stream setzen
virtual void SetErrorStream(std::ostream* posStdErr)=0;
// Status zurckgeben
virtual int GetStatus() const=0;
// Status setzen (dieser kann in Lua abgefragt werden
// und zur externen Steuerung eines Skripts verwendet werden)
virtual void SetStatus(int iStatus)=0;
// Ein Lua-Skript ausfhren (von Datei)
virtual void ExecuteLuaScript(const std::string& sFilename)=0;
// Eine Eingabezeile verarbeiten
virtual void HandleInputLine(const std::string& sLine)=0;
};
#endif // __VALUA_SHELL_H__
\ No newline at end of file
# $Id:$
set( RelativeDir "Include" )
set( RelativeSourceGroup "Include" )
set( DirFiles
VALuaDefs.h
VALuaShell.h
_SourceFiles.cmake
)
set( DirFiles_SourceGroup "${RelativeSourceGroup}" )
set( LocalSourceGroupFiles )
foreach( File ${DirFiles} )
list( APPEND LocalSourceGroupFiles "${RelativeDir}/${File}" )
list( APPEND ProjectSources "${RelativeDir}/${File}" )
endforeach()
source_group( ${DirFiles_SourceGroup} FILES ${LocalSourceGroupFiles} )
File added
print("\n")
print(" ----- Test von Conversion functions ! -------")
print("\n")
core = VACore() -- Zgruff auf dem Kern-Instanz
print(core:GetVersionInfo())
print("\n")
AuraMode = core:GetAuralizationModeStr( 5 )
print("Auralization Mode : " .. AuraMode)
Volume = core:GetVolumeStrDecibel( 2.8 )
print("Volume : " .. Volume)
\ No newline at end of file
print("\n")
print(" ----- Test von allen Directivities Methoden ! -------")
print("\n")
core = VACore() -- Zgruff auf dem Kern-Instanz
print(core:GetVersionInfo())
print("\n")
direct1 = core:LoadDirectivity("Floete.ddb", "Directivity1")
print("\n")
print(" ----- Test von Conversion functions ! -------")
print("\n")
core = VACore() -- Zgruff auf dem Kern-Instanz
print(core:GetVersionInfo())
print("\n")
core:SetInputGain( 1, 4.8 )
GainIn = core:GetInputGain( 1 )
print("Input Gain = " ..GainIn )
core:SetOutputGain( 3.6 )
GainOut = core:GetOutputGain()
print("Output Gain : " ..GainOut)
\ No newline at end of file