www.pudn.com > Wave_Src_func.zip > Form1.h


#pragma once 
#include "WaveFileHandler.h" 
#include  
namespace WaveFun 
{ 
	using namespace System; 
	using namespace System::ComponentModel; 
	using namespace System::Collections; 
	using namespace System::Windows::Forms; 
	using namespace System::Data; 
	using namespace System::Drawing; 
 
	///   
	/// Summary for Form1 
	/// 
	/// WARNING: If you change the name of this class, you will need to change the  
	///          'Resource File Name' property for the managed resource compiler tool  
	///          associated with all .resx files this class depends on.  Otherwise, 
	///          the designers will not be able to interact properly with localized 
	///          resources associated with this form. 
	///  
	public __gc class Form1 : public System::Windows::Forms::Form 
	{	 
	public: 
		Form1(void) 
		{ 
			InitializeComponent(); 
		} 
   
	protected: 
		void Dispose(Boolean disposing) 
		{ 
			if (disposing && components) 
			{ 
				components->Dispose(); 
			} 
			__super::Dispose(disposing); 
		} 
	private: System::Windows::Forms::Label *  label1; 
	private: System::Windows::Forms::Label *  label2; 
	private: System::Windows::Forms::OpenFileDialog *  openFileDialog1; 
 
 
	private: System::Windows::Forms::TextBox *  SrcFile; 
	private: System::Windows::Forms::TextBox *  TargetFile; 
	private: System::Windows::Forms::SaveFileDialog *  saveFileDialog1; 
	private: System::Windows::Forms::Button *  TargetBtn; 
	private: System::Windows::Forms::Button *  srcFileBtn; 
	private: System::Windows::Forms::Button *  Reverse; 
 
	private: 
		///  
		/// Required designer variable. 
		///  
		System::ComponentModel::Container * components; 
 
		///  
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor. 
		///  
		void InitializeComponent(void) 
		{ 
			this->label1 = new System::Windows::Forms::Label(); 
			this->label2 = new System::Windows::Forms::Label(); 
			this->openFileDialog1 = new System::Windows::Forms::OpenFileDialog(); 
			this->TargetBtn = new System::Windows::Forms::Button(); 
			this->srcFileBtn = new System::Windows::Forms::Button(); 
			this->SrcFile = new System::Windows::Forms::TextBox(); 
			this->TargetFile = new System::Windows::Forms::TextBox(); 
			this->saveFileDialog1 = new System::Windows::Forms::SaveFileDialog(); 
			this->Reverse = new System::Windows::Forms::Button(); 
			this->SuspendLayout(); 
			//  
			// label1 
			//  
			this->label1->Location = System::Drawing::Point(8, 32); 
			this->label1->Name = S"label1"; 
			this->label1->Size = System::Drawing::Size(100, 16); 
			this->label1->TabIndex = 0; 
			this->label1->Text = S"Source File (.wav)"; 
			//  
			// label2 
			//  
			this->label2->Location = System::Drawing::Point(8, 96); 
			this->label2->Name = S"label2"; 
			this->label2->Size = System::Drawing::Size(100, 16); 
			this->label2->TabIndex = 0; 
			this->label2->Text = S"Target File (.wav)"; 
			//  
			// TargetBtn 
			//  
			this->TargetBtn->Location = System::Drawing::Point(120, 96); 
			this->TargetBtn->Name = S"TargetBtn"; 
			this->TargetBtn->Size = System::Drawing::Size(24, 16); 
			this->TargetBtn->TabIndex = 1; 
			this->TargetBtn->Text = S"..."; 
			this->TargetBtn->Click += new System::EventHandler(this, TargetBtn_Click); 
			//  
			// srcFileBtn 
			//  
			this->srcFileBtn->Location = System::Drawing::Point(120, 32); 
			this->srcFileBtn->Name = S"srcFileBtn"; 
			this->srcFileBtn->Size = System::Drawing::Size(24, 16); 
			this->srcFileBtn->TabIndex = 1; 
			this->srcFileBtn->Text = S"..."; 
			this->srcFileBtn->Click += new System::EventHandler(this, SrcFileBtn_Click); 
			//  
			// SrcFile 
			//  
			this->SrcFile->Location = System::Drawing::Point(16, 56); 
			this->SrcFile->Name = S"SrcFile"; 
			this->SrcFile->Size = System::Drawing::Size(264, 20); 
			this->SrcFile->TabIndex = 2; 
			this->SrcFile->Text = S""; 
			//  
			// TargetFile 
			//  
			this->TargetFile->Location = System::Drawing::Point(16, 120); 
			this->TargetFile->Name = S"TargetFile"; 
			this->TargetFile->Size = System::Drawing::Size(264, 20); 
			this->TargetFile->TabIndex = 2; 
			this->TargetFile->Text = S""; 
			//  
			// saveFileDialog1 
			//  
			this->saveFileDialog1->FileOk += new System::ComponentModel::CancelEventHandler(this, saveFileDialog1_FileOk); 
			//  
			// Reverse 
			//  
			this->Reverse->Location = System::Drawing::Point(24, 160); 
			this->Reverse->Name = S"Reverse"; 
			this->Reverse->Size = System::Drawing::Size(64, 32); 
			this->Reverse->TabIndex = 3; 
			this->Reverse->Text = S"ReverseWav"; 
			this->Reverse->Click += new System::EventHandler(this, Reverse_Click); 
			//  
			// Form1 
			//  
			this->AutoScaleBaseSize = System::Drawing::Size(5, 13); 
			this->ClientSize = System::Drawing::Size(292, 266); 
			this->Controls->Add(this->Reverse); 
			this->Controls->Add(this->SrcFile); 
			this->Controls->Add(this->TargetBtn); 
			this->Controls->Add(this->label1); 
			this->Controls->Add(this->label2); 
			this->Controls->Add(this->srcFileBtn); 
			this->Controls->Add(this->TargetFile); 
			this->Name = S"Form1"; 
			this->Text = S"Wave Reverser"; 
			this->ResumeLayout(false); 
 
		}	 
	private: System::Void SrcFileBtn_Click(System::Object *  sender, System::EventArgs *  e) 
			 { 
				openFileDialog1->Filter = S"wave files (*.wav)|*.wav" ; 
				if(openFileDialog1->ShowDialog() == DialogResult::OK) 
				{ 
					SrcFile->set_Text(openFileDialog1->get_FileName()); 
				} 
			 } 
 
private: System::Void saveFileDialog1_FileOk(System::Object *  sender, System::ComponentModel::CancelEventArgs *  e) 
		 { 
		 } 
 
private: System::Void TargetBtn_Click(System::Object *  sender, System::EventArgs *  e) 
		 { 
			saveFileDialog1->Filter = S"wave files (*.wav)|*.wav" ; 
			if(saveFileDialog1->ShowDialog() == DialogResult::OK) 
			{ 
				TargetFile->set_Text(saveFileDialog1->get_FileName()); 
			} 
		 } 
 
private: System::Void Reverse_Click(System::Object *  sender, System::EventArgs *  e) 
		 { 
				Reverse->set_Enabled(false); 
				CWaveFileHandler wfh; 
 
				using namespace System::Runtime::InteropServices; 
				char* strFileName = (char*)(void*)Marshal::StringToHGlobalAnsi(SrcFile->get_Text()); 
				wfh.OpenForRead(strFileName); 
				Marshal::FreeHGlobal(strFileName); 
 
				strFileName = (char*)(void*)Marshal::StringToHGlobalAnsi(TargetFile->get_Text()); 
				wfh.OpenForWrite(strFileName,true); 
				Marshal::FreeHGlobal(strFileName); 
 
				// ok, we have source file and destination file. let us start the fun 
				DWORD dwRiffSize = 0,dwFmtsize=0,dwDatasize=0; 
				BYTE * pRiff = wfh.GetRiff(dwRiffSize); 
				wfh.PutRiff(pRiff,dwRiffSize); 
				BYTE * pFmt = wfh.GetFmt(dwFmtsize); 
				wfh.PutFmt(pFmt,dwFmtsize); 
				BYTE * pData = wfh.GetData(dwDatasize); 
				 
				// pData now has the wave data of the source file 
				// we need to go to the end and copy in reverse order 
				// to dest file one sample frame at a time 
 
				int nSampFramesize =  
					((FMT_BLOCK*)pFmt)->wavFormat.wChannels * ((FMT_BLOCK*)pFmt)->wavFormat.wBitsPerSample; 
 
				nSampFramesize /= 8; // how many bytes 
 
				BYTE *pRevdata = pData + dwDatasize; // go to end of source 
				pRevdata -= nSampFramesize; 
				wfh.PutData(pRevdata,nSampFramesize); 
 
				while(pRevdata > pData) 
				{ 
					pRevdata -= nSampFramesize; 
					wfh.PutRawData(pRevdata,nSampFramesize); 
 
				} // while(pRevdata < pData) 
 
				wfh.CloseAll(); 
 
				Reverse->set_Enabled(true); 
		 } 
 
}; 
}