summaryrefslogtreecommitdiffstats
path: root/libk3b/projects/audiocd/k3baudiozerodata.cpp
blob: aff0cf9c391e8b2876c5bdd5b39de390aede4895 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* 
 *
 * $Id: k3baudiozerodata.cpp 619556 2007-01-03 17:38:12Z trueg $
 * Copyright (C) 2004 Sebastian Trueg <[email protected]>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <[email protected]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * See the file "COPYING" for the exact licensing terms.
 */

#include "k3baudiozerodata.h"
#include "k3baudiotrack.h"

#include <klocale.h>

#include <string.h>


K3bAudioZeroData::K3bAudioZeroData( const K3b::Msf& len )
  : K3bAudioDataSource(),
    m_length(len),
    m_writtenData(0)
{
}


K3bAudioZeroData::K3bAudioZeroData( const K3bAudioZeroData& zero )
  : K3bAudioDataSource( zero ),
    m_length( zero.m_length ),
    m_writtenData( 0 )
{
}


K3bAudioZeroData::~K3bAudioZeroData()
{
}


void K3bAudioZeroData::setLength( const K3b::Msf& msf )
{
  if( msf > 0 )
    m_length = msf;
  else
    m_length = 1; // 1 frame

  m_writtenData = 0;

  emitChange();
}


TQString K3bAudioZeroData::type() const
{
  return i18n("Silence");
}


TQString K3bAudioZeroData::sourceComment() const
{
  return TQString();
}


bool K3bAudioZeroData::seek( const K3b::Msf& msf )
{
  if( msf < length() ) {
    m_writtenData = msf.audioBytes();
    return true;
  }
  else
    return false;
}


int K3bAudioZeroData::read( char* data, unsigned int max )
{
  if( m_writtenData + max > length().audioBytes() )
    max = length().audioBytes() - m_writtenData;

  m_writtenData += max;

  ::memset( data, 0, max );

  return max;
}


K3bAudioDataSource* K3bAudioZeroData::copy() const
{
  return new K3bAudioZeroData( *this );
}


void K3bAudioZeroData::setStartOffset( const K3b::Msf& pos )
{
  if( pos >= length() )
    setLength( 1 );
  else
    setLength( length() - pos );
}


void K3bAudioZeroData::setEndOffset( const K3b::Msf& pos )
{
  if( pos < 1 )
    setLength( 1 );
  else
    setLength( pos );
}