Blame xdao/TocEditView.cc

Packit bf707c
/*  cdrdao - write audio CD-Rs in disc-at-once mode
Packit bf707c
 *
Packit bf707c
 *  Copyright (C) 1998-2000 Andreas Mueller <mueller@daneb.ping.de>
Packit bf707c
 *
Packit bf707c
 *  This program is free software; you can redistribute it and/or modify
Packit bf707c
 *  it under the terms of the GNU General Public License as published by
Packit bf707c
 *  the Free Software Foundation; either version 2 of the License, or
Packit bf707c
 *  (at your option) any later version.
Packit bf707c
 *
Packit bf707c
 *  This program is distributed in the hope that it will be useful,
Packit bf707c
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit bf707c
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit bf707c
 *  GNU General Public License for more details.
Packit bf707c
 *
Packit bf707c
 *  You should have received a copy of the GNU General Public License
Packit bf707c
 *  along with this program; if not, write to the Free Software
Packit bf707c
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Packit bf707c
 */
Packit bf707c
Packit bf707c
#include "TocEditView.h"
Packit bf707c
Packit bf707c
#include <stddef.h>
Packit bf707c
Packit bf707c
#include "guiUpdate.h"
Packit bf707c
#include "TocEdit.h"
Packit bf707c
Packit bf707c
TocEditView::TocEditView(TocEdit *t)
Packit bf707c
{
Packit bf707c
  tocEdit_ = t;
Packit bf707c
Packit bf707c
  sampleMarkerValid_ = false;
Packit bf707c
  sampleSelectionValid_ = false;
Packit bf707c
  sampleViewMin_ = sampleViewMax_ = 0;
Packit bf707c
  trackSelectionValid_ = 0;
Packit bf707c
  indexSelectionValid_ = 0;
Packit bf707c
}
Packit bf707c
Packit bf707c
TocEditView::~TocEditView()
Packit bf707c
{
Packit bf707c
  tocEdit_ = 0;
Packit bf707c
}
Packit bf707c
Packit bf707c
TocEdit *TocEditView::tocEdit() const
Packit bf707c
{
Packit bf707c
  return tocEdit_;
Packit bf707c
}
Packit bf707c
Packit bf707c
Packit bf707c
void TocEditView::sampleMarker(unsigned long sample)
Packit bf707c
{
Packit bf707c
  if (sample < tocEdit_->toc()->length().samples()) {
Packit bf707c
    sampleMarker_ = sample;
Packit bf707c
    sampleMarkerValid_ = true;
Packit bf707c
  }
Packit bf707c
  else {
Packit bf707c
    sampleMarkerValid_ = false;
Packit bf707c
  }
Packit bf707c
}
Packit bf707c
Packit bf707c
bool TocEditView::sampleMarker(unsigned long *sample) const
Packit bf707c
{
Packit bf707c
  if (sampleMarkerValid_)
Packit bf707c
    *sample = sampleMarker_;
Packit bf707c
Packit bf707c
  return sampleMarkerValid_;
Packit bf707c
}
Packit bf707c
Packit bf707c
void TocEditView::sampleSelectAll()
Packit bf707c
{
Packit bf707c
  unsigned long slength = tocEdit_->toc()->length().samples();
Packit bf707c
Packit bf707c
  if (slength) {
Packit bf707c
    sampleSelectionMin_ = 0;
Packit bf707c
    sampleSelectionMax_ = slength - 1;
Packit bf707c
    sampleSelectionValid_ = true;
Packit bf707c
  }
Packit bf707c
}
Packit bf707c
Packit bf707c
void TocEditView::sampleSelect(unsigned long smin, unsigned long smax)
Packit bf707c
{
Packit bf707c
  unsigned long tmp;
Packit bf707c
Packit bf707c
  if (smin > smax) {
Packit bf707c
    tmp = smin;
Packit bf707c
    smin = smax;
Packit bf707c
    smax = tmp;
Packit bf707c
  }
Packit bf707c
Packit bf707c
  if (smax < tocEdit_->toc()->length().samples()) {
Packit bf707c
    sampleSelectionMin_ = smin;
Packit bf707c
    sampleSelectionMax_ = smax;
Packit bf707c
Packit bf707c
    sampleSelectionValid_ = true;
Packit bf707c
  }
Packit bf707c
  else {
Packit bf707c
    sampleSelectionValid_ = false;
Packit bf707c
  }
Packit bf707c
}
Packit bf707c
Packit bf707c
bool TocEditView::sampleSelectionClear()
Packit bf707c
{
Packit bf707c
  if (sampleSelectionValid_) {
Packit bf707c
    sampleSelectionValid_ = false;
Packit bf707c
    return true;
Packit bf707c
  }
Packit bf707c
  return false;
Packit bf707c
}
Packit bf707c
Packit bf707c
bool TocEditView::sampleSelection(unsigned long *smin,
Packit bf707c
                                  unsigned long *smax) const
