Ejemplo n.º 1
0
    void DecodeRLE(const uint8_t* data, std::size_t size, Dump& result)
    {
      Dump tmp;
      tmp.reserve(MAX_SECTOR_SIZE);
      ByteStream stream(data, size);
      while (!stream.Eof())
      {
        const uint_t len = 2 * stream.GetByte();
        Require(!stream.Eof());
        const uint_t count = stream.GetByte();
        Require(count != 0);

        const bool isRLE = len != 0;
        const uint_t blockSize = isRLE ? len : count;
        Require(stream.GetRestBytes() >= blockSize);
        for (uint_t idx = 0; idx != blockSize; ++idx)
        {
          tmp.push_back(stream.GetByte());
        }
        if (isRLE)
        {
          Require(CopyFromBack(len, tmp, len * (count - 1)));
        }
      }
      result.swap(tmp);
    }
Ejemplo n.º 2
0
 void ApplyInsertions(Dump& result) const
 {
   if (0 == SizeAddon)
   {
     return;
   }
   Dump tmp(result.size() + SizeAddon);
   Dump::const_iterator src = result.begin();
   const Dump::const_iterator srcEnd = result.end();
   auto dst = tmp.begin();
   std::size_t oldOffset = 0;
   for (const auto& ins : Insertions)
   {
     if (const std::size_t toCopy = ins.first - oldOffset)
     {
       const Dump::const_iterator nextEnd = src + toCopy;
       dst = std::copy(src, nextEnd, dst);
       src = nextEnd;
       oldOffset += toCopy;
     }
     dst = std::copy(ins.second.begin(), ins.second.end(), dst);
   }
   std::copy(src, srcEnd, dst);
   result.swap(tmp);
 }
Ejemplo n.º 3
0
void DisplayDevice::dump(Dump& d)
{
    d.append("-------------------------------------------------------------\n");
    d.append("Device Name: %s (%s)\n", mName,
            mConnection ? "connected" : "disconnected");
    d.append("Display configs (count = %d):\n", mDisplayConfigs.size());
    d.append(" CONFIG | VSYNC_PERIOD | WIDTH | HEIGHT | DPI_X | DPI_Y \n");
    d.append("--------+--------------+-------+--------+-------+-------\n");
    for (size_t i = 0; i < mDisplayConfigs.size(); i++) {
        DisplayConfig *config = mDisplayConfigs.itemAt(i);
        if (config) {
            d.append("%s %2d   |     %4d     | %5d |  %4d  |  %3d  |  %3d  \n",
                     (i == (size_t)mActiveDisplayConfig) ? "* " : "  ",
                     i,
                     config->getRefreshRate(),
                     config->getWidth(),
                     config->getHeight(),
                     config->getDpiX(),
                     config->getDpiY());
        }
    }
    // dump layer list
    if (mLayerList)
        mLayerList->dump(d);
}
Ejemplo n.º 4
0
void dsp::SingleThread::insert_dump_point (const std::string& transform_name)
{
  typedef HasInput<TimeSeries> Xform;

  for (unsigned iop=0; iop < operations.size(); iop++)
  {
    if (operations[iop]->get_name() == transform_name)
    {
      Xform* xform = dynamic_cast<Xform*>( operations[iop].get() );
      if (!xform)
	throw Error (InvalidParam, "dsp::SingleThread::insert_dump_point",
		     transform_name + " does not have TimeSeries input");

      string filename = "pre_" + transform_name;

      if (config->get_total_nthread() > 1)
        filename += "." + tostring (thread_id);

      filename += ".dump";

      cerr << "dspsr: dump output in " << filename << endl;

      Dump* dump = new Dump;
      dump->set_output( fopen(filename.c_str(), "w") );
      dump->set_input( xform->get_input() ) ;
      dump->set_output_binary (true);

      operations.insert (operations.begin()+iop, dump);
      iop++;
    }
  }
}
Ejemplo n.º 5
0
    void GetResult(Dump& data) const override
    {
      Dump rawDump;
      Delegate->GetResult(rawDump);
      Require(0 == rawDump.size() % Registers::TOTAL);
      const uint32_t framesCount = rawDump.size() / Registers::TOTAL;
      const uint_t storedRegisters = Registers::TOTAL;

      const String& title = Params->Title();
      const String author = Params->Author();
      const uint32_t headerSize = sizeof(FYMHeader) + (title.size() + 1) + (author.size() + 1);
      const std::size_t contentSize = framesCount * storedRegisters;

      Binary::DataBuilder builder(headerSize + contentSize);
      FYMHeader& header = builder.Add<FYMHeader>();
      header.HeaderSize = fromLE(headerSize);
      header.FramesCount = fromLE(framesCount);
      header.LoopFrame = fromLE(static_cast<uint32_t>(Params->LoopFrame()));
      header.PSGFreq = fromLE(static_cast<uint32_t>(Params->ClockFreq()));
      header.IntFreq = fromLE(static_cast<uint32_t>(Time::GetFrequencyForPeriod(Params->FrameDuration())));
      builder.AddCString(title);
      builder.AddCString(author);

      for (uint_t reg = 0; reg < storedRegisters; ++reg)
      {
        uint8_t* const result = static_cast<uint8_t*>(builder.Allocate(framesCount));
        for (uint_t frm = 0, inOffset = reg; frm < framesCount; ++frm, inOffset += Registers::TOTAL)
        {
          result[frm] = rawDump[inOffset];
        }
      }
      Dump result;
      builder.CaptureResult(result);
      Binary::Compression::Zlib::Compress(result, data);
    }
