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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
#include "cuesheeteditor.h"
#include <tqlayout.h>
#include <tqstring.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kpushbutton.h>
#include <kmessagebox.h>
//#include <ktextedit.h>
/*#include <kparts/factory.h> // KPart Factory
#include <klibloader.h> // LibLoader, contains factories
#include <kate/document.h> // Katepart document
#include <kate/view.h> // Katepart view
*/
// ### soundkonverter 0.4: import/export flac cuesheet
CuesheetEditor::CuesheetEditor( TQWidget *parent, const char *name, bool modal, WFlags f )
: KDialog( parent, name, modal, f )
{
// TODO can the cuesheet editor be extendet by more tags (composer), etc.
// create an icon loader object for loading icons
KIconLoader* iconLoader = new KIconLoader();
setCaption( i18n("Cuesheet Editor") );
resize( 600, 400 );
setIcon( iconLoader->loadIcon("kwrite",KIcon::Small) );
TQGridLayout *grid = new TQGridLayout( this, 4, 1, 11, 6 );
tTextEdit = new KTextEdit( this, "tTextEdit" );
tTextEdit->setFocus();
grid->addWidget( tTextEdit, 0, 0 );
/*
// Get KPart factory for the katepart library.
// This returns 0, if the library can not be found
KParts::Factory* factory = (KParts::Factory *)
KLibLoader::self()->factory ("libkatepart");
if (factory)
{
// The library was found, so create the Kate::Document
KTextEditor::Document *doc = (KTextEditor::Document *)
factory->createPart( 0, "", this, "", "KTextEditor::Document" );
// The document only represents the document, to view
// the document's content
// we have to create a view for the document.
Kate::View *view = (Kate::View *) doc->createView( this, 0L );
// all went well, so return the view
//return view;
grid->addWidget( view, 0, 0 );
}
else
{
// The library was not found
//return 0L;
}
*/
TQHBoxLayout *buttonBox = new TQHBoxLayout();
grid->addLayout( buttonBox, 3, 0 );
pHelp = new KPushButton( iconLoader->loadIcon("help",KIcon::Small), "", this, "pHelp" );
buttonBox->addWidget( pHelp );
connect( pHelp, TQT_SIGNAL(clicked()),
this, TQT_SLOT(help())
);
pGenerate = new KPushButton( iconLoader->loadIcon("filenew",KIcon::Small), i18n("Generate"), this, "pGenerate" );
buttonBox->addWidget( pGenerate );
connect( pGenerate, TQT_SIGNAL(clicked()),
this, TQT_SLOT(generate())
);
pConvert = new KPushButton( iconLoader->loadIcon("run",KIcon::Small), i18n("Format"), this, "pConvert" );
buttonBox->addWidget( pConvert );
connect( pConvert, TQT_SIGNAL(clicked()),
this, TQT_SLOT(convert())
);
pShift = new KPushButton( iconLoader->loadIcon("reload",KIcon::Small), i18n("Shift Title/Performer"), this, "pShift" );
buttonBox->addWidget( pShift );
connect( pShift, TQT_SIGNAL(clicked()),
this, TQT_SLOT(shift())
);
buttonBox->addStretch();
pOk = new KPushButton(iconLoader->loadIcon("exit",KIcon::Small), i18n("Close"), this, "pOk" );
pOk->setFocus();
buttonBox->addWidget( pOk );
connect( pOk, TQT_SIGNAL(clicked()),
this, TQT_SLOT(accept())
);
// delete the icon loader object
delete iconLoader;
}
CuesheetEditor::~CuesheetEditor()
{}
void CuesheetEditor::help()
{
KMessageBox::information( this,
i18n("<p>With this small tool you can process cue files as they are used for burning music mixes and for organizing them in media players like amaroK.<br><br>You can generate a new file by pasting text into the input area. It must be formated the following way:<br><br>Title - Artist [time]<br>Title - Artist [3:25]<br>Title - Artist [2:37]<br>...<br>A tip: Use kwrite and regular expressions to format it this way.</p>"),
i18n("Cuesheet Editor - Help") );
}
void CuesheetEditor::generate()
{
TQString text = tTextEdit->text();
TQString newText;
TQStringList titleList, performerList;
TQValueList<int> timeList;
TQString time;
int min, sec;
int index;
while( index != -1 )
{
index = text.find( " - " );
if( index == -1 )
break;
titleList.append( text.left(index) );
text.remove( 0, index + 3 );
index=text.find( " [" );
if( index == -1 )
break;
performerList.append( text.left(index) );
text.remove( 0, index + 2 );
index = text.find( "]" );
if( index == -1 )
break;
time = text.left( index );
sscanf( time, "%i:%i", &min, &sec );
timeList.append( min * 60 + sec );
text.remove( 0, index + 2 );
}
newText.append( "TITLE \"\"\n" );
newText.append( "PERFORMER \"\"\n" );
newText.append( "FILE \"\" MP3\n" );
int TRACK = 1;
int INDEX = 0;
bool addFrames = false;
TQStringList::Iterator performerIt = performerList.begin();
TQValueList<int>::Iterator timeIt = timeList.begin();
for( TQStringList::Iterator titleIt = titleList.begin(); titleIt != titleList.end(); ++titleIt )
{
newText.append( TQString().sprintf(" TRACK %02i AUDIO\n",TRACK ) );
newText.append( " TITLE \"" + (*titleIt) + "\"\n" );
newText.append( " PERFORMER \"" + (*performerIt) + "\"\n" );
if( addFrames ) {
newText.append( TQString().sprintf(" INDEX 01 %02i:%02i:37\n",INDEX/60,INDEX%60) );
INDEX++;
addFrames = false;
}
else {
newText.append( TQString().sprintf(" INDEX 01 %02i:%02i:00\n",INDEX/60,INDEX%60) );
addFrames = true;
}
performerIt++;
timeIt++;
TRACK++;
INDEX += (*timeIt);
}
tTextEdit->setText(newText);
}
void CuesheetEditor::convert()
{
TQString text=tTextEdit->text();
TQString newText;
TQString tmpText;
TQString first, rest;
TQStringList splinters;
int index;
while( index!=-1 )
{
index=text.find("\"");
if( index==-1 )
break;
newText+=text.left(index+1);
text.remove(0,index+1);
index=text.find("\"");
tmpText=text.left(index+1);
text.remove(0,index+1);
if( newText.right(6) == "FILE \"" )
{
newText+=tmpText;
continue;
}
splinters=TQStringList::split(' ',tmpText);
for( TQStringList::Iterator it=splinters.begin(); it!=splinters.end(); ++it )
{
for( uint i=0; i<(*it).length(); i++ )
{
if( (*it).left(i).lower() != (*it).left(i).upper() )
{
index=i;
break;
}
}
first=(*it).left(index);
first=first.upper();
rest=(*it).right((*it).length()-index);
rest=rest.lower();
for( uint i=0; i<rest.length(); i++ )
{
/*if( rest.mid(i,1).lower() == rest.mid(i,1).upper() )
{
rest=rest.left(i+1)+rest.mid(i+1,1).upper()+rest.right(rest.length()-i-2);
}*/
if( rest.mid(i,1) == "-" )
{
rest=rest.left(i+1)+rest.mid(i+1,1).upper()+rest.right(rest.length()-i-2);
}
if( rest.mid(i,1).lower() == "j" && rest.mid(i-1,1).lower() == "d" )
{
rest=rest.left(i-1)+rest.mid(i-1,2).upper()+rest.right(rest.length()-i-1);
}
if( rest.mid(i,1).lower() == "j" && first.right(1).lower() == "d" )
{
rest=rest.left(i)+rest.mid(i,1).upper()+rest.right(rest.length()-i-1);
}
}
newText += first + rest + " ";
}
newText.remove( newText.length() - 1, 1 );
}
newText += text;
tTextEdit->setText( newText );
}
void CuesheetEditor::shift() //move the title to "PERFORMER" and performer to "TITLE"
{
TQString text = tTextEdit->text();
TQString newText;
TQString line, title="", performer="";
int index;
while( index !=- 1 )
{
index = text.find("\n");
if( index == -1 )
break;
line = text.left(index+1);
text.remove(0,index+1);
// TODO clean up
if( line.find( "TITLE" ) != -1 ) {
line.replace( "TITLE", "PERFORMER" );
if( performer != "" ) newText += performer;
performer=line;
}
else if( line.find( "PERFORMER" ) != -1 ) {
line.replace( "PERFORMER", "TITLE" );
if( title != "" ) newText += title;
title = line;
}
else {
if( title != "" ) newText += title;
if( performer != "" ) newText += performer;
title = "";
performer = "";
newText += line;
}
if( title != "" && performer != "" ) {
newText += title;
newText += performer;
title = "";
performer = "";
}
}
tTextEdit->setText( newText );
}
/*
void CuesheetEditor::shift() //replace title by performer and reverse
{
TQString text=tTextEdit->text();
TQString newText;
TQString line, title, performer;
int index;
while( index!=-1 )
{
index=text.find("\n");
if( index==-1 )
break;
line=text.left(index+1);
text.remove(0,index+1);
if( line.find(" TITLE \"") != -1 ) {
line.replace(" TITLE \""," PERFORMER \"");
newText+=line;
}
else if( line.find(" PERFORMER \"") != -1 ) {
line.replace(" PERFORMER \""," TITLE \"");
newText+=line;
}
else {
newText+=line;
}
}
tTextEdit->setText(newText);
}
*/
|