-
Notifications
You must be signed in to change notification settings - Fork 0
/
regionwavesaver.cpp
109 lines (83 loc) · 2.76 KB
/
regionwavesaver.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
#include "regionwavesaver.h"
RegionWaveSaver::RegionWaveSaver(QString fileName)
{
file = new QFile(fileName);
markerList = new MarkerList;
regionList = new RegionList;
info = new WaveFileInfo;
dataChunk = NULL;
rootChunk = NULL;
}
RegionWaveSaver::~RegionWaveSaver(void){
delete markerList;
delete regionList;
delete rootChunk;
delete file;
}
Chunk* RegionWaveSaver::getRootChunk(){ return rootChunk; }
void RegionWaveSaver::addRegion(myDWORD position, myDWORD duration, QString name){
regionList->append(new Region(position, duration, name));
}
void RegionWaveSaver::addMarker(myDWORD position){
markerList->append(new Marker(position));
}
void RegionWaveSaver::addWaveData(ByteBuffer* bb){
if (!dataChunk) dataChunk = new Chunk("data", file);
dataChunk->addData(bb);
}
bool RegionWaveSaver::write(){
rootChunk = new Chunk("RIFF", file);
ChunkList* riffChildren = rootChunk->getChildren();
Chunk* fmt = new Chunk("fmt ", file);
fmt->addData(info->toByteBuffer());
qDebug() << rootChunk->isList() << (riffChildren==NULL);
riffChildren->append(fmt);
// Chunk* data = new Chunk("data", file);
// data->addToData(waveData->data(), waveData->size());
riffChildren->append(dataChunk);
Chunk* cue = new Chunk("cue ", file);
riffChildren->append(cue);
Chunk* list = new Chunk("LIST", file);
ChunkList* listChildren = list->getChildren();
riffChildren->append(list);
Region* r;
int freeID=1;
ChunkList lables;
foreach(r, *regionList){
myDWORD cueID = freeID++;
CuePoint cuePoint1(cueID, r->begin);
cue->addData(cuePoint1.toByteBuffer(cueID));
Chunk* ch = new Chunk("ltxt", file);
ch->addData(r->toLtxtChunkByteBuffer(cueID));
listChildren->append(ch);
ch = new Chunk("labl", file);
ch->addData(r->toLablChunkByteBuffer(cueID));
lables.append(ch);
}
*(listChildren) += lables;
Marker* m;
foreach(m, *markerList){
myDWORD cueID = freeID++;
CuePoint cuePoint1(cueID, m->position); // ñîçäàåò îáúåêò cue ýëêìåíòà
cue->addData(cuePoint1.toByteBuffer(cueID));
Chunk* ch = new Chunk("labl", file);
ch->addData(m->toLablChunkByteBuffer(cueID));
listChildren->append(ch);
}
// myDWORD cuePointCount = lables.size();
freeID--;
qDebug() << "freeID" << freeID;
cue->addForwardData(getByteBuffer((char*)&freeID, 4));
// âñòàâèòü cue Number
file->open(QIODevice::WriteOnly);
rootChunk->write();
file->close();
return true;
}
WaveFileInfo* RegionWaveSaver::getInfo(){
return info;
}
void RegionWaveSaver::setInfo(WaveFileInfo* info){
if (!this->info) delete info;
this->info = info;
}