📄 wxsystem.cc
字号:
/*..........................................................................*//* *//* L a s t W a v e K e r n e l 3 . 0 *//* *//* Copyright (C) 1998-2002 Emmanuel Bacry. *//* email : lastwave@cmap.polytechnique.fr *//* *//*..........................................................................*//* *//* This program is a free software, you can redistribute it and/or *//* modify it under the terms of the GNU General Public License as *//* published by the Free Software Foundation; either version 2 of the *//* License, or (at your option) any later version *//* *//* This program is distributed in the hope that it will be useful, *//* but WITHOUT ANY WARRANTY; without even the implied warranty of *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *//* GNU General Public License for more details. *//* *//* You should have received a copy of the GNU General Public License *//* along with this program (in a file named COPYRIGHT); *//* if not, write to the Free Software Foundation, Inc., *//* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* *//*..........................................................................*//********************************************************************//* *//* mac_system.c : *//* *//********************************************************************/// For compilers that support precompilation, includes "wx/wx.h".#include "wx/wxprec.h"// for all others, include the necessary headers (this file is usually all you// need because it includes almost all "standard" wxWidgets headers)#ifndef WX_PRECOMP#include "wx/wx.h"#endifextern "C" {#include "lastwave.h"#include "xx_system.h"#include "xx_audio.h"#include "signals.h"}#include "wx/textctrl.h"#include "terminalCtrl.h"#include "wxmain.h"#include "wxgraphics.h"#include "wx/dir.h"#include "wx/filefn.h"#include "wx/filename.h"// Get temporary filenamechar * XXGetTmpFilename(){ static char res[500]; wxString str = wxFileName::CreateTempFileName(_T("")); if (str.Len()<490) { strcpy(res,WXSTRING2ANSI(str)); } else { strncpy(res,WXSTRING2ANSI(str),490); res[490] = '\0'; } return(res);}/* * Get the number of seconds since 1 January 1970 00h00 */void XXGetTime(long *sec, long *microsec){ wxLongLong t = wxGetLocalTimeMillis(); *sec = (t/1000).ToLong(); *microsec = ((t%1000).ToLong())*1000;}char *XXGetHistoryFile(){ static char file[1000] = ""; if (file[0] == '\0') { sprintf(file,"%s/history",_LWUserDataDir_); } return(file);}static char *Convert(char *file){ wxFileName fn(ANSI2WXSTRING(file), wxPATH_UNIX); // IsOK wxString s = fn.GetFullPath(); static char res[2000]; if (s.Len()<1990) { strcpy(res,WXSTRING2ANSI(s)); } else { strncpy(res,WXSTRING2ANSI(s),1990); res[1990] = '\0'; } return(res);}char *XXConvertFilename(char *file){ return(Convert(file));}void XXStartup(int *a, char ***b){}char _LWHome_[1000];char _LWUser_[1000];char _LWUserDataDir_[1000];char *_LWSystem_;char *_LWComputer_;char *_LWTerm_;char _LWScriptDir_[1000];#include <wx/stdpaths.h>#include <wx/log.h>void XXSetSystemInfo(){ strcpy(_LWUser_,WXSTRING2ANSI(wxGetUserName())); strcpy(_LWHome_,WXSTRING2ANSI(wxGetHomeDir())); // This is the user directory where to put the config files : history and scriptDir // We create it if necessary. wxString str = SOFTVERSION; wxString str1 = wxStandardPaths::Get().GetUserDataDir()+"."+str; strcpy(_LWUserDataDir_,WXSTRING2ANSI(str1)); if (!wxFileName::DirExists(str1)) ::wxMkdir(str1);/* strcpy(_LWUserDataDir_,WXSTRING2ANSI(wxStandardPaths::Get().GetUserDataDir())); if (!wxFileName::DirExists(wxStandardPaths::Get().GetUserDataDir())) ::wxMkdir(wxStandardPaths::Get().GetUserDataDir()); */ // Now we look for the scriptDir file in this director char dir[1000]; sprintf(dir,"%s/%s",_LWUserDataDir_,"scriptDir"); // If this file does not exist, we create a dummy one if (!wxFileName::FileExists(ANSI2WXSTRING(dir))) { FILE *f = FOpen(dir,"w"); FClose(f); } // Now as long as we cannot read an existing directory name in this file we ask to pick up a directory while (1) { _LWScriptDir_[0] = '\0'; FILE *f = FOpen(dir,"r"); fscanf(f,"%[^\n\r] ",_LWScriptDir_); FClose(f); if (wxFileName::DirExists(ANSI2WXSTRING(_LWScriptDir_))) { char startup[1200]; strcpy(startup,_LWScriptDir_); strcat(startup,"/startup"); if (wxFileName::FileExists(ANSI2WXSTRING(startup))) break; } char * ans = XXChooseFileDialog("Please select a script directory in which there is a startup file",1); if (ans[0] != '\0') { FILE *f = FOpen(dir,"w"); fprintf(f,"%s",ans); FClose(f); } } _LWTerm_ = ""; int os = wxGetOsVersion(); switch(os) { __CASEMAC : _LWSystem_ = "mac"; _LWComputer_ = "mac"; break; __CASEUNIX : _LWSystem_ = "gtk"; _LWComputer_ = "pc"; break; __CASEWINDOWS : _LWSystem_ = "windows"; _LWComputer_ = "pc"; break; default : _LWSystem_ = "other"; _LWComputer_ = "other"; }}/* Create a directory */char XXCreateDirectory(char *directory,char *name){ char str[1000]; sprintf(str,"%s/%s",directory,name); wxString s = ANSI2WXSTRING(str); if (::wxMkdir(s)) return(1); else return(0);}/* Remove a file */char XXRemoveFile(char *name){ wxString s=ANSI2WXSTRING(name); if (::wxRemoveFile(s)) return(1); else return(0);}/* Rename a file */char XXRenameFile(char *name1, char *name2){ wxString s1=ANSI2WXSTRING(name1); wxString s2=ANSI2WXSTRING(name2); if (::wxRenameFile(s1,s2)) return(1); else return(0);}/* * Get the filenames of the current directory */char *XXGetFilenames(char *dirName){ static wxDir dir; static bool flagFirst; static wxString filename; static char res[2000]; if (dirName != NULL) { dir.Open(ANSI2WXSTRING(dirName)); flagFirst = true; return(dirName); } if (dir.IsOpened() == false) return(NULL); if (flagFirst) { if (!(dir.GetFirst(&filename))) return(NULL); flagFirst = false; } else if (!(dir.GetNext(&filename))) return(NULL); if (filename.Len()<1990) { strcpy(res,WXSTRING2ANSI(filename)); } else { strncpy(res,WXSTRING2ANSI(filename),1990); res[1990] = '\0'; } return(res);}/* * Get a filename info */void XXGetFilenameInfo(char *filename,int *type,int *size){ wxString s(ANSI2WXSTRING(filename)); if (wxFileName::DirExists(s)) { *type = DirectoryFile; *size = 0; } else if (wxFileName::FileExists(s)) { *type = RegularFile; *size = 0; } else { *type = UnknownTypeFile; *size = 0; }}/* * Change current directory */char *XXChangeDirectory(char *directory){ if (directory) { ::wxSetWorkingDirectory(ANSI2WXSTRING(directory)); return(directory); } else { static char res[500]; if (::wxGetCwd().Len()<490) { strcpy(res,WXSTRING2ANSI(::wxGetCwd())); } else { strncpy(res,WXSTRING2ANSI(::wxGetCwd()),490); res[490] = '\0'; } return(res); }} class MyTimer : public wxTimer{public : MyTimer(); ~MyTimer(); struct event event; void Notify();};MyTimer::MyTimer() : wxTimer(){ event.type = DelayEvent | TimeEvent; event.object = NULL;}MyTimer::~MyTimer() {}void MyTimer::Notify(){ ProcessNextEvent(&event);}void *XXCreateTimer(){ MyTimer *t = new MyTimer(); t->event.timer = t; return(t);}void XXStartTimer(void *t, int ms, int flagOneShot){ if (ms < 0 && !flagOneShot) return; if (ms < 0 && flagOneShot) ms = 0; MyTimer *timer = (MyTimer *) t; if (flagOneShot) timer->Start(ms,wxTIMER_ONE_SHOT); else timer->Start(ms,wxTIMER_CONTINUOUS); }void XXStop(void *t){ MyTimer *timer = (MyTimer *) t; timer->Stop();}void XXDeleteTimer(void *t){ MyTimer *timer = (MyTimer *) t; delete timer;} void XXSoundRecord(LWFLOAT **samplesLeft,LWFLOAT **samplesRight, unsigned long *nbSamples,LWFLOAT *sampleFreq, unsigned char soundQuality, unsigned long customSampleFreq,unsigned char customBitsPerSample, unsigned long maxNbSamples){}// Play a sound on the default output device, at the given sampling frequency.// The sound may be mono, in which case sampleRight must be NULL.//// This is the MacOSX version --> files are in MacSound//#ifdef _LWMACOSX_extern "C" {#include "soundlw.h"extern char Name2SoundFormat(char *str, SoundFormat *sf);};extern void PlaySoundFile (char *fileName);void XXSoundPlay(short *samplesLeft,short *samplesRight,unsigned long nSamples,LWFLOAT sampleFreq){ char *name = XXGetTmpFilename(); char str[1000]; strcpy(str,name); strcat(str,".wav"); SIGNAL sig1 = TNewSignal(); SizeSignal(sig1,nSamples,YSIG); sig1->dx = 1/sampleFreq; for(int i = 0; i<nSamples;i++) sig1->Y[i] = samplesLeft[i]; SoundFormat sf; Name2SoundFormat("wave16", &sf); SoundWrite(str,sig1, NULL,YES,1.0, &sf); PlaySoundFile(str);}#else#include <wx/sound.h>extern "C" {#include "soundlw.h"extern char Name2SoundFormat(char *str, SoundFormat *sf);};extern void PlaySoundFile (char *fileName);void XXSoundPlay(short *samplesLeft,short *samplesRight,unsigned long nSamples,LWFLOAT sampleFreq){ #ifdef _LWWINDOWS_ char *name = XXGetTmpFilename(); char str[1000]; strcpy(str,name); strcat(str,".wav"); SIGNAL sig1 = TNewSignal(); SizeSignal(sig1,nSamples,YSIG); sig1->dx = 1/sampleFreq; for(int i = 0; i<nSamples;i++) sig1->Y[i] = samplesLeft[i]; SoundFormat sf; Name2SoundFormat("wave16", &sf); SoundWrite(str,sig1, NULL,YES,1.0, &sf); wxSound::Play(str);#endif}#endif// Stop the currently playing sound : Not implemented yetvoid XXSoundStopPlaying(void){}#include <wx/filedlg.h>#include <wx/filename.h>char *XXChooseFileDialog(char *str, char flagDir){ wxString answer; wxString msge =ANSI2WXSTRING(str); wxString default_path = _T(""); wxString default_filename = _T("startup"); wxString default_extension = _T(""); wxString wildcard = _T("*.*"); int flags = wxFILE_MUST_EXIST | wxOPEN; wxWindow *parent = NULL; int x = -1; int y = -1; if (!flagDir) { answer = wxFileSelector(msge, default_path,default_filename,default_extension,wildcard,flags,parent,x,y); } else { answer = wxDirSelector(msge); }// wxFileName fn(answer);// answer = fn.GetFullPath(wxPATH_UNIX); static char res[500]; if (answer.Len()<490) { strcpy(res,WXSTRING2ANSI(answer)); } else { strncpy(res,WXSTRING2ANSI(answer),490); res[490] = '\0'; } return(res);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -