1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-01-11 15:15:57 +01:00

Move library tree where it belongs

This commit is contained in:
ra
2010-01-24 09:19:39 +00:00
parent e74978ba77
commit 58caf78a86
6020 changed files with 2790154 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
# -----------------------------------------------------------------------------
# Build mod-script-pipe plugin
#
# EXPERIMENTAL!
# (Based on a Makefile by Leland)
#
# -----------------------------------------------------------------------------
# NOTE: Change this to the base of the Audacity source distribution, or specify
# via command line or environment
#
AUDACITY_DIR =
# -----------------------------------------------------------------------------
# NOTE: Set to the names of your objects and final module name
#
OBJS = PipeServer.o ScripterCallback.o
MOD = mod-script-pipe.so
# -----------------------------------------------------------------------------
# NOTE: Set any custom flags you may need
#
CXXFLAGS += -Wall -O9
CXXFLAGS += -DCC_HASVISIBILITY # Normally provided by configure
CXXFLAGS += -DBUILDING_SCRIPT_PIPE
CXXFLAGS += -D__WXDEBUG__ -D__WXGTK__
# -----------------------------------------------------------------------------
# Hopefully the rest is generic enough to satisfy most needs
# -----------------------------------------------------------------------------
CXXFLAGS += -DAUDACITY_DLL_API= -I$(AUDACITY_DIR)/src
CXXFLAGS += ${shell set -x ; sed -e '/override CXXFLAGS/!d;s/override CXXFLAGS += //;s@$$(top_srcdir)@$(AUDACITY_DIR)@g' $(AUDACITY_DIR)/src/Makefile}
LDFLAGS += ${shell sed -e '/^LIBS/!d;s/LIBS *=//' $(AUDACITY_DIR)/src/Makefile}
SYS = $(shell uname -s)
ifeq ($(SYS),Darwin)
CXXFLAGS += -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
LDFLAGS += $(CXXFLAGS) -dynamiclib -undefined suppress
else
CXXFLAGS += -fPIC -fvisibility=hidden
LDFLAGS += -shared
endif
LD = g++
all: basecheck $(MOD)
# -----------------------------------------------------------------------------
# Make sure we can get to the Audacity source
#
basecheck:
@if test -z "$(AUDACITY_DIR)/src/Audacity.h" ; \
then \
echo "You need to set AUDACITY_DIR equal to the base" ; \
echo "of your Audacity source directory. You can do" ; \
echo "this via an environemnt variable, include it on" ; \
echo "the make command line or set it at the top of" ; \
echo "the Makefile." ; \
exit 1 ; \
fi
# -----------------------------------------------------------------------------
# Build it
#
$(MOD): $(OBJS)
$(LD) $(LDFLAGS) -o $(MOD) $(OBJS)
@mkdir -p $(AUDACITY_DIR)/modules
@cp $(MOD) $(AUDACITY_DIR)/modules
@echo
@echo "$(MOD) has been copied to $(AUDACITY_DIR)/modules"
@echo
# -----------------------------------------------------------------------------
# Cleanup
#
clean:
-rm $(MOD) $(OBJS)

View File

