Changeset 1295

Show
Ignore:
Timestamp:
10/30/07 01:16:02 (10 months ago)
Author:
calvin
Message:

zoners patch with modifications: export wave, open in external editor and re-import.
also allow setting max_tracks on a machine instead of max_tracks-1

Location:
trunk/src/buzelib
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/buzelib/BuzeConfiguration.cpp

    r1290 r1295  
    186186} 
    187187 
     188std::string CConfiguration::getExternalWaveEditor() { 
     189        string cmd; 
     190        if (!getConfigString("Settings", "ExternalWaveEditor", &cmd)) 
     191                return ""; 
     192        return cmd; 
     193} 
     194 
     195void CConfiguration::setExternalWaveEditor(std::string cmd) { 
     196        setConfigString("Settings", "ExternalWaveEditor", cmd); 
     197} 
     198 
    188199void CConfiguration::setMachineParameterVisibility(std::string uri, int parameterIndex, bool state) { 
    189200        setConfigNumber("Machines\\" + (string)uri + "\\ExtMachineInfo\\Parameter" + stringFromInt(parameterIndex), "Hidden", state?1:0); 
  • trunk/src/buzelib/BuzeConfiguration.h

    r1290 r1295  
    5151        void setMachineSkinVisibility(std::string uri, bool state); 
    5252        bool getMachineSkinVisibility(std::string uri); 
     53 
     54        void setExternalWaveEditor(std::string cmd); 
     55        std::string getExternalWaveEditor(); 
     56 
    5357}; 
  • trunk/src/buzelib/EditorActions.cpp

    r1273 r1295  
    747747        int numTracks=this->tracks; 
    748748         
    749         if (numTracks<machine->loader->plugin_info->max_tracks) { 
     749        if (numTracks<=machine->loader->plugin_info->max_tracks) { 
    750750                int prevTracks = machine->getTracks(); 
    751751                machine->setTracks(numTracks); 
  • trunk/src/buzelib/MainFrm.cpp

    r1290 r1295  
    3535#include <sys/stat.h> 
    3636#include <fstream> 
     37#include <win32/sndfile.h> 
    3738#include "DockTabFrame/DockTabSerializer.h" 
    3839 
     
    861862} 
    862863 
     864LRESULT CMainFrame::OnWaveXEdit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { 
     865        assert(document->selectedWave); 
     866 
     867        int wavetableIndex = document->getWaveIndex(document->selectedWave); 
     868 
     869        // Get global settings 
     870 
     871        std::string waveEditor = _Module.configuration->getExternalWaveEditor(); 
     872 
     873        if (!waveEditor.length()) { 
     874                MessageBox("No wave editor specified", "Error"); 
     875                return 0; 
     876        } 
     877 
     878        char tmpPath[MAX_PATH]; 
     879        GetTempPath(MAX_PATH, tmpPath); 
     880 
     881        std::string tempFile = tmpPath + stringFromInt(wavetableIndex) + ".wav"; 
     882 
     883        PROCESS_INFORMATION pi; 
     884        STARTUPINFO si; 
     885 
     886        memset(&si,0,sizeof(si)); 
     887        si.cb= sizeof(si); 
     888 
     889        // Export document->selectedWave as tmpFileName 
     890 
     891        if(!exportWaveEntry(document->selectedWave, const_cast<char*>(tempFile.c_str()))) { 
     892                MessageBox("Unable to create temporary file", tempFile.c_str()); 
     893                return 0; 
     894        } 
     895 
     896        // Create a process for the wave editor, editing the temporary file 
     897 
     898        std::string command = "\"" + waveEditor + "\" " + tempFile; 
     899        char commandStr[1024]; 
     900        strncpy(commandStr, command.c_str(), 1024); 
     901        if(!CreateProcess(NULL, commandStr, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) { 
     902                MessageBox("Unable to spawn the external wave editor.", command.c_str()); 
     903        } 
     904 
     905        return 0; 
     906} 
     907 
     908LRESULT CMainFrame::OnWaveIEdit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { 
     909        assert(document->selectedWave); 
     910 
     911        int wavetableIndex = document->getWaveIndex(document->selectedWave); 
     912 
     913        // Get global settings 
     914 
     915        char tmpPath[MAX_PATH]; 
     916        GetTempPath(MAX_PATH, tmpPath); 
     917 
     918        std::string tempFile = tmpPath + stringFromInt(wavetableIndex) + ".wav"; 
     919 
     920        // Re-Import tmpFileName into document->selectedWave 
     921 
     922        std::string originalFileName = document->selectedWave->fileName; 
     923        std::string originalName = document->selectedWave->name; 
     924        CBrowserIterator* browser; 
     925 
     926        browser = CArchiveBrowserBase::createBrowser(tempFile); 
     927        if (!browser) { 
     928                MessageBox("Unable to import the temporary wave file", tempFile.c_str()); 
     929                return 0; 
     930        } 
     931 
     932        importWaveEntry(browser, document->selectedWave); 
     933        browser->close(); 
     934        delete browser; 
     935 
     936        document->selectedWave->fileName = originalFileName; 
     937        document->selectedWave->name = originalName; 
     938 
     939        // This UI refresh is required as the names were reinstated 
     940        document->updateAllViews(0, UpdateImportWave, document->selectedWave); 
     941 
     942        if(remove(tempFile.c_str())) 
     943        { 
     944                MessageBox("Unable to delete the temporary wave file", tempFile.c_str()); 
     945        } 
     946 
     947         
     948        return 0; 
     949} 
     950 
    863951LRESULT CMainFrame::OnWaveLevelProperties(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { 
    864952        showPropertyView(); 
     
    22262314} 
    22272315 
     2316bool CMainFrame::exportWaveEntry(zzub::wave_info_ex* entry, char *path) { 
     2317        zzub_wave_t* wave = (zzub_wave_t*)entry; 
     2318        int result = -1; 
     2319        int level = 0; 
     2320        SF_INFO sfinfo; 
     2321 
     2322        memset(&sfinfo, 0, sizeof(sfinfo)); 
     2323        sfinfo.samplerate = wave->get_samples_per_sec(level); 
     2324        sfinfo.channels = wave->get_stereo()?2:1; 
     2325        sfinfo.format = SF_FORMAT_WAV; 
     2326        if (wave->get_bits_per_sample(level) == 16) 
     2327                sfinfo.format |= SF_FORMAT_PCM_16; 
     2328        else if (wave->get_bits_per_sample(level) == 8) 
     2329                sfinfo.format |= SF_FORMAT_PCM_S8; 
     2330        else if (wave->get_bits_per_sample(level) == 24) 
     2331                sfinfo.format |= SF_FORMAT_PCM_24; 
     2332        else if (wave->get_bits_per_sample(level) == 32) 
     2333                sfinfo.format |= SF_FORMAT_PCM_32; 
     2334        else 
     2335                return 0; 
     2336        SNDFILE *sf = sf_open(path, SFM_WRITE, &sfinfo); 
     2337        if (!sf) 
     2338                return 0; 
     2339        zzub::wave_level* wavelevel = wave->get_level(level); 
     2340        sf_writef_short(sf, (const short*)wave->get_sample_ptr(level), wave->get_sample_count(level)); 
     2341        sf_close(sf); // so close it 
     2342        return 1; 
     2343 
     2344} 
    22282345 
    22292346bool CMainFrame::importWaveEntry(CBrowserIterator* it, wave_info_ex* entry) { 
  • trunk/src/buzelib/MainFrm.h

    r1281 r1295  
    320320                COMMAND_ID_HANDLER(ID_MACHINE_PROPERTIES, OnMachineProperties) 
    321321                COMMAND_ID_HANDLER(ID_WAVE_PROPERTIES, OnWaveProperties) 
     322                COMMAND_ID_HANDLER(ID_WAVE_XEDIT, OnWaveXEdit) 
     323                COMMAND_ID_HANDLER(ID_WAVE_IEDIT, OnWaveIEdit) 
    322324                COMMAND_ID_HANDLER(ID_WAVELEVEL_PROPERTIES, OnWaveLevelProperties) 
    323325                COMMAND_ID_HANDLER(ID_WAVELEVEL_ADD, OnWaveLevelAdd) 
     
    400402        LRESULT OnMachineProperties(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
    401403        LRESULT OnWaveProperties(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
     404        LRESULT OnWaveXEdit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
     405        LRESULT OnWaveIEdit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
    402406        LRESULT OnWaveLevelProperties(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
    403407        LRESULT OnWaveLevelAdd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
     
    560564        // wave table editing 
    561565        bool importWaveEntry(CBrowserIterator* , zzub::wave_info_ex* entry); 
     566        bool exportWaveEntry(zzub::wave_info_ex* entry, char *path); 
    562567 
    563568        void mixdownSong(zzub::metaplugin* plugin, zzub::metaplugin* rec); 
  • trunk/src/buzelib/WaveTableList.cpp

    r1293 r1295  
    123123        view->mainFrame->document->selectWave(wave); 
    124124        menu.InsertMenu(-1, MF_BYPOSITION|MF_STRING, (UINT_PTR)ID_WAVE_PROPERTIES, "Properties"); 
     125        menu.InsertMenu(-1, MF_BYPOSITION|MF_STRING, (UINT_PTR)ID_WAVE_XEDIT, "Export And Open With External Editor"); 
     126        menu.InsertMenu(-1, MF_BYPOSITION|MF_STRING, (UINT_PTR)ID_WAVE_IEDIT, "Re-Import"); 
    125127 
    126128        ClientToScreen(&pt); 
  • trunk/src/buzelib/resource.h

    r1289 r1295  
    398398#define ID_EDIT_STEP_8                 53432 
    399399#define ID_EDIT_STEP_9                 53433 
     400#define ID_WAVE_XEDIT                                   53434 
     401#define ID_WAVE_IEDIT                                   53435 
    400402 
    401403// Next default values for new objects