summaryrefslogtreecommitdiffstats
path: root/libk3b/projects/k3binffilewriter.cpp
blob: 050b69f04ab9744bd8461364d0f8c054f78f8732 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* 
 *
 * $Id: k3binffilewriter.cpp 619556 2007-01-03 17:38:12Z trueg $
 * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * 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 "k3binffilewriter.h"

#include <k3bcdtext.h>
#include <k3btrack.h>
#include <k3bmsf.h>
#include <k3bcore.h>
#include <k3bversion.h>

#include <tqfile.h>
#include <tqtextstream.h>
#include <tqdatetime.h>



K3bInfFileWriter::K3bInfFileWriter()
  : m_index0(-1),
    m_trackNumber(1),
    m_trackStart(0),
    m_trackLength(0),
    m_preEmphasis(false),
    m_copyPermitted(true),
    m_bigEndian(false)
{
}


bool K3bInfFileWriter::save( const TQString& filename )
{
  TQFile f( filename );

  if( !f.open( IO_WriteOnly ) ) {
    kdDebug() << "(K3bInfFileWriter) could not open file " << f.name() << endl;
    return false;
  }

  TQTextStream s( &f );

  return save( s );
}


bool K3bInfFileWriter::save( TQTextStream& s )
{
  // now write the inf data
  // ----------------------
  // header
  s << "# Cdrecord-Inf-File written by K3b " << k3bcore->version() 
    << ", " << TQDateTime::currentDateTime().toString() << endl
    << "#" << endl;

  s << "ISRC=\t\t" << m_isrc << endl;
  s << "MCN=\t\t" << m_mcn << endl;

  // CD-Text
  s << "Albumperformer=\t" << "'" << m_albumPerformer << "'" << endl;
  s << "Albumtitle=\t" << "'" << m_albumTitle << "'" << endl;
    
  s << "Performer=\t" << "'" << m_trackPerformer << "'" << endl;
  s << "Songwriter=\t" << "'" << m_trackSongwriter << "'" << endl;
  s << "Composer=\t" << "'" << m_trackComposer << "'" << endl;
  s << "Arranger=\t" << "'" << m_trackArranger << "'" << endl;
  s << "Message=\t" << "'" << m_trackMessage << "'" << endl;
    
  s << "Tracktitle=\t" << "'" << m_trackTitle << "'" << endl;
    
  s << "Tracknumber=\t" << m_trackNumber << endl;

  // track start
  s << "Trackstart=\t" << m_trackStart.lba() << endl;

  // track length
  s << "# Tracklength: " << m_trackLength.toString() << endl;
  s << "Tracklength=\t" << m_trackLength.totalFrames() << ", 0" << endl;

  // pre-emphasis
  s << "Pre-emphasis=\t";
  if( m_preEmphasis )
    s << "yes";
  else
    s << "no";
  s << endl;

  // channels (always 2)
  s << "Channels=\t2" << endl;

  // copy-permitted
  // TODO: not sure about this!
  //       there are three options: yes, no, once
  //       but using "once" gives the same result as with cdrdao
  //       and that's important.
  s << "Copy_permitted=\t";
  if( m_copyPermitted )
    s << "yes";
  else
    s << "once";
  s << endl;

  // endianess - wav is little -> onthefly: big, with images: little
  s << "Endianess=\t";
  if( m_bigEndian )
    s << "big";
  else
    s << "little";
  s << endl;

  // write indices
  // the current tracks' data contains the pregap of the next track
  // if the pregap has length 0 we need no index 0
  if( m_indices.isEmpty() )
    s << "Index=\t\t0" << endl;
  else {
    for( unsigned int i = 0; i < m_indices.count(); ++i )
      s << "Index=\t\t" << m_indices[i] << endl;
  }

  s << "Index0=\t\t" << m_index0 << endl;

  return ( s.device()->status() == IO_Ok );
}


void K3bInfFileWriter::setTrack( const K3bDevice::Track& track )
{
  m_indices.clear();

  // the first index always has to be a zero (cdrecord manpage)
  m_indices.append( 0 );

  const TQValueVector<K3b::Msf>& indexList = track.indices();
  for( unsigned int i = 0; i < indexList.count(); ++i )
    m_indices.append( indexList[i].lba() );

  if( track.index0() > 0 )
    m_index0 = track.index0().lba();
  else
    m_index0 = -1;

  setPreEmphasis( track.preEmphasis() );
  setCopyPermitted( track.copyPermitted() );

  setTrackStart( track.firstSector() );
  setTrackLength( track.length() );

  setIsrc( track.isrc() );

  setBigEndian( true );
}


void K3bInfFileWriter::addIndex( long i )
{
  m_indices.append( i );
}


void K3bInfFileWriter::setTrackCdText( const K3bDevice::TrackCdText& cdtext )
{
  setTrackTitle( cdtext.title() );
  setTrackPerformer( cdtext.performer() );
  setTrackSongwriter( cdtext.songwriter() );
  setTrackComposer( cdtext.composer() );
  setTrackArranger( cdtext.arranger() );
  setTrackMessage( cdtext.message() );
}


void K3bInfFileWriter::setCdText( const K3bDevice::CdText& cdtext )
{
  setAlbumTitle( cdtext.title() );
  setAlbumPerformer( cdtext.performer() );
}