@@ -0,0 +1,198 @@
#if defined(WIN32)
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
const int nBuff = 1024;
extern "C" int DoSrv( char * pIn );
extern "C" int DoSrvMore( char * pOut, int nMax );
void PipeServer()
{
HANDLE hPipeToSrv;
HANDLE hPipeFromSrv;
LPTSTR pipeNameToSrv= _T("\\\\.\\pipe\\ToSrvPipe");
hPipeToSrv = CreateNamedPipe(
pipeNameToSrv ,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT ,//| PIPE_REJECT_REMOTE_CLIENTS,
PIPE_UNLIMITED_INSTANCES,
nBuff,
nBuff,
50,//Timeout - always send straight away.
NULL);
if( hPipeToSrv == INVALID_HANDLE_VALUE)
return;
LPTSTR pipeNameFromSrv= __T("\\\\.\\pipe\\FromSrvPipe");
hPipeFromSrv = CreateNamedPipe(
pipeNameFromSrv ,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT ,//| PIPE_REJECT_REMOTE_CLIENTS,
PIPE_UNLIMITED_INSTANCES,
nBuff,
nBuff,
50,//Timeout - always send straight away.
NULL);
if( hPipeFromSrv == INVALID_HANDLE_VALUE)
return;
BOOL bConnected;
BOOL bSuccess;
DWORD cbBytesRead;
DWORD cbBytesWritten;
CHAR chRequest[ nBuff ];
CHAR chResponse[ nBuff ];
int jj=0;
for(;;)
{
printf( "Obtaining pipe\n" );
bConnected = ConnectNamedPipe(hPipeToSrv, NULL) ?
TRUE : (GetLastError()==ERROR_PIPE_CONNECTED );
printf( "Obtained to-srv %i\n", bConnected );
bConnected = ConnectNamedPipe(hPipeFromSrv, NULL) ?
TRUE : (GetLastError()==ERROR_PIPE_CONNECTED );
printf( "Obtained from-srv %i\n", bConnected );
if( bConnected )
{
for(;;)
{
printf( "About to read\n" );
bSuccess = ReadFile( hPipeToSrv, chRequest, nBuff, &cbBytesRead, NULL);
chRequest[ cbBytesRead] = '\0';
if( !bSuccess || cbBytesRead==0 )
break;
printf( "Rxd %s\n", chRequest );
DoSrv( chRequest );
jj++;
while( true )
{
int nWritten = DoSrvMore( chResponse, nBuff );
if( nWritten <= 1 )
break;
WriteFile( hPipeFromSrv, chResponse, nWritten-1, &cbBytesWritten, NULL);
}
//FlushFileBuffers( hPipeFromSrv );
}
FlushFileBuffers( hPipeToSrv );
DisconnectNamedPipe( hPipeToSrv );
FlushFileBuffers( hPipeFromSrv );
DisconnectNamedPipe( hPipeFromSrv );
break;
}
else
{
CloseHandle( hPipeToSrv );
CloseHandle( hPipeFromSrv );
}
}
CloseHandle( hPipeToSrv );
CloseHandle( hPipeFromSrv );
}
#else
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
const char fifotmpl[] = "/tmp/audacity_script_pipe.%s.%d";
const int nBuff = 1024;
extern "C" int DoSrv( char * pIn );
extern "C" int DoSrvMore( char * pOut, int nMax );
void PipeServer()
{
FILE *fromFifo = NULL;
FILE *toFifo = NULL;
int rc;
char buf[nBuff];
char toFifoName[nBuff];
char fromFifoName[nBuff];
sprintf(toFifoName, fifotmpl, "to", getuid());
sprintf(fromFifoName, fifotmpl, "from", getuid());
unlink(toFifoName);
unlink(fromFifoName);
// TODO avoid symlink security issues?
rc = mkfifo(fromFifoName, S_IRWXU) & mkfifo(toFifoName, S_IRWXU);
if (rc < 0)
{
perror("Unable to create fifos");
printf("Ignoring...");
// return;
}
fromFifo = fopen(fromFifoName, "w");
if (fromFifo == NULL)
{
perror("Unable to open fifo from server to script");
return;
}
toFifo = fopen(toFifoName, "r");
if (toFifo == NULL)
{
perror("Unable to open fifo to server from script");
return;
}
while (fgets(buf, sizeof(buf), toFifo) != NULL)
{
int len = strlen(buf);
if (len <= 1)
{
continue;
}
buf[len - 1] = '\0';
printf("Server received %s\n", buf);
DoSrv(buf);
while (true)
{
len = DoSrvMore(buf, nBuff);
if (len <= 1)
{
break;
}
printf("Server sending %s",buf);
// len - 1 because we do not send the null character
fwrite(buf, 1, len - 1, fromFifo);
}
fflush(fromFifo);
}
printf("Read failed on fifo, quitting\n");
if (toFifo != NULL)
fclose(toFifo);
if (fromFifo != NULL)
fclose(fromFifo);
unlink(toFifoName);
unlink(fromFifoName);
}
#endif

View File