Packit bf707c
{
Packit bf707c
  if (sampleSelectionValid_) {
Packit bf707c
    *smin = sampleSelectionMin_;
Packit bf707c
    *smax = sampleSelectionMax_;
Packit bf707c
  }
Packit bf707c
Packit bf707c
  return sampleSelectionValid_;
Packit bf707c
}
Packit bf707c
Packit bf707c
bool TocEditView::sampleView(unsigned long smin, unsigned long smax)
Packit bf707c
{
Packit bf707c
  if (smin <= smax && smax < tocEdit_->lengthSample()) {
Packit bf707c
    sampleViewMin_ = smin;
Packit bf707c
    sampleViewMax_ = smax;
Packit bf707c
    return true;
Packit bf707c
  }
Packit bf707c
  return false;
Packit bf707c
}
Packit bf707c
Packit bf707c
void TocEditView::sampleView(unsigned long *smin, unsigned long *smax) const
Packit bf707c
{
Packit bf707c
  *smin = sampleViewMin_;
Packit bf707c
  *smax = sampleViewMax_;
Packit bf707c
}
Packit bf707c
Packit bf707c
void TocEditView::sampleViewFull()
Packit bf707c
{
Packit bf707c
  sampleViewMin_ = 0;
Packit bf707c
Packit bf707c
  if ((sampleViewMax_ = tocEdit_->lengthSample()) > 0)
Packit bf707c
    sampleViewMax_ -= 1;
Packit bf707c
}
Packit bf707c
Packit bf707c
void TocEditView::sampleViewUpdate()
Packit bf707c
{
Packit bf707c
  if (sampleViewMax_ >= tocEdit_->lengthSample()) {
Packit bf707c
    unsigned long len = sampleViewMax_ - sampleViewMin_;
Packit bf707c
Packit bf707c
    if ((sampleViewMax_ = tocEdit_->lengthSample()) > 0)
Packit bf707c
      sampleViewMax_ -= 1;
Packit bf707c
    
Packit bf707c
Packit bf707c
    if (sampleViewMax_ >= len)
Packit bf707c
      sampleViewMin_ = sampleViewMax_ - len;
Packit bf707c
    else
Packit bf707c
      sampleViewMin_ = 0;
Packit bf707c
Packit bf707c
    tocEdit_->updateLevel_ |= UPD_SAMPLES;
Packit bf707c
  }
Packit bf707c
}
Packit bf707c
Packit bf707c
void TocEditView::sampleViewInclude(unsigned long smin, unsigned long smax)
Packit bf707c
{
Packit bf707c
  if (smin < sampleViewMin_) {
Packit bf707c
    sampleViewMin_ = smin;
Packit bf707c
    tocEdit_->updateLevel_ |= UPD_SAMPLES;
Packit bf707c
  }
Packit bf707c
Packit bf707c
  if (smax < tocEdit_->lengthSample() && smax > sampleViewMax_) {
Packit bf707c
    sampleViewMax_ = smax;
Packit bf707c
    tocEdit_->updateLevel_ |= UPD_SAMPLES;
Packit bf707c
  }
Packit bf707c
}
Packit bf707c
Packit bf707c
void TocEditView::trackSelection(int tnum)
Packit bf707c
{
Packit bf707c
  if (tnum > 0) {
Packit bf707c
    trackSelection_ = tnum;
Packit bf707c
    trackSelectionValid_ = 1;
Packit bf707c
  }
Packit bf707c
  else {
Packit bf707c
    trackSelectionValid_ = 0;
Packit bf707c
  }
Packit bf707c
}
Packit bf707c
Packit bf707c
int TocEditView::trackSelection(int *tnum) const
Packit bf707c
{
Packit bf707c
  if (trackSelectionValid_)
Packit bf707c
    *tnum = trackSelection_;
Packit bf707c
Packit bf707c
  return trackSelectionValid_;
Packit bf707c
}
Packit bf707c
Packit bf707c
void TocEditView::indexSelection(int inum)
Packit bf707c
{
Packit bf707c
  if (inum >= 0) {
Packit bf707c
    indexSelection_ = inum;
Packit bf707c
    indexSelectionValid_ = 1;
Packit bf707c
  }
Packit bf707c
  else {
Packit bf707c
    indexSelectionValid_ = 0;
Packit bf707c
  }
Packit bf707c
}
Packit bf707c
Packit bf707c
int TocEditView::indexSelection(int *inum) const
Packit bf707c
{
Packit bf707c
  if (indexSelectionValid_)
Packit bf707c
    *inum = indexSelection_;
Packit bf707c
Packit bf707c
  return indexSelectionValid_;
Packit bf707c
}