Ejemplo n.º 6
0
    bool DecodeData()
    {
      const uint8_t* const rawData = static_cast<const uint8_t*>(Header.ID);
      const std::size_t dataOffset = fromLE(Header.DataOffset);
      const uint_t cylinders = fromLE(Header.Cylinders);
      const uint_t sides = fromLE(Header.Sides);

      Dump result;
      result.reserve(FDI_MAX_SIZE);
      std::size_t trackInfoOffset = sizeof(Header) + fromLE(Header.InfoSize);
      std::size_t rawSize = dataOffset;
      for (uint_t cyl = 0; cyl != cylinders; ++cyl)
      {
        for (uint_t sid = 0; sid != sides; ++sid)
        {
          if (trackInfoOffset + sizeof(RawTrack) > Limit)
          {
            return false;
          }

          const RawTrack* const trackInfo = safe_ptr_cast<const RawTrack*>(rawData + trackInfoOffset);
          typedef std::vector<SectorDescr> SectorDescrs;
          //collect sectors reference
          SectorDescrs sectors;
          sectors.reserve(trackInfo->SectorsCount);
          for (std::size_t secNum = 0; secNum != trackInfo->SectorsCount; ++secNum)
          {
            const RawTrack::Sector* const sector = trackInfo->Sectors + secNum;
            const std::size_t secSize = 128 << sector->Size;
            //since there's no information about head number (always 0), do not check it
            //assert(sector->Head == sid);
            if (sector->Cylinder != cyl)
            {
              return false;
            }
            const std::size_t offset = dataOffset + fromLE(sector->Offset) + fromLE(trackInfo->Offset);
            if (offset + secSize > Limit)
            {
              return false;
            }
            sectors.push_back(SectorDescr(sector->Number, rawData + offset, rawData + offset + secSize));
            rawSize = std::max(rawSize, offset + secSize);
          }

          //sort by number
          std::sort(sectors.begin(), sectors.end());
          //and gather data
          for (SectorDescrs::const_iterator it = sectors.begin(), lim = sectors.end(); it != lim; ++it)
          {
            result.insert(result.end(), it->Begin, it->End);
          }
          //calculate next track by offset
          trackInfoOffset += sizeof(*trackInfo) + (trackInfo->SectorsCount - 1) * sizeof(trackInfo->Sectors);
        }
      }
      UsedSize = rawSize;
      Decoded.swap(result);
      return true;
    }
Ejemplo n.º 7
0
 bool IsInfoEmpty(const Dump& info)
 {
   assert(info.size() == 53);
   //28 is fixed
   //25 is title
   const Dump::const_iterator titleStart = info.begin() + 28;
   return info.end() == std::find_if(titleStart, info.end(), std::bind2nd(std::greater<Char>(), Char(' ')));
 }