@@ -0,0 +1,183 @@
// ScripterCallback.cpp :
//
// A loadable module that connects a windows named pipe
// to a registered service function that is able to
// process a single command at a time.
//
// The service function is provided by the application
// and not by libscript. mod_script_pipe was developed for
// Audacity. Because it forwards commands
// rather than handling them itself it can be used in
// other projects too.
#include <wx/wx.h>
#include "ScripterCallback.h"
//#include "../lib_widget_extra/ShuttleGuiBase.h"
#include "../../src/ShuttleGui.h"
#ifdef NOT_DEFINED
// This is 'traditional code' for DLLs, which we're not
// using.
//#include "stdafx.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif
extern void PipeServer();
extern "C" {
typedef SCRIPT_PIPE_DLL_IMPORT int (*tpExecScriptServerFunc)( wxString * pIn, wxString * pOut);
static tpExecScriptServerFunc pScriptServerFn=NULL;
wxString Str2;
wxArrayString aStr;
unsigned int currentLine;
size_t currentPosition;
// Send the received command to Audacity and build an array of response lines.
// The response lines can be retrieved by calling DoSrvMore repeatedly.
int DoSrv(char *pIn)
{
wxString Str1(pIn, wxConvISO8859_1);
Str1.Replace( wxT("\r"), wxT(""));
Str1.Replace( wxT("\n"), wxT(""));
Str2 = wxEmptyString;
(*pScriptServerFn)( &Str1 , &Str2);
Str2 += wxT('\n');
size_t outputLength = Str2.Length();
aStr.Clear();
size_t iStart = 0;
size_t i;
for(i = 0; i < outputLength; ++i)
{
if( Str2[i] == wxT('\n') )
{
aStr.Add( Str2.Mid( iStart, i-iStart) + wxT("\n") );
iStart = i+1;
}
}
currentLine = 0;
currentPosition = 0;
return 1;
}
size_t smin(size_t a, size_t b) { return a < b ? a : b; }
// Write up to nMax characters of the prepared (by DoSrv) response lines.
// Returns the number of characters sent, including null.
// Zero returned if and only if there's nothing else to send.
int DoSrvMore(char *pOut, size_t nMax)
{
wxASSERT(currentLine >= 0);
wxASSERT(currentPosition >= 0);
size_t totalLines = aStr.GetCount();
while (currentLine < totalLines)
{
wxString lineString = aStr[currentLine];
size_t lineLength = lineString.Length();
size_t charsLeftInLine = lineLength - currentPosition;
wxASSERT(charsLeftInLine >= 0);
if (charsLeftInLine == 0)
{
// Move to next line
++currentLine;
currentPosition = 0;
}
else
{
// Write as much of the rest of the line as will fit in the buffer
size_t charsToWrite = smin(charsLeftInLine, nMax - 1);
memcpy(pOut,
lineString.Mid(currentPosition,
currentPosition + charsToWrite).mb_str(),
charsToWrite);
pOut[charsToWrite] = '\0';
currentPosition += charsToWrite;
// Need to cast to prevent compiler warnings
int charsWritten = static_cast<int>(charsToWrite + 1);
// (Check cast was safe)
wxASSERT(static_cast<size_t>(charsWritten) == charsToWrite + 1);
return charsWritten;
}
}
return 0;
}
int SCRIPT_PIPE_DLL_API RegScriptServerFunc( tpExecScriptServerFunc pFn )
{
if( pFn )
{
pScriptServerFn = pFn;
PipeServer();
}
return 4;
}
// This is an example of an exported function.
int SCRIPT_PIPE_DLL_API ExtensionModuleInit(int ix)
{
// pExecFunc = NULL;
ix;// compiler food.
#if defined(_DEBUG)
wxLogDebug(wxT("Got into DLL"));
#endif
// Here is proof that the DLL was dynamically loaded and this Init function
// called.
//wxDialog Dlg( (wxWindow*)NULL, (wxWindowID)-1, wxT("mod-script-pipe - Dialog Loaded by Plug In"), wxPoint(0,0));
#if 0
ShuttleGui S( &Dlg, eIsCreating );
S.StartStatic( "Scripter Initialising" );
S.StartHorizontalLay();
S.Id(wxID_CANCEL).AddButton( "Cancel" );
S.Id(wxID_OK).AddButton( "OK" )->SetFocus();
S.EndHorizontalLay();
S.EndStatic();
#endif
/*
Dlg.Fit();
Dlg.Move( 100,100 );
int id = Dlg.ShowModal();
*/
//printf("id = %d\n", id);
// return -1 for cancel, anything else for OK.
// return (id==wxID_CANCEL)?-1:42;
return 0;
}
wxString SCRIPT_PIPE_DLL_API GetVersionString()
{
return SCRIPT_PIPE_VERSION_STRING;
}
} // End extern "C"

View File

