示例#1
0
void TrackComponent::mouseDrag(const MouseEvent &e)
{
    int posX;
    if(_regionComponents.size() != 0)
    {
        MouseEvent ev = e.getEventRelativeTo(this);
        posX = ev.x;
        for (std::size_t i = 0; i != _regionComponents.size(); ++i)
        {
            _regionComponents.at(i)->toFront(true);
            
            int distance = ev.getDistanceFromDragStartX();
            Rectangle<int> r = _regionComponents.at(i)->getBounds();
            if(_regionComponents.at(i)->getPositionX() < posX && posX < (_regionComponents.at(i)->getPositionX() + _regionComponents.at(i)->getRegionWidth()))
            {
                int newPos = r.getX() + distance;
                int newEnd = r.getX() + distance + r.getWidth();
                _posX.at(i) = newPos;
                _regionComponents.at(i)->setBounds(newPos, 0, newEnd - newPos, getHeight());
                resized();
                
                int64 samplesRange = secondsToSamples(static_cast<double>(_numberOfClips), _sampleRate);
                int64 positionSamples = pixelsToSamples(newPos - _mixerOffset, _numberOfClips * _pixelsPerClip, samplesRange);
                int64 widthInSamples = pixelsToSamples(newEnd - _mixerOffset, _numberOfClips * _pixelsPerClip, samplesRange);
                _track->setTotalLength(widthInSamples);
                _track->move(_regionComponents.at(i)->getRegion(), positionSamples);
                
                if(_posX.at(i) < _mixerOffset)
                {
                    _posX.at(i) = getX() + _mixerOffset ;
                    _track->move(_regionComponents.at(i)->getRegion(), 0);
                    resized();
                }
            }
            else if((getComponentAt(e.x, e.y ) == _regionComponents.at(i)))
            {
                if(ev.x > _mixerOffset)
                {
                    int newPos = r.getX() + distance;
                    int newEnd = r.getX() + distance + r.getWidth();
                    _posX.at(i) = newPos;
                    resized();
                    Region* region = _regionComponents.at(i)->getRegion();
                    region->setNextReadPosition(0);
                    int64 samplesRange = secondsToSamples((double)_numberOfClips, _sampleRate);
                    int64 positionSamples = pixelsToSamples(newPos - _mixerOffset, _numberOfClips * _pixelsPerClip, samplesRange);
                    int64 widthInSamples = pixelsToSamples(newEnd - _mixerOffset, _numberOfClips * _pixelsPerClip, samplesRange);
                    _track->setTotalLength(widthInSamples);
                    _track->move(region, positionSamples);
                    if(_posX.at(i) < _mixerOffset)
                    {
                        _posX.at(i) = getX() + _mixerOffset ;
                        _track->move(region, 0);
                        resized();
                    }
                 }
            }
        }
    }
}
示例#2
0
void TrackComponent::filesDropped(const StringArray & files, int x, int)
{
    for (auto current = files.begin(), end = files.end(); current != end; ++current)
    {
        const String fileString = *current;
        String format;
        if(fileString.contains(".wav") || fileString.contains(".WAV"))
            format = "WAV";
        else if(fileString.contains(".aif") || fileString.contains(".aiff") || fileString.contains(".AIF") || fileString.contains(".AIFF"))
            format = "AIFF";
        else if(fileString.contains(".flac") || fileString.contains(".FLAC"))
            format = "FLAC";
        File file(fileString);
        AudioFormatManager formatManager;
        formatManager.registerBasicFormats();
        
        AudioFormatReader* reader = formatManager.createReaderFor(file);
        Region* region = new SampleRegion(reader, 1, &file);
        if(x > _mixerOffset)
        {
            int64 samplesRange = secondsToSamples((double)_numberOfClips, _sampleRate);
            int64 positionSamples = pixelsToSamples(x - _mixerOffset, _numberOfClips * _pixelsPerClip, samplesRange);
            
            _track->add(positionSamples, region);
            createRegionGUI(x, region, formatManager, file);
        }
        else if(x < _mixerOffset)
        {
            _track->add(0, region);
            createRegionGUI(_mixerOffset, region, formatManager, file);
        }
    }
}
示例#3
0
void GdImageRenderer::drawTimeAxisLabels() const
{
    const int marker_height = 10;

    // Time interval between axis markers (seconds)
    const int axis_label_interval_secs = getAxisLabelScale();

    // Time of first axis marker (seconds)
    const int first_axis_label_secs = MathUtil::roundUpToNearest(start_time_, axis_label_interval_secs);

    // Distance between waveform start time and first axis marker (seconds)
    const double axis_label_offset_secs = first_axis_label_secs - start_time_;

    // Distance between waveform start time and first axis marker (samples)
    const int axis_label_offset_samples = secondsToSamples(axis_label_offset_secs);

    // Distance between waveform start time and first axis marker (pixels)
    const int axis_label_offset_pixels = axis_label_offset_samples / samples_per_pixel_;

    assert(axis_label_offset_pixels >= 0);

    gdFontPtr font = gdFontGetSmall();

    int secs = first_axis_label_secs;

    for (;;) {
        const int x = axis_label_offset_pixels +
            (secs - first_axis_label_secs) * sample_rate_ / samples_per_pixel_;

        assert(x >= 0);

        if (x >= image_width_) {
            break;
        }

        gdImageLine(image_, x, 0, x, marker_height, border_color_);
        gdImageLine(image_, x, image_height_ - 1, x, image_height_ - 1 - marker_height, border_color_);

        char label[50];
        const int label_length = TimeUtil::secondsToString(label, ARRAY_LENGTH(label), secs);

        const int label_width = font->w * label_length;
        const int label_x = x - (label_width / 2) + 1;
        const int label_y = image_height_ - 1 - marker_height - 1 - font->h;

        if (label_x >= 0) {
            gdImageString(
                image_,
                font,
                label_x,
                label_y,
                reinterpret_cast<unsigned char*>(label),
                axis_label_color_
            );
        }

        secs += axis_label_interval_secs;
    }
}
void AudioFilePlayerExt::setPosition (double newPosition, bool ignoreAnyLoopBounds)
{
    if (ignoreAnyLoopBounds && loopingAudioSource != nullptr)
    {
        const double sampleRate = audioFormatReaderSource->getAudioFormatReader()->sampleRate;
        
        if (sampleRate > 0.0)
            loopingAudioSource->setNextReadPositionIgnoringLoop (secondsToSamples (newPosition, sampleRate));
    }
    else
    {
        AudioFilePlayer::setPosition (newPosition);
    }
}
示例#5
0
/*
Used by loadTracks to add each tracks associated regions to the UI
*/
void ProjectManager::addRegionGUIs(std::vector<Track*> audioTracks_)
{
	std::vector<TrackComponent*>* trackComponents_ = _mainWindow.Content.getArrangement()->getTrackMap();
	
	int numberOfTracks_ = projectElements
		->getChildByName("Tracks")
		->getNumChildElements();
	if (numberOfTracks_ > 0)
	{
		//Create XML elements for each track
		int trackNumber_ = 1;
		while (trackNumber_ <= numberOfTracks_)
		{
			//Find out the number of regions the loaded track has
			String trackName_ = "Track_" + (String)trackNumber_;
			int numberOfRegions_ = projectElements
				->getChildByName("Tracks")
				->getChildByName(trackName_)
				->getNumChildElements();
			if (numberOfRegions_ > 0)
			{
				int currentRegion_ = 1;
				//Loop through and add the regions
				while (currentRegion_ <= numberOfRegions_)
				{
					String regionName_ = "Region_" + (String)currentRegion_;
					//Retrieve the file path associated with the region
					String fileString_ = projectElements
						->getChildByName("Tracks")
						->getChildByName(trackName_)
						->getChildByName(regionName_)
						->getStringAttribute("File_Path");
					//Check that the file is in the correct format
					String format_;
					if (fileString_.contains(".wav") || fileString_.contains(".WAV"))
						format_ = "WAV";
					else if (fileString_.contains(".aif") || fileString_.contains(".aiff") || fileString_.contains(".AIF") || fileString_.contains(".AIFF"))
						format_ = "AIFF";
					else if (fileString_.contains(".flac") || fileString_.contains(".FLAC"))
						format_ = "FLAC";
					File currentRegionFile_(fileString_);

					//Create a format manager and register basic formats (WAV, AIF(F), Flac)
					AudioFormatManager formatManager_;
					formatManager_.registerBasicFormats();

					//Create a reader for the Region file
					AudioFormatReader* reader_ = formatManager_.createReaderFor(currentRegionFile_);
					//Create the necessary region
					Audio::Region* region = new Audio::SampleRegion(reader_, 1, &currentRegionFile_);

					//Retrieve the regions position
					int regionPosition_ = projectElements
						->getChildByName("Tracks")
						->getChildByName(trackName_)
						->getChildByName(regionName_)
						->getIntAttribute("Region_Position");
					int64 mixerOffset_ = _mainWindow.Content.getArrangement()->getMixerOffset();
					int64 pixelsPerClip_ = _mainWindow.Content.getArrangement()->getPixelsPerClip();
					double sampleRate_ = _engine.getCurrentSamplerate();

					if (regionPosition_ >= mixerOffset_)
					{
						int64 samplesRange_ = secondsToSamples(100, sampleRate_);
						int64 positionSamples_ = pixelsToSamples(regionPosition_ - mixerOffset_, 100 * pixelsPerClip_, samplesRange_);

						audioTracks_.at(trackNumber_ - 1)->add(positionSamples_, region);
						trackComponents_->at(trackNumber_-1)->createRegionGUI(regionPosition_, region, formatManager_, currentRegionFile_);
					}
					else if (regionPosition_ < mixerOffset_)
					{
						audioTracks_.at(trackNumber_)->add(0, region);
						trackComponents_->at(trackNumber_-1)->createRegionGUI(mixerOffset_, region, formatManager_, currentRegionFile_);
					}
					currentRegion_++;
				}
			}
			trackNumber_++;
		}
	}
}
示例#6
0
void TrackComponent::mouseDown(const MouseEvent &e) {

	ModifierKeys modifiers = ModifierKeys::getCurrentModifiersRealtime();

    int posX;
	// check the mod keys ..
	if (modifiers.isPopupMenu() || modifiers.isCtrlDown())
	{
		ScopedPointer<PopupMenu> trackMenu_ = new PopupMenu();
		trackMenu_->clear();
		trackMenu_->addCommandItem(&_commands, MainWindow::showMixer);
		trackMenu_->addItem(1, "Add Region", true);
        MouseEvent ev = e.getEventRelativeTo(this);
        for(auto region : _regionComponents)
        {
            posX = ev.x;
            region->setBroughtToFrontOnMouseClick(true);
            if(region->getPositionX() < posX && posX < (region->getPositionX() + region->getRegionWidth()))
            {
                trackMenu_->addItem(2, "Remove Region", true);
            }
        }
        switch (trackMenu_->show())
        {
            case 1:
            {
                FileChooser chooser("Select an audio file to add...",
                                    File::nonexistent,
                                    "*.wav; *aif; *.flac");
                if (chooser.browseForFileToOpen()) {
                    File audioFile(chooser.getResult());
                    const String fileString = audioFile.getFullPathName();
                    String format;
                    if (fileString.contains(".wav"))
                        format = "WAV";
                    else if (fileString.contains(".aif") || fileString.contains(".aiff"))
                        format = "AIFF";
                    else if (fileString.contains(".flac"))
                        format = "FLAC";
                    AudioFormatManager formatManager;
                    formatManager.registerBasicFormats();
                    
                    AudioFormatReader* reader = formatManager.createReaderFor(audioFile);
                    Audio::Region* region = new Audio::SampleRegion(reader, 1, &audioFile);
                    Point<int> position = e.getPosition();
                    int x = position.getX();
                    
                    if (x > _mixerOffset)
                    {
                        int64 samplesRange = secondsToSamples(100, _sampleRate);
                        int64 positionSamples = pixelsToSamples(x - _mixerOffset, 100 * _pixelsPerClip, samplesRange);
                        
                        _track->add(positionSamples, region);
                        createRegionGUI(x, region, formatManager, audioFile);
                        getParentComponent()->resized();
                    }
                    else if (x < _mixerOffset)
                    {
                        _track->add(0, region);
                        createRegionGUI(_mixerOffset, region, formatManager, audioFile);
                        getParentComponent()->resized();
                    }
                }
            }
                break;
            case 2:
            {
                CriticalSection critical;
                critical.enter();
                for(size_t i = 0; i < _regionComponents.size(); ++i)
                {
                    
                    Rectangle<int> bounds_ = _regionComponents.at(i)->getBounds();
					posX = ev.x;
                    if((int)_regionComponents.at(i)->getPositionX() < posX && posX < ((int)_regionComponents.at(i)->getPositionX() + (int)_regionComponents.at(i)->getRegionWidth()))
                    {
                        _track->remove(_regionComponents.at(i)->getRegion(), _posX.at(i));
                        std::vector<RegionComponent*>::iterator regit = _regionComponents.begin() + i;
                        RegionComponent* component = _regionComponents.at(i);
                        removeChildComponent(_regionComponents.at(i));
                        _regionComponents.erase(regit);
                        delete component;
                        _regions.erase(_posX.at(i));
                        std::vector<int64>::iterator posit = _posX.begin() + i;;
                        _posX.erase(posit);
                        std::vector<int64>::iterator sampsit = _sizeSamps.begin() + i;;
                        _sizeSamps.erase(sampsit);
                    }
                }
                critical.exit();
            }
            default:
                break;
        }
    }
}
示例#7
0
double TSoundTrack::getMinPressure(double t0, double t1,
                                   TSound::Channel chan) const {
  return getMinPressure(secondsToSamples(t0), secondsToSamples(t1), chan);
}
示例#8
0
void TSoundTrack::getMinMaxPressure(double t0, double t1, TSound::Channel chan,
                                    double &min, double &max) const {
  getMinMaxPressure(secondsToSamples(t0), secondsToSamples(t1), chan, min, max);
}
示例#9
0
double TSoundTrack::getPressure(double second, TSound::Channel chan) const {
  return getPressure(secondsToSamples(second), chan);
}
示例#10
0
void TSoundTrack::blank(double t0, double t1) {
  blank(secondsToSamples(t0), secondsToSamples(t1));
}
示例#11
0
void TSoundTrack::copy(const TSoundTrackP &src, double dst_t0) {
  copy(src, secondsToSamples(dst_t0));
}
示例#12
0
TSoundTrackP TSoundTrack::extract(double t0, double t1) {
  return extract(secondsToSamples(t0), secondsToSamples(t1));
}