summaryrefslogtreecommitdiff
path: root/muse_qt4_evolution/muse/waveevent.cpp
blob: 4aff6a4712a450f1d1ea4d4a1a4476025c19ef74 (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
//=============================================================================
//  MusE
//  Linux Music Editor
//  $Id:$
//
//  Copyright (C) 2002-2006 by Werner Schweer and others
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2.
//
//  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; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================

#include "globals.h"
#include "event.h"
#include "waveevent.h"
#include "al/xml.h"
#include "wave.h"

//---------------------------------------------------------
//   WaveEvent
//---------------------------------------------------------

WaveEventBase::WaveEventBase(EventType t)
   : EventBase(t)
      {
      deleted = false;
      }

//---------------------------------------------------------
//   WaveEvent::mid
//---------------------------------------------------------

EventBase* WaveEventBase::mid(unsigned b, unsigned e)
      {
      WaveEventBase* ev = new WaveEventBase(*this);

      int offset   = b - frame();
      unsigned end = endFrame();
      if (e < end)
            end = e;

      int len = end - b;
      ev->setFrame(b);
      ev->setLenFrame(len);
      ev->setSpos(spos() + offset);
      return ev;
      }

//---------------------------------------------------------
//   dump
//---------------------------------------------------------

void WaveEventBase::dump(int n) const
      {
      EventBase::dump(n);
      }

//---------------------------------------------------------
//   WaveEventBase::read
//---------------------------------------------------------

void WaveEventBase::read(QDomNode node)
      {
      node = node.firstChild();
      while (!node.isNull()) {
            QDomElement e = node.toElement();
            if (e.tagName() == "poslen")
                  PosLen::read(node);
            else if (e.tagName() == "frame")
                  _spos = e.text().toInt();
            else if (e.tagName() == "file") {
                  SndFile* wf = SndFile::getWave(e.text(), false);
                  if (wf)
                        f = SndFileR(wf);
                  }
            else
                  printf("MusE:WaveEventBase: unknown tag %s\n", e.tagName().toLatin1().data());
            node = node.nextSibling();
            }
      Pos::setType(AL::FRAMES);
      }

//---------------------------------------------------------
//   write
//---------------------------------------------------------

void WaveEventBase::write(Xml& xml, const Pos& offset) const
      {
      if (f.isNull())
            return;
      xml.stag("event");
      PosLen wpos(*this);
      wpos += offset;
//      if (offset)
//            wpos.setTick(wpos.tick() + offset);
      wpos.write(xml, "poslen");
      xml.tag("frame", _spos);  // offset in wave file
      xml.tag("file", f.finfo()->fileName());
      xml.etag("event");
      }

//---------------------------------------------------------
//   read
//---------------------------------------------------------

void WaveEventBase::read(unsigned offset, float** buffer, int channel, int n)
      {
      if (f.isNull())
            return;
      f.seek(offset + _spos);
      f.read(channel, buffer, n);
      }

//---------------------------------------------------------
//   WaveEventBase::operator==
//---------------------------------------------------------

bool WaveEventBase::operator==(const EventBase& ev) const {

  const WaveEventBase* pev = dynamic_cast<const WaveEventBase*>(&ev);

  if(pev) return operator==(*pev);
  else return false;
}

bool WaveEventBase::operator==(const WaveEventBase& /*ev*/) const {
  //TODO
  return false;
}