@@ -0,0 +1,54 @@
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the LIBSCRIPT_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// SCRIPT_PIPE_DLL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
/* Magic for dynamic library import and export. This is unfortunately
* compiler-specific because there isn't a standard way to do it. Currently it
* works with the Visual Studio compiler for windows, and for GCC 4+. Anything
* else gets all symbols made public, which gets messy */
/* The Visual Studio implementation */
#ifdef _MSC_VER
#define SCRIPT_PIPE_DLL_IMPORT _declspec(dllimport)
#ifdef BUILDING_SCRIPT_PIPE
#define SCRIPT_PIPE_DLL_API _declspec(dllexport)
#elif _DLL
#define SCRIPT_PIPE_DLL_API _declspec(dllimport)
#else
#define AUDACITY_DLL_API
#endif
#endif //_MSC_VER
/* The GCC implementation */
#ifdef CC_HASVISIBILITY // this is provided by the configure script, is only
// enabled for suitable GCC versions
/* The incantation is a bit weird here because it uses ELF symbol stuff. If we
* make a symbol "default" it makes it visible (for import or export). Making it
* "hidden" means it is invisible outside the shared object. */
#define SCRIPT_PIPE_DLL_IMPORT __attribute__((visibility("default")))
#ifdef BUILDING_SCRIPT_PIPE
#define SCRIPT_PIPE_DLL_API __attribute__((visibility("default")))
#else
#define SCRIPT_PIPE_DLL_API __attribute__((visibility("default")))
#endif
#endif
// This should be set to the version of Audacity that this version of
// mod-scipt-pipe is designed to work with. For now, the versions must match
// exactly for Audacity to agree to load the module.
#define SCRIPT_PIPE_VERSION 1
#define SCRIPT_PIPE_RELEASE 3
#define SCRIPT_PIPE_REVISION 10
#define SCRIPT_PIPE_SUFFIX wxT("-alpha-") __TDATE__
#define SCRIPT_PIPE_MAKESTR( x ) #x
#define SCRIPT_PIPE_QUOTE( x ) SCRIPT_PIPE_MAKESTR( x )
#define SCRIPT_PIPE_VERSION_STRING wxT( SCRIPT_PIPE_QUOTE( SCRIPT_PIPE_VERSION ) ) wxT(".") \
wxT( SCRIPT_PIPE_QUOTE( SCRIPT_PIPE_RELEASE ) ) wxT(".") \
wxT( SCRIPT_PIPE_QUOTE( SCRIPT_PIPE_REVISION ) ) \
SCRIPT_PIPE_SUFFIX

View File

@@ -0,0 +1,186 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="mod-script-pipe"
ProjectGUID="{85774A29-EA2F-4A40-994F-6BE593D847A5}"
RootNamespace="mod-script-pipe"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug wx284|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(WXWIN)\lib\vc_dll\mswd&quot;;&quot;$(WXWIN)\include&quot;"
PreprocessorDefinitions="BUILDING_SCRIPT_PIPE;WXUSINGDLL;WIN32;_DEBUG;_WINDOWS;_USRDLL"
RuntimeLibrary="3"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="wxmsw28d_core.lib wxbase28d.lib odbc32.lib odbccp32.lib oldnames.lib comctl32.lib rpcrt4.lib wsock32.lib netapi32.lib"
OutputFile="$(OutDir)\modules\$(ProjectName).dll"
AdditionalLibraryDirectories="&quot;$(WXWIN)\lib\vc_dll&quot;"
GenerateDebugInformation="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Modular_Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(WXWIN)\lib\vc_dll\mswd&quot;;&quot;$(WXWIN)\include&quot;"
PreprocessorDefinitions="BUILDING_SCRIPT_PIPE;WXUSINGDLL;WIN32;_DEBUG;_WINDOWS;_USRDLL"
RuntimeLibrary="2"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="wxmsw28d_core.lib wxbase28d.lib odbc32.lib odbccp32.lib oldnames.lib comctl32.lib rpcrt4.lib wsock32.lib netapi32.lib"
OutputFile="$(OutDir)\modules\$(ProjectName).dll"
AdditionalLibraryDirectories="&quot;$(WXWIN)\lib\vc_dll&quot;"
GenerateDebugInformation="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;h;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\PipeServer.cpp"
>
</File>
<File
RelativePath=".\ScripterCallback.cpp"
>
</File>
<File
RelativePath=".\ScripterCallback.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>