-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathDataFile.cpp
1544 lines (1367 loc) · 37.8 KB
/
DataFile.cpp
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* DataFile.cpp - implementation of class DataFile
*
* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2012-2013 Paul Giblock <p/at/pgiblock.net>
*
* This file is part of LMMS - https://lmms.io
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "DataFile.h"
#include <math.h>
#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include <QMessageBox>
#include "base64.h"
#include "ConfigManager.h"
#include "Effect.h"
#include "embed.h"
#include "GuiApplication.h"
#include "LocaleHelper.h"
#include "PluginFactory.h"
#include "ProjectVersion.h"
#include "SongEditor.h"
#include "TextFloat.h"
#include "lmmsversion.h"
static void findIds(const QDomElement& elem, QList<jo_id_t>& idList);
DataFile::typeDescStruct
DataFile::s_types[DataFile::TypeCount] =
{
{ DataFile::UnknownType, "unknown" },
{ DataFile::SongProject, "song" },
{ DataFile::SongProjectTemplate, "songtemplate" },
{ DataFile::InstrumentTrackSettings, "instrumenttracksettings" },
{ DataFile::DragNDropData, "dnddata" },
{ DataFile::ClipboardData, "clipboard-data" },
{ DataFile::JournalData, "journaldata" },
{ DataFile::EffectSettings, "effectsettings" }
} ;
DataFile::DataFile( Type type ) :
QDomDocument( "lmms-project" ),
m_content(),
m_head(),
m_type( type )
{
appendChild( createProcessingInstruction("xml", "version=\"1.0\""));
QDomElement root = createElement( "lmms-project" );
root.setAttribute( "version", LDF_VERSION_STRING );
root.setAttribute( "type", typeName( type ) );
root.setAttribute( "creator", "LMMS" );
root.setAttribute( "creatorversion", LMMS_VERSION );
appendChild( root );
m_head = createElement( "head" );
root.appendChild( m_head );
m_content = createElement( typeName( type ) );
root.appendChild( m_content );
}
DataFile::DataFile( const QString & _fileName ) :
QDomDocument(),
m_content(),
m_head()
{
QFile inFile( _fileName );
if( !inFile.open( QIODevice::ReadOnly ) )
{
if( gui )
{
QMessageBox::critical( NULL,
SongEditor::tr( "Could not open file" ),
SongEditor::tr( "Could not open file %1. You probably "
"have no permissions to read this "
"file.\n Please make sure to have at "
"least read permissions to the file "
"and try again." ).arg( _fileName ) );
}
return;
}
loadData( inFile.readAll(), _fileName );
}
DataFile::DataFile( const QByteArray & _data ) :
QDomDocument(),
m_content(),
m_head()
{
loadData( _data, "<internal data>" );
}
DataFile::~DataFile()
{
}
bool DataFile::validate( QString extension )
{
switch( m_type )
{
case Type::SongProject:
if( extension == "mmp" || extension == "mmpz" )
{
return true;
}
break;
case Type::SongProjectTemplate:
if( extension == "mpt" )
{
return true;
}
break;
case Type::InstrumentTrackSettings:
if ( extension == "xpf" || extension == "xml" )
{
return true;
}
break;
case Type::UnknownType:
if (! ( extension == "mmp" || extension == "mpt" || extension == "mmpz" ||
extension == "xpf" || extension == "xml" ||
( extension == "xiz" && ! pluginFactory->pluginSupportingExtension(extension).isNull()) ||
extension == "sf2" || extension == "sf3" || extension == "pat" || extension == "mid" ||
extension == "dll"
#ifdef LMMS_HAVE_LV2
|| extension == "lv2"
#endif
) )
{
return true;
}
if( extension == "wav" || extension == "ogg" ||
extension == "ds" )
{
return true;
}
break;
default:
return false;
}
return false;
}
QString DataFile::nameWithExtension( const QString & _fn ) const
{
switch( type() )
{
case SongProject:
if( _fn.section( '.', -1 ) != "mmp" &&
_fn.section( '.', -1 ) != "mpt" &&
_fn.section( '.', -1 ) != "mmpz" )
{
if( ConfigManager::inst()->value( "app",
"nommpz" ).toInt() == 0 )
{
return _fn + ".mmpz";
}
return _fn + ".mmp";
}
break;
case SongProjectTemplate:
if( _fn.section( '.',-1 ) != "mpt" )
{
return _fn + ".mpt";
}
break;
case InstrumentTrackSettings:
if( _fn.section( '.', -1 ) != "xpf" )
{
return _fn + ".xpf";
}
break;
default: ;
}
return _fn;
}
void DataFile::write( QTextStream & _strm )
{
if( type() == SongProject || type() == SongProjectTemplate
|| type() == InstrumentTrackSettings )
{
cleanMetaNodes( documentElement() );
}
save(_strm, 2);
}
bool DataFile::writeFile( const QString& filename )
{
const QString fullName = nameWithExtension( filename );
const QString fullNameTemp = fullName + ".new";
const QString fullNameBak = fullName + ".bak";
QFile outfile( fullNameTemp );
if( !outfile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
if( gui )
{
QMessageBox::critical( NULL,
SongEditor::tr( "Could not write file" ),
SongEditor::tr( "Could not open %1 for writing. You probably are not permitted to "
"write to this file. Please make sure you have write-access to "
"the file and try again." ).arg( fullName ) );
}
return false;
}
if( fullName.section( '.', -1 ) == "mmpz" )
{
QString xml;
QTextStream ts( &xml );
write( ts );
outfile.write( qCompress( xml.toUtf8() ) );
}
else
{
QTextStream ts( &outfile );
write( ts );
}
outfile.close();
// make sure the file has been written correctly
if( QFileInfo( outfile.fileName() ).size() > 0 )
{
if( ConfigManager::inst()->value( "app", "disablebackup" ).toInt() )
{
// remove current file
QFile::remove( fullName );
}
else
{
// remove old backup file
QFile::remove( fullNameBak );
// move current file to backup file
QFile::rename( fullName, fullNameBak );
}
// move temporary file to current file
QFile::rename( fullNameTemp, fullName );
return true;
}
return false;
}
DataFile::Type DataFile::type( const QString& typeName )
{
for( int i = 0; i < TypeCount; ++i )
{
if( s_types[i].m_name == typeName )
{
return static_cast<DataFile::Type>( i );
}
}
// compat code
if( typeName == "channelsettings" )
{
return DataFile::InstrumentTrackSettings;
}
return UnknownType;
}
QString DataFile::typeName( Type type )
{
if( type >= UnknownType && type < TypeCount )
{
return s_types[type].m_name;
}
return s_types[UnknownType].m_name;
}
void DataFile::cleanMetaNodes( QDomElement _de )
{
QDomNode node = _de.firstChild();
while( !node.isNull() )
{
if( node.isElement() )
{
if( node.toElement().attribute( "metadata" ).toInt() )
{
QDomNode ns = node.nextSibling();
_de.removeChild( node );
node = ns;
continue;
}
if( node.hasChildNodes() )
{
cleanMetaNodes( node.toElement() );
}
}
node = node.nextSibling();
}
}
void DataFile::upgrade_0_2_1_20070501()
{
// Upgrade to version 0.2.1-20070501
QDomNodeList list = elementsByTagName( "arpandchords" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
if( el.hasAttribute( "arpdir" ) )
{
int arpdir = el.attribute( "arpdir" ).toInt();
if( arpdir > 0 )
{
el.setAttribute( "arpdir", arpdir - 1 );
}
else
{
el.setAttribute( "arpdisabled", "1" );
}
}
}
list = elementsByTagName( "sampletrack" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
if( el.attribute( "vol" ) != "" )
{
el.setAttribute( "vol", LocaleHelper::toFloat(
el.attribute( "vol" ) ) * 100.0f );
}
else
{
QDomNode node = el.namedItem(
"automation-pattern" );
if( !node.isElement() ||
!node.namedItem( "vol" ).isElement() )
{
el.setAttribute( "vol", 100.0f );
}
}
}
list = elementsByTagName( "ladspacontrols" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
QDomNode anode = el.namedItem( "automation-pattern" );
QDomNode node = anode.firstChild();
while( !node.isNull() )
{
if( node.isElement() )
{
QString name = node.nodeName();
if( name.endsWith( "link" ) )
{
el.setAttribute( name,
node.namedItem( "time" )
.toElement()
.attribute( "value" ) );
QDomNode oldNode = node;
node = node.nextSibling();
anode.removeChild( oldNode );
continue;
}
}
node = node.nextSibling();
}
}
QDomNode node = m_head.firstChild();
while( !node.isNull() )
{
if( node.isElement() )
{
if( node.nodeName() == "bpm" )
{
int value = node.toElement().attribute(
"value" ).toInt();
if( value > 0 )
{
m_head.setAttribute( "bpm",
value );
QDomNode oldNode = node;
node = node.nextSibling();
m_head.removeChild( oldNode );
continue;
}
}
else if( node.nodeName() == "mastervol" )
{
int value = node.toElement().attribute(
"value" ).toInt();
if( value > 0 )
{
m_head.setAttribute(
"mastervol", value );
QDomNode oldNode = node;
node = node.nextSibling();
m_head.removeChild( oldNode );
continue;
}
}
else if( node.nodeName() == "masterpitch" )
{
m_head.setAttribute( "masterpitch",
-node.toElement().attribute(
"value" ).toInt() );
QDomNode oldNode = node;
node = node.nextSibling();
m_head.removeChild( oldNode );
continue;
}
}
node = node.nextSibling();
}
}
void DataFile::upgrade_0_2_1_20070508()
{
// Upgrade to version 0.2.1-20070508 from some version greater than or equal to 0.2.1-20070501
QDomNodeList list = elementsByTagName( "arpandchords" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
if( el.hasAttribute( "chorddisabled" ) )
{
el.setAttribute( "chord-enabled",
!el.attribute( "chorddisabled" )
.toInt() );
el.setAttribute( "arp-enabled",
!el.attribute( "arpdisabled" )
.toInt() );
}
else if( !el.hasAttribute( "chord-enabled" ) )
{
el.setAttribute( "chord-enabled", true );
el.setAttribute( "arp-enabled",
el.attribute( "arpdir" ).toInt() != 0 );
}
}
while( !( list = elementsByTagName( "channeltrack" ) ).isEmpty() )
{
QDomElement el = list.item( 0 ).toElement();
el.setTagName( "instrumenttrack" );
}
list = elementsByTagName( "instrumenttrack" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
if( el.hasAttribute( "vol" ) )
{
float value = LocaleHelper::toFloat( el.attribute( "vol" ) );
value = roundf( value * 0.585786438f );
el.setAttribute( "vol", value );
}
else
{
QDomNodeList vol_list = el.namedItem(
"automation-pattern" )
.namedItem( "vol" ).toElement()
.elementsByTagName( "time" );
for( int j = 0; !vol_list.item( j ).isNull();
++j )
{
QDomElement timeEl = list.item( j )
.toElement();
int value = timeEl.attribute( "value" )
.toInt();
value = (int)roundf( value *
0.585786438f );
timeEl.setAttribute( "value", value );
}
}
}
}
void DataFile::upgrade_0_3_0_rc2()
{
// Upgrade to version 0.3.0-rc2 from some version greater than or equal to 0.2.1-20070508
QDomNodeList list = elementsByTagName( "arpandchords" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
if( el.attribute( "arpdir" ).toInt() > 0 )
{
el.setAttribute( "arpdir",
el.attribute( "arpdir" ).toInt() - 1 );
}
}
}
void DataFile::upgrade_0_3_0()
{
// Upgrade to version 0.3.0 (final) from some version greater than or equal to 0.3.0-rc2
QDomNodeList list;
while( !( list = elementsByTagName(
"pluckedstringsynth" ) ).isEmpty() )
{
QDomElement el = list.item( 0 ).toElement();
el.setTagName( "vibedstrings" );
el.setAttribute( "active0", 1 );
}
while( !( list = elementsByTagName( "lb303" ) ).isEmpty() )
{
QDomElement el = list.item( 0 ).toElement();
el.setTagName( "lb302" );
}
while( !( list = elementsByTagName( "channelsettings" ) ).
isEmpty() )
{
QDomElement el = list.item( 0 ).toElement();
el.setTagName( "instrumenttracksettings" );
}
}
void DataFile::upgrade_0_4_0_20080104()
{
// Upgrade to version 0.4.0-20080104 from some version greater than or equal to 0.3.0 (final)
QDomNodeList list = elementsByTagName( "fx" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
if( el.hasAttribute( "fxdisabled" ) &&
el.attribute( "fxdisabled" ).toInt() == 0 )
{
el.setAttribute( "enabled", 1 );
}
}
}
void DataFile::upgrade_0_4_0_20080118()
{
// Upgrade to version 0.4.0-20080118 from some version greater than or equal to 0.4.0-20080104
QDomNodeList list;
while( !( list = elementsByTagName( "fx" ) ).isEmpty() )
{
QDomElement fxchain = list.item( 0 ).toElement();
fxchain.setTagName( "fxchain" );
QDomNode rack = list.item( 0 ).firstChild();
QDomNodeList effects = rack.childNodes();
// move items one level up
while( effects.count() )
{
fxchain.appendChild( effects.at( 0 ) );
}
fxchain.setAttribute( "numofeffects",
rack.toElement().attribute( "numofeffects" ) );
fxchain.removeChild( rack );
}
}
void DataFile::upgrade_0_4_0_20080129()
{
// Upgrade to version 0.4.0-20080129 from some version greater than or equal to 0.4.0-20080118
QDomNodeList list;
while( !( list =
elementsByTagName( "arpandchords" ) ).isEmpty() )
{
QDomElement aac = list.item( 0 ).toElement();
aac.setTagName( "arpeggiator" );
QDomNode cloned = aac.cloneNode();
cloned.toElement().setTagName( "chordcreator" );
aac.parentNode().appendChild( cloned );
}
}
void DataFile::upgrade_0_4_0_20080409()
{
// Upgrade to version 0.4.0-20080409 from some version greater than or equal to 0.4.0-20080129
QStringList s;
s << "note" << "pattern" << "bbtco" << "sampletco" << "time";
for( QStringList::iterator it = s.begin(); it < s.end(); ++it )
{
QDomNodeList list = elementsByTagName( *it );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
el.setAttribute( "pos",
el.attribute( "pos" ).toInt()*3 );
el.setAttribute( "len",
el.attribute( "len" ).toInt()*3 );
}
}
QDomNodeList list = elementsByTagName( "timeline" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
el.setAttribute( "lp0pos",
el.attribute( "lp0pos" ).toInt()*3 );
el.setAttribute( "lp1pos",
el.attribute( "lp1pos" ).toInt()*3 );
}
}
void DataFile::upgrade_0_4_0_20080607()
{
// Upgrade to version 0.4.0-20080607 from some version greater than or equal to 0.3.0-20080409
QDomNodeList list;
while( !( list = elementsByTagName( "midi" ) ).isEmpty() )
{
QDomElement el = list.item( 0 ).toElement();
el.setTagName( "midiport" );
}
}
void DataFile::upgrade_0_4_0_20080622()
{
// Upgrade to version 0.4.0-20080622 from some version greater than or equal to 0.3.0-20080607
QDomNodeList list;
while( !( list = elementsByTagName(
"automation-pattern" ) ).isEmpty() )
{
QDomElement el = list.item( 0 ).toElement();
el.setTagName( "automationpattern" );
}
list = elementsByTagName( "bbtrack" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
QString s = el.attribute( "name" );
s.replace( QRegExp( "^Beat/Baseline " ),
"Beat/Bassline " );
el.setAttribute( "name", s );
}
}
void DataFile::upgrade_0_4_0_beta1()
{
// Upgrade to version 0.4.0-beta1 from some version greater than or equal to 0.4.0-20080622
// convert binary effect-key-blobs to XML
QDomNodeList list;
list = elementsByTagName( "effect" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
QString k = el.attribute( "key" );
if( !k.isEmpty() )
{
const QList<QVariant> l =
base64::decode( k, QVariant::List ).toList();
if( !l.isEmpty() )
{
QString name = l[0].toString();
QVariant u = l[1];
EffectKey::AttributeMap m;
// VST-effect?
if( u.type() == QVariant::String )
{
m["file"] = u.toString();
}
// LADSPA-effect?
else if( u.type() == QVariant::StringList )
{
const QStringList sl = u.toStringList();
m["plugin"] = sl.value( 0 );
m["file"] = sl.value( 1 );
}
EffectKey key( NULL, name, m );
el.appendChild( key.saveXML( *this ) );
}
}
}
}
void DataFile::upgrade_0_4_0_rc2()
{
// Upgrade to version 0.4.0-rc2 from some version greater than or equal to 0.4.0-beta1
QDomNodeList list = elementsByTagName( "audiofileprocessor" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
QString s = el.attribute( "src" );
s.replace( "drumsynth/misc ", "drumsynth/misc_" );
s.replace( "drumsynth/r&b", "drumsynth/r_n_b" );
s.replace( "drumsynth/r_b", "drumsynth/r_n_b" );
el.setAttribute( "src", s );
}
list = elementsByTagName( "lb302" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
int s = el.attribute( "shape" ).toInt();
if( s >= 1 )
{
s--;
}
el.setAttribute( "shape", QString("%1").arg(s) );
}
}
void DataFile::upgrade_1_0_99()
{
jo_id_t last_assigned_id = 0;
QList<jo_id_t> idList;
findIds(documentElement(), idList);
QDomNodeList list = elementsByTagName("ladspacontrols");
for(int i = 0; !list.item(i).isNull(); ++i)
{
for(QDomNode node = list.item(i).firstChild(); !node.isNull();
node = node.nextSibling())
{
QDomElement el = node.toElement();
QDomNode data_child = el.namedItem("data");
if(!data_child.isElement())
{
if (el.attribute("scale_type") == "log")
{
QDomElement me = createElement("data");
me.setAttribute("value", el.attribute("data"));
me.setAttribute("scale_type", "log");
jo_id_t id;
for(id = last_assigned_id + 1;
idList.contains(id); id++)
{
}
last_assigned_id = id;
idList.append(id);
me.setAttribute("id", id);
el.appendChild(me);
}
}
}
}
}
void DataFile::upgrade_1_1_0()
{
QDomNodeList list = elementsByTagName("fxchannel");
for (int i = 1; !list.item(i).isNull(); ++i)
{
QDomElement el = list.item(i).toElement();
QDomElement send = createElement("send");
send.setAttribute("channel", "0");
send.setAttribute("amount", "1");
el.appendChild(send);
}
}
void DataFile::upgrade_1_1_91()
{
// Upgrade to version 1.1.91 from some version less than 1.1.91
QDomNodeList list = elementsByTagName( "audiofileprocessor" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
QString s = el.attribute( "src" );
s.replace( QRegExp("/samples/bassloopes/"), "/samples/bassloops/" );
el.setAttribute( "src", s );
}
list = elementsByTagName( "attribute" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
if( el.attribute( "name" ) == "plugin" && el.attribute( "value" ) == "vocoder-lmms" ) {
el.setAttribute( "value", "vocoder" );
}
}
list = elementsByTagName( "crossoevereqcontrols" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
// invert the mute LEDs
for( int j = 1; j <= 4; ++j ){
QString a = QString( "mute%1" ).arg( j );
el.setAttribute( a, ( el.attribute( a ) == "0" ) ? "1" : "0" );
}
}
list = elementsByTagName( "arpeggiator" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
QDomElement el = list.item( i ).toElement();
// Swap elements ArpDirRandom and ArpDirDownAndUp
if( el.attribute( "arpdir" ) == "3" )
{
el.setAttribute( "arpdir", "4" );
}
else if( el.attribute( "arpdir" ) == "4" )
{
el.setAttribute( "arpdir", "3" );
}
}
}
void DataFile::upgrade_1_2_0_rc3()
{
// Upgrade from earlier bbtrack beat note behaviour of adding
// steps if a note is placed after the last step.
QDomNodeList bbtracks = elementsByTagName( "bbtrack" );
for( int i = 0; !bbtracks.item( i ).isNull(); ++i )
{
QDomNodeList patterns = bbtracks.item( i
).toElement().elementsByTagName(
"pattern" );
for( int j = 0; !patterns.item( j ).isNull(); ++j )
{
int patternLength, steps;
QDomElement el = patterns.item( j ).toElement();
if( el.attribute( "len" ) != "" )
{
patternLength = el.attribute( "len" ).toInt();
steps = patternLength / 12;
el.setAttribute( "steps", steps );
}
}
}
}
static void upgradeElement_1_2_0_rc2_42( QDomElement & el )
{
if( el.hasAttribute( "syncmode" ) )
{
int syncmode = el.attribute( "syncmode" ).toInt();
QStringList names;
QDomNamedNodeMap atts = el.attributes();
for( uint i = 0; i < atts.length(); i++ )
{
QString name = atts.item( i ).nodeName();
if( name.endsWith( "_numerator" ) )
{
names << name.remove( "_numerator" )
+ "_syncmode";
}
}
for( QStringList::iterator it = names.begin(); it < names.end();
++it )
{
el.setAttribute( *it, syncmode );
}
}
QDomElement child = el.firstChildElement();
while ( !child.isNull() )
{
upgradeElement_1_2_0_rc2_42( child );
child = child.nextSiblingElement();
}
}
void DataFile::upgrade_1_2_0_rc2_42()
{
QDomElement el = firstChildElement();
while ( !el.isNull() )
{
upgradeElement_1_2_0_rc2_42( el );
el = el.nextSiblingElement();
}
}
/**
* Helper function to call a functor for all effect ports' DomElements,
* providing the functor with lists to add and remove DomElements. Helpful for
* patching port values from savefiles.
*/
template<class Ftor>
void iterate_ladspa_ports(QDomElement& effect, Ftor& ftor)
{
// Head back up the DOM to upgrade ports
QDomNodeList ladspacontrols = effect.elementsByTagName( "ladspacontrols" );
for( int m = 0; !ladspacontrols.item( m ).isNull(); ++m )
{
QList<QDomElement> addList, removeList;
QDomElement ladspacontrol = ladspacontrols.item( m ).toElement();
for( QDomElement port = ladspacontrol.firstChild().toElement();
!port.isNull(); port = port.nextSibling().toElement() )
{
QStringList parts = port.tagName().split("port");
// Not a "port"
if ( parts.size() < 2 )
{
continue;
}
int num = parts[1].toInt();
// From Qt's docs of QDomNode:
// * copying a QDomNode is OK, they still have the same
// pointer to the "internal" QDomNodePrivate.
// * Also, they are using linked lists, which means
// deleting or appending QDomNode does not invalidate
// any other pointers.
// => Inside ftor, you can (and should) push back the
// QDomElements by value, not references
// => The loops below for adding and removing don't
// invalidate any other QDomElements
ftor(port, num, addList, removeList);
}
// Add ports marked for adding
for ( QDomElement e : addList )
{
ladspacontrol.appendChild( e );
}
// Remove ports marked for removal
for ( QDomElement e : removeList )
{
ladspacontrol.removeChild( e );
}
}
}
// helper function if you need to print a QDomNode
QDebug operator<<(QDebug dbg, const QDomNode& node)
{
QString s;
QTextStream str(&s, QIODevice::WriteOnly);
node.save(str, 2);