Ejemplo n.º 8
0
void WriteDump::command(int narg, char **arg)
{

    if (narg < 3) error->all(FLERR,"Illegal write_dump command");

    // modindex = index in args of "modify" keyword
    // will be narg if "modify" is not present

    int modindex;
    for (modindex = 0; modindex < narg; modindex++)
        if (strcmp(arg[modindex],"modify") == 0) break;

    // create the Dump instance
    // create dump command line with extra required args

    Dump *dump;

    char **dumpargs = new char*[modindex+2];
    dumpargs[0] = (char *) "WRITE_DUMP"; // dump id
    dumpargs[1] = arg[0];                // group
    dumpargs[2] = arg[1];                // dump style
    dumpargs[3] = (char *) "0";          // dump frequency

    for (int i = 2; i < modindex; ++i)
        dumpargs[i+2] = arg[i];

    if (0) return;         // dummy line to enable else-if macro expansion

#define DUMP_CLASS
#define DumpStyle(key,Class) \
  else if (strcmp(arg[1],#key) == 0) dump = new Class(lmp,modindex+2,dumpargs);
#include "style_dump.h"
#undef DUMP_CLASS

    else error->all(FLERR,"Unknown dump style");

    if (modindex < narg) dump->modify_params(narg-modindex-1,&arg[modindex+1]);

    // write out one frame and then delete the dump again
    // set multifile_override for DumpImage so that filename needs no "*"

    if (strcmp(arg[1],"image") == 0)
        ((DumpImage *) dump)->multifile_override = 1;

    if (strcmp(arg[1],"cfg") == 0)
        ((DumpCFG *) dump)->multifile_override = 1;

    dump->init();
    dump->write();

    // delete the Dump instance and local storage

    delete dump;
    delete [] dumpargs;
}
Ejemplo n.º 9
0
 void DecodeR2P(const uint8_t* data, std::size_t size, Dump& result)
 {
   Require(size % sizeof(R2PEntry) == 0);
   Dump tmp;
   tmp.reserve(MAX_SECTOR_SIZE);
   for (const R2PEntry* it = safe_ptr_cast<const R2PEntry*>(data), *lim = it + size / sizeof(*it); it != lim; ++it)
   {
     const uint_t count = fromLE(it->Count);
     Require(count != 0);
     tmp.push_back(it->Data[0]);
     tmp.push_back(it->Data[1]);
     Require(CopyFromBack(sizeof(it->Data), tmp, sizeof(it->Data) * (count - 1)));
   }
   result.swap(tmp);
 }
void BufferManager::dump(Dump& d)
{
    d.append("Buffer Manager status: pool size %d\n", mBufferPool->getCacheSize());
    d.append("-------------------------------------------------------------\n");
    for (size_t i = 0; i < mBufferPool->getCacheSize(); i++) {
        BufferMapper *mapper = mBufferPool->getMapper(i);
        d.append("Buffer %d: handle %#x, (%dx%d), format %d, refCount %d\n",
                 i,
                 mapper->getHandle(),
                 mapper->getWidth(),
                 mapper->getHeight(),
                 mapper->getFormat(),
                 mapper->getRef());
    }
    return;
}
Ejemplo n.º 11
0
 void ApplyOverwrites(Dump& result) const
 {
   for (const auto& over : Overwrites)
   {
     std::copy(over.second.begin(), over.second.end(), result.begin() + over.first);
   }
 }
Ejemplo n.º 12
0
 void DecodeBlock(Binary::InputStream& stream, std::size_t srcSize, Dump& dst)
 {
   const std::size_t LOOKUP = 1;
   const uint8_t* const src = stream.ReadData(LOOKUP);
   const std::size_t used = DecodeBlock(src, srcSize, &dst[0], dst.size());
   stream.ReadData(used - LOOKUP);
 }
Ejemplo n.º 13
0
 void OnSector(const Formats::CHS& loc, const uint8_t* rawData, std::size_t rawSize, SectorDataType type, std::size_t targetSize) override
 {
   Dump result;
   switch (type)
   {
   case RAW_SECTOR:
     result.assign(rawData, rawData + rawSize);
     break;
   case R2P_SECTOR:
     DecodeR2P(rawData, rawSize, result);
     break;
   case RLE_SECTOR:
     DecodeRLE(rawData, rawSize, result);
     break;
   }
   Require(result.size() == targetSize);
   Builder->SetSector(loc, result);
 }
Ejemplo n.º 14
0
 Container::Ptr Decode(const Binary::Container& rawData) const override
 {
   using namespace CompiledSTP;
   if (!Player->Match(rawData))
   {
     return Container::Ptr();
   }
   const Binary::TypedContainer typedData(rawData);
   const std::size_t availSize = rawData.Size();
   const typename Version::RawPlayer& rawPlayer = *typedData.GetField<typename Version::RawPlayer>(0);
   const std::size_t playerSize = rawPlayer.GetSize();
   if (playerSize >= std::min(availSize, CompiledSTP::MAX_PLAYER_SIZE))
   {
     Dbg("Invalid player");
     return Container::Ptr();
   }
   Dbg("Detected player in first %1% bytes", playerSize);
   const std::size_t modDataSize = std::min(CompiledSTP::MAX_MODULE_SIZE, availSize - playerSize);
   const Binary::Container::Ptr modData = rawData.GetSubcontainer(playerSize, modDataSize);
   const Dump metainfo = rawPlayer.GetInfo();
   if (CompiledSTP::IsInfoEmpty(metainfo))
   {
     Dbg("Player has empty metainfo");
     if (const Binary::Container::Ptr originalModule = Formats::Chiptune::SoundTrackerPro::ParseCompiled(*modData, Formats::Chiptune::SoundTrackerPro::GetStubBuilder()))
     {
       const std::size_t originalSize = originalModule->Size();
       return CreateContainer(originalModule, playerSize + originalSize);
     }
   }
   else if (const Binary::Container::Ptr fixedModule = Formats::Chiptune::SoundTrackerPro::InsertMetaInformation(*modData, metainfo))
   {
     if (Formats::Chiptune::SoundTrackerPro::ParseCompiled(*fixedModule, Formats::Chiptune::SoundTrackerPro::GetStubBuilder()))
     {
       const std::size_t originalSize = fixedModule->Size() - metainfo.size();
       return CreateContainer(fixedModule, playerSize + originalSize);
     }
     Dbg("Failed to parse fixed module");
   }
   Dbg("Failed to find module after player");
   return Container::Ptr();
 }
Ejemplo n.º 15
0
 void AddData(const Dump& registers) override
 {
   Devices::AYM::Registers& data = Data->Allocate();
   const uint_t availRegs = std::min<uint_t>(registers.size(), Devices::AYM::Registers::ENV + 1);
   for (uint_t reg = 0, mask = 1; reg != availRegs; ++reg, mask <<= 1)
   {
     const uint8_t val = registers[reg];
     if (reg != Devices::AYM::Registers::ENV || val != 0xff)
     {
       data[static_cast<Devices::AYM::Registers::Index>(reg)] = val;
     }
   }
 }
Ejemplo n.º 16
0
void HwcLayerList::dump(Dump& d)
{
    d.append("Layer list: (number of layers %d):\n", mLayers.size());
    d.append(" LAYER |    TYPE    |   PLANE INDEX  \n");
    d.append("-------+------------+----------------\n");
    for (size_t i = 0; i < mLayers.size(); i++) {
        HwcLayer *hwcLayer = mLayers.itemAt(i);
        IDisplayPlane *plane;
        int planeIndex = -1;
        const char *type;

        if (hwcLayer) {
            switch (hwcLayer->getType()) {
            case HwcLayer::LAYER_FB:
                type = "FB";
                break;
            case HwcLayer::LAYER_SPRITE:
                type = "Sprite";
                break;
            case HwcLayer::LAYER_OVERLAY:
                type = "Overlay";
                break;
            case HwcLayer::LAYER_PRIMARY:
                type = "Primary";
                break;
            default:
                type = "Unknown";
            }

            plane = hwcLayer->getPlane();
            if (plane)
                planeIndex = plane->getIndex();


            d.append("  %2d   | %8s   |%10D  \n", i, type, planeIndex);
        }
    }
}
void DisplayPlaneManager::dump(Dump& d)
{
    d.append("Display Plane Manager state:\n");
    d.append("-------------------------------------------------------------\n");
    d.append(" PLANE TYPE | COUNT |   FREE   | RECLAIMED \n");
    d.append("------------+-------+----------+-----------\n");
    d.append("    SPRITE  |  %2d   | %08x | %08x\n",
             mPlaneCount[DisplayPlane::PLANE_SPRITE],
             mFreePlanes[DisplayPlane::PLANE_SPRITE],
             mReclaimedPlanes[DisplayPlane::PLANE_SPRITE]);
    d.append("   OVERLAY  |  %2d   | %08x | %08x\n",
             mPlaneCount[DisplayPlane::PLANE_OVERLAY],
             mFreePlanes[DisplayPlane::PLANE_OVERLAY],
             mReclaimedPlanes[DisplayPlane::PLANE_OVERLAY]);
    d.append("   PRIMARY  |  %2d   | %08x | %08x\n",
             mPlaneCount[DisplayPlane::PLANE_PRIMARY],
             mFreePlanes[DisplayPlane::PLANE_PRIMARY],
             mReclaimedPlanes[DisplayPlane::PLANE_PRIMARY]);
    d.append("   CURSOR   |  %2d   | %08x | %08x\n",
             mPlaneCount[DisplayPlane::PLANE_CURSOR],
             mFreePlanes[DisplayPlane::PLANE_CURSOR],
             mReclaimedPlanes[DisplayPlane::PLANE_CURSOR]);
}
Ejemplo n.º 18
0
int main( int argc , char ** argv ) {
    Dump d;
    return d.main( argc , argv );
}
Ejemplo n.º 19
0
int main( int argc , char ** argv, char ** envp ) {
    mongo::runGlobalInitializersOrDie(argc, argv, envp);
    Dump d;
    return d.main( argc , argv );
}
Ejemplo n.º 20
0
 void OverwriteData(std::size_t offset, const Dump& data) override
 {
   Require(offset + data.size() <= Source.Size());
   Require(Overwrites.insert(BlobsMap::value_type(offset, data)).second);
 }
Ejemplo n.º 21
0
 void InsertData(std::size_t offset, const Dump& data) override
 {
   Require(Insertions.insert(BlobsMap::value_type(offset, data)).second);
   SizeAddon += data.size();
 }
Ejemplo n.º 22
0
 void AddData(const Dump& str)
 {
   std::copy(str.begin(), str.end(), std::back_inserter(Data));
 }
Ejemplo n.º 23
0
int main(int argc, char *argv[])
{
    synth = new SYNTH_T;
    config.init();
    dump.startnow();
    int noui = 0;
    cerr
    << "\nZynAddSubFX - Copyright (c) 2002-2011 Nasca Octavian Paul and others"
    << endl;
    cerr << "Compiled: " << __DATE__ << " " << __TIME__ << endl;
    cerr << "This program is free software (GNU GPL v.2 or later) and \n";
    cerr << "it comes with ABSOLUTELY NO WARRANTY.\n" << endl;
    if(argc == 1)
        cerr << "Try 'zynaddsubfx --help' for command-line options." << endl;

    /* Get the settings from the Config*/
    synth->samplerate = config.cfg.SampleRate;
    synth->buffersize = config.cfg.SoundBufferSize;
    synth->oscilsize  = config.cfg.OscilSize;
    swaplr = config.cfg.SwapStereo;

    Nio::preferedSampleRate(synth->samplerate);

    synth->alias(); //build aliases

    sprng(time(NULL));

    /* Parse command-line options */
    struct option opts[] = {
        {
            "load", 2, NULL, 'l'
        },
        {
            "load-instrument", 2, NULL, 'L'
        },
        {
            "sample-rate", 2, NULL, 'r'
        },
        {
            "buffer-size", 2, NULL, 'b'
        },
        {
            "oscil-size", 2, NULL, 'o'
        },
        {
            "dump", 2, NULL, 'D'
        },
        {
            "swap", 2, NULL, 'S'
        },
        {
            "no-gui", 2, NULL, 'U'
        },
        {
            "dummy", 2, NULL, 'Y'
        },
        {
            "help", 2, NULL, 'h'
        },
        {
            "version", 2, NULL, 'v'
        },
        {
            "named", 1, NULL, 'N'
        },
        {
            "auto-connect", 0, NULL, 'a'
        },
        {
            "output", 1, NULL, 'O'
        },
        {
            "input", 1, NULL, 'I'
        },
        {
            "exec-after-init", 1, NULL, 'e'
        },
        {
            0, 0, 0, 0
        }
    };
    opterr = 0;
    int option_index = 0, opt, exitwithhelp = 0, exitwithversion = 0;

    string loadfile, loadinstrument, execAfterInit;

    while(1) {
        int tmp = 0;

        /**\todo check this process for a small memory leak*/
        opt = getopt_long(argc,
                          argv,
                          "l:L:r:b:o:I:O:N:e:hvaSDUY",
                          opts,
                          &option_index);
        char *optarguments = optarg;

#define GETOP(x) if(optarguments) \
        x = optarguments
#define GETOPNUM(x) if(optarguments) \
        x = atoi(optarguments)


        if(opt == -1)
            break;

        switch(opt) {
            case 'h':
                exitwithhelp = 1;
                break;
            case 'v':
                exitwithversion = 1;
                break;
            case 'Y': /* this command a dummy command (has NO effect)
                        and is used because I need for NSIS installer
                        (NSIS sometimes forces a command line for a
                        program, even if I don't need that; eg. when
                        I want to add a icon to a shortcut.
                     */
                break;
            case 'U':
                noui = 1;
                break;
            case 'l':
                GETOP(loadfile);
                break;
            case 'L':
                GETOP(loadinstrument);
                break;
            case 'r':
                GETOPNUM(synth->samplerate);
                if(synth->samplerate < 4000) {
                    cerr << "ERROR:Incorrect sample rate: " << optarguments
                         << endl;
                    exit(1);
                }
                break;
            case 'b':
                GETOPNUM(synth->buffersize);
                if(synth->buffersize < 2) {
                    cerr << "ERROR:Incorrect buffer size: " << optarguments
                         << endl;
                    exit(1);
                }
                break;
            case 'o':
                if(optarguments)
                    synth->oscilsize = tmp = atoi(optarguments);
                if(synth->oscilsize < MAX_AD_HARMONICS * 2)
                    synth->oscilsize = MAX_AD_HARMONICS * 2;
                synth->oscilsize =
                    (int) powf(2,
                               ceil(logf(synth->oscilsize - 1.0f) / logf(2.0f)));
                if(tmp != synth->oscilsize)
                    cerr
                    <<
                    "synth->oscilsize is wrong (must be 2^n) or too small. Adjusting to "
                    << synth->oscilsize << "." << endl;
                break;
            case 'S':
                swaplr = 1;
                break;
            case 'D':
                dump.startnow();
                break;
            case 'N':
                Nio::setPostfix(optarguments);
                break;
            case 'I':
                if(optarguments)
                    Nio::setDefaultSource(optarguments);
                break;
            case 'O':
                if(optarguments)
                    Nio::setDefaultSink(optarguments);
                break;
            case 'a':
                Nio::autoConnect = true;
                break;
            case 'e':
                GETOP(execAfterInit);
                break;
            case '?':
                cerr << "ERROR:Bad option or parameter.\n" << endl;
                exitwithhelp = 1;
                break;
        }
    }

    synth->alias();

    if(exitwithversion) {
        cout << "Version: " << VERSION << endl;
        return 0;
    }
    if(exitwithhelp != 0) {
        cout << "Usage: zynaddsubfx [OPTION]\n\n"
             << "  -h , --help \t\t\t\t Display command-line help and exit\n"
             << "  -v , --version \t\t\t Display version and exit\n"
             << "  -l file, --load=FILE\t\t\t Loads a .xmz file\n"
             << "  -L file, --load-instrument=FILE\t Loads a .xiz file\n"
             << "  -r SR, --sample-rate=SR\t\t Set the sample rate SR\n"
             <<
        "  -b BS, --buffer-size=SR\t\t Set the buffer size (granularity)\n"
             << "  -o OS, --oscil-size=OS\t\t Set the ADsynth oscil. size\n"
             << "  -S , --swap\t\t\t\t Swap Left <--> Right\n"
             << "  -D , --dump\t\t\t\t Dumps midi note ON/OFF commands\n"
             <<
        "  -U , --no-gui\t\t\t\t Run ZynAddSubFX without user interface\n"
             << "  -N , --named\t\t\t\t Postfix IO Name when possible\n"
             << "  -a , --auto-connect\t\t\t AutoConnect when using JACK\n"
             << "  -O , --output\t\t\t\t Set Output Engine\n"
             << "  -I , --input\t\t\t\t Set Input Engine\n"
             << "  -e , --exec-after-init\t\t Run post-initialization script\n"
             << endl;

        return 0;
    }

    //produce denormal buf
    denormalkillbuf = new float [synth->buffersize];
    for(int i = 0; i < synth->buffersize; ++i)
        denormalkillbuf[i] = (RND - 0.5f) * 1e-16;

    initprogram();

    if(!loadfile.empty()) {
        int tmp = master->loadXML(loadfile.c_str());
        if(tmp < 0) {
            cerr << "ERROR: Could not load master file " << loadfile
                 << "." << endl;
            exit(1);
        }
        else {
            master->applyparameters();
            cout << "Master file loaded." << endl;
        }
    }

    if(!loadinstrument.empty()) {
        int loadtopart = 0;
        int tmp = master->part[loadtopart]->loadXMLinstrument(
            loadinstrument.c_str());
        if(tmp < 0) {
            cerr << "ERROR: Could not load instrument file "
                 << loadinstrument << '.' << endl;
            exit(1);
        }
        else {
            master->part[loadtopart]->applyparameters();
            cout << "Instrument file loaded." << endl;
        }
    }

    //Run the Nio system
    bool ioGood = Nio::start();

    if(!execAfterInit.empty()) {
        cout << "Executing user supplied command: " << execAfterInit << endl;
        if(system(execAfterInit.c_str()) == -1)
            cerr << "Command Failed..." << endl;
    }


#ifndef DISABLE_GUI

#ifdef NTK_GUI
    fl_register_images();

    Fl_Tooltip::textcolor(0x0);

    Fl_Dial::default_style(Fl_Dial::PIXMAP_DIAL);

    if(Fl_Shared_Image *img = Fl_Shared_Image::get(PIXMAP_PATH "/knob.png"))
        Fl_Dial::default_image(img);
    else
        Fl_Dial::default_image(Fl_Shared_Image::get(SOURCE_DIR "/../pixmaps/knob.png"));

    if(Fl_Shared_Image *img = Fl_Shared_Image::get(PIXMAP_PATH "/window_backdrop.png"))
        Fl::scheme_bg(new Fl_Tiled_Image(img));
    else
        Fl::scheme_bg(new Fl_Tiled_Image(Fl_Shared_Image::get(SOURCE_DIR "/../pixmaps/window_backdrop.png")));

    if(Fl_Shared_Image *img = Fl_Shared_Image::get(PIXMAP_PATH "/module_backdrop.png"))
        module_backdrop = new Fl_Tiled_Image(img);
    else
        module_backdrop = new Fl_Tiled_Image(Fl_Shared_Image::get(SOURCE_DIR "/../pixmaps/module_backdrop.png"));

    Fl::background(  50, 50, 50 );
    Fl::background2(  70, 70, 70 );
    Fl::foreground( 255,255,255 );
#endif

    ui = new MasterUI(master, &Pexitprogram);
    
    if ( !noui) 
    {
        ui->showUI();

        if(!ioGood)
            fl_alert(
                "Default IO did not initialize.\nDefaulting to NULL backend.");
    }

#endif

#ifndef DISABLE_GUI
#if USE_NSM
    char *nsm_url = getenv("NSM_URL");

    if(nsm_url) {
        nsm = new NSM_Client;

        if(!nsm->init(nsm_url))
            nsm->announce("ZynAddSubFX", ":switch:", argv[0]);
        else {
            delete nsm;
            nsm = NULL;
        }
    }
#endif
#endif

#if USE_NSM
    if(!nsm)
#endif
    {
#if LASH
        lash = new LASHClient(&argc, &argv);
#ifndef DISABLE_GUI
        ui->sm_indicator1->value(1);
        ui->sm_indicator2->value(1);
        ui->sm_indicator1->tooltip("LASH");
        ui->sm_indicator2->tooltip("LASH");
#endif
#endif
    }

    while(Pexitprogram == 0) {
#ifndef DISABLE_GUI
#if USE_NSM
        if(nsm) {
            nsm->check();
            goto done;
        }
#endif
#if LASH
        {
            string filename;
            switch(lash->checkevents(filename)) {
                case LASHClient::Save:
                    ui->do_save_master(filename.c_str());
                    lash->confirmevent(LASHClient::Save);
                    break;
                case LASHClient::Restore:
                    ui->do_load_master(filename.c_str());
                    lash->confirmevent(LASHClient::Restore);
                    break;
                case LASHClient::Quit:
                    Pexitprogram = 1;
                default:
                    break;
            }
        }
#endif //LASH

#if USE_NSM
done:
#endif

        Fl::wait(0.02f);
#else
        usleep(100000);
#endif
    }

    exitprogram();
    return 0;
}