Canorus  0.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CAMidiImport Class Reference

#include <midiimport.h>

Inheritance diagram for CAMidiImport:
Inheritance graph
[legend]

Classes

struct  CATime
 

Public Member Functions

 CAMidiImport (QTextStream *in=0)
 
virtual ~CAMidiImport ()
 
void closeFile ()
 
CADocumentimportDocumentImpl ()
 
CASheetimportSheetImpl ()
 
const QString readableStatus ()
 
- Public Member Functions inherited from CAImport
 CAImport (QTextStream *stream=0)
 
 CAImport (const QString stream)
 
virtual ~CAImport ()
 
void importDocument ()
 
void importSheet ()
 
void importStaff ()
 
void importVoice ()
 
void importLyricsContext ()
 
void importFunctionMarkContext ()
 
CADocumentimportedDocument ()
 
CASheetimportedSheet ()
 
CAStaffimportedStaff ()
 
CAVoiceimportedVoice ()
 
CALyricsContextimportedLyricsContext ()
 
CAFunctionMarkContextimportedFunctionMarkContext ()
 
- Public Member Functions inherited from CAFile
 CAFile ()
 
virtual ~CAFile ()
 
const int status ()
 
const int progress ()
 
void setStreamFromFile (const QString filename)
 
void setStreamToFile (const QString filename)
 
void setStreamFromDevice (QIODevice *device)
 
void setStreamToDevice (QIODevice *device)
 

Private Types

enum  CALilyPondDepth { Score, Layout, Voice, Chord }
 
enum  smtpOffsComponents {
  hr, min, se, fr,
  ff, next
}
 

Private Member Functions

void initMidiImport ()
 
CAVoicecurVoice ()
 
void setCurVoice (CAVoice *voice)
 
const QString parseNextElement ()
 
const QString peekNextElement ()
 
void addError (QString description, int lineError=0, int charError=0)
 
CAPlayableLength playableLengthFromLilyPond (QString &playableElt, bool parse=false)
 
bool isNote (const QString elt)
 
CADiatonicPitch relativePitchFromLilyPond (QString &note, CADiatonicPitch prevPitch, bool parse=false)
 
bool isRest (const QString elt)
 
CARest::CARestType restTypeFromLilyPond (QString &rest, bool parse=false)
 
CAClef::CAPredefinedClefType predefinedClefTypeFromLilyPond (const QString clef)
 
int clefOffsetFromLilyPond (const QString clef)
 
CABarline::CABarlineType barlineTypeFromLilyPond (const QString bar)
 
CADiatonicKey::CAGender diatonicKeyGenderFromLilyPond (QString gender)
 
CATime timeSigFromLilyPond (QString time)
 
CAMusElementfindSharedElement (CAMusElement *elt)
 
QString & in ()
 
CALilyPondDepth curDepth ()
 
void pushDepth (CALilyPondDepth depth)
 
CALilyPondDepth popDepth ()
 
int curLine ()
 
int curChar ()
 
int getVariableLength (QByteArray *x)
 
QByteArray getHead (QByteArray *x)
 
int getByte (QByteArray *x)
 
int getWord16 (QByteArray *x)
 
int getWord24 (QByteArray *x)
 
int getWord32 (QByteArray *x)
 
QByteArray getString (QByteArray *x, int len)
 
void printQByteArray (QByteArray x)
 
void noteOn (bool on, int channel, int pitch, int velocity, int time)
 
void combineMidiFileEvents ()
 
void quantizeMidiFileEvents ()
 
void exportNonChordsToOtherVoices ()
 
void writeMidiFileEventsToScore (CASheet *sheet)
 
void writeMidiChannelEventsToVoice (int channel, CAStaff *staff, CAVoice *voice)
 

Private Attributes

CAVoice_curVoice
 
CASlur_curSlur
 
CASlur_curPhrasingSlur
 
QStack< CALilyPondDepth_depth
 
int _curLine
 
int _curChar
 
QList< QString > _errors
 
QList< QString > _warnings
 
int _dataIndex
 
int _nextTrackIndex
 
bool _parseError
 
int _smtpOffset [next]
 
int _microSecondsPerMidiQuarternote
 
CADocument_document
 
QVector< QList< QList
< CAMidiImportEvent * > * > * > 
_allChannelsEvents
 
QList< CAMidiImportEvent * > _eventsX
 

Static Private Attributes

static const QRegExp WHITESPACE_DELIMITERS = QRegExp("[\\s]")
 
static const QRegExp SYNTAX_DELIMITERS = QRegExp("[<>{}]")
 
static const QRegExp DELIMITERS
 

Additional Inherited Members

- Signals inherited from CAImport
void documentImported (CADocument *)
 
void sheetImported (CASheet *)
 
void staffImported (CAStaff *)
 
void voiceImported (CAVoice *)
 
void lyricsContextImported (CALyricsContext *)
 
void functionMarkContextImported (CAFunctionMarkContext *)
 
void importDone (int status)
 
- Protected Member Functions inherited from CAImport
virtual CAStaffimportStaffImpl ()
 
virtual CAVoiceimportVoiceImpl ()
 
virtual CALyricsContextimportLyricsContextImpl ()
 
virtual CAFunctionMarkContextimportFunctionMarkContextImpl ()
 
QTextStream & in ()
 

Member Enumeration Documentation

Enumerator
Score 
Layout 
Voice 
Chord 
Enumerator
hr 
min 
se 
fr 
ff 
next 

Constructor & Destructor Documentation

CAMidiImport::CAMidiImport ( QTextStream *  in = 0)

References _allChannelsEvents, and initMidiImport().

Here is the call graph for this function:

CAMidiImport::~CAMidiImport ( )
virtual

Member Function Documentation

void CAMidiImport::addError ( QString  description,
int  lineError = 0,
int  charError = 0 
)
private

References _curChar, _curLine, and _errors.

CABarline::CABarlineType CAMidiImport::barlineTypeFromLilyPond ( const QString  bar)
private

Genarates barline type from the LilyPond syntax for the given barline from format "barlineType".

References CABarline::Dotted, CABarline::Double, CABarline::End, CABarline::RepeatClose, CABarline::RepeatCloseOpen, CABarline::RepeatOpen, CABarline::Single, and CABarline::Undefined.

int CAMidiImport::clefOffsetFromLilyPond ( const QString  constClef)
private

Returns the Canorus octava or whichever interval above or below the clef.

void CAMidiImport::closeFile ( )

References CAFile::file().

Here is the call graph for this function:

void CAMidiImport::combineMidiFileEvents ( )
private

Combines the midi on/off events and reduces them to a note with a length. Note off events are, which can also be a note on with velocity zero, are thus eaten up and are invalidated by pitch -1.

todo: rounding fine grained note lenghts, dispersing small rests

todo: combine concurrent notes to chords or export concurrent notes to a next voice.

References _allChannelsEvents.

Referenced by importSheetImpl().

Here is the caller graph for this function:

int CAMidiImport::curChar ( )
inlineprivate

References _curChar.

Referenced by readableStatus().

Here is the caller graph for this function:

CALilyPondDepth CAMidiImport::curDepth ( )
inlineprivate

References _depth.

int CAMidiImport::curLine ( )
inlineprivate

References _curLine.

Referenced by readableStatus().

Here is the caller graph for this function:

CAVoice* CAMidiImport::curVoice ( )
inlineprivate

References _curVoice.

Referenced by findSharedElement().

Here is the caller graph for this function:

CADiatonicKey::CAGender CAMidiImport::diatonicKeyGenderFromLilyPond ( QString  gender)
private

Returns the key signature gender from format \genderType.

References CADiatonicKey::Major, and CADiatonicKey::Minor.

void CAMidiImport::exportNonChordsToOtherVoices ( )
private

If not a chord move overlapping notes to other voices.

The algorithm is this: For every note on event we look if there are follow up events that overlap. If there is a overlap the second note will be moved to a higher (index of the) voice, so high, where it can be stay without overlap.

References _allChannelsEvents, and next.

Referenced by importSheetImpl().

Here is the caller graph for this function:

CAMusElement * CAMidiImport::findSharedElement ( CAMusElement elt)
private

Gathers a list of music elements with the given element's start time and returns the first music element in the gathered list with the same attributes.

This method is usually called when voices have "shared" music elements (barlines, clefs etc.). However, in LilyPond syntax the music element can/should be present in all the voices. This function finds this shared music element, if it already exists.

If the music element with the same properties exists, user should delete its own instance and add an already existing instance of the returned shared music element to the voice.

See Also
CAMusElement::compare()

References CAVoice::contains(), curVoice(), CAStaff::getEltByType(), CAMusElement::musElementType(), CAVoice::staff(), and CAMusElement::timeStart().

Here is the call graph for this function:

int CAMidiImport::getByte ( QByteArray *  x)
private

References _dataIndex, and _parseError.

Referenced by getWord24(), and importSheetImpl().

Here is the caller graph for this function:

QByteArray CAMidiImport::getHead ( QByteArray *  x)
private

References _dataIndex, and _parseError.

Referenced by importSheetImpl().

Here is the caller graph for this function:

QByteArray CAMidiImport::getString ( QByteArray *  x,
int  len 
)
private

References _dataIndex, and _parseError.

Referenced by importSheetImpl().

Here is the caller graph for this function:

int CAMidiImport::getVariableLength ( QByteArray *  x)
private

References _dataIndex, _parseError, and next.

Referenced by importSheetImpl().

Here is the caller graph for this function:

int CAMidiImport::getWord16 ( QByteArray *  x)
private

References _dataIndex, and _parseError.

Referenced by getWord24(), getWord32(), and importSheetImpl().

Here is the caller graph for this function:

int CAMidiImport::getWord24 ( QByteArray *  x)
private

References getByte(), and getWord16().

Referenced by importSheetImpl().

Here is the call graph for this function:

Here is the caller graph for this function:

int CAMidiImport::getWord32 ( QByteArray *  x)
private

References getWord16().

Referenced by importSheetImpl().

Here is the call graph for this function:

Here is the caller graph for this function:

CADocument * CAMidiImport::importDocumentImpl ( )
virtual

Reimplemented from CAImport.

References _document, CADocument::addSheet(), and importSheetImpl().

Here is the call graph for this function:

CASheet * CAMidiImport::importSheetImpl ( )
virtual
QString& CAMidiImport::in ( )
inlineprivate

References CAFile::stream().

Referenced by parseNextElement(), and peekNextElement().

Here is the call graph for this function:

Here is the caller graph for this function:

void CAMidiImport::initMidiImport ( )
private

References _curChar, _curLine, _curPhrasingSlur, _curSlur, _document, and _microSecondsPerMidiQuarternote.

Referenced by CAMidiImport().

Here is the caller graph for this function:

bool CAMidiImport::isNote ( const QString  elt)
private

Returns true, if the given LilyPond element is a note.

See Also
isRest()
bool CAMidiImport::isRest ( const QString  elt)
private

Returns true, if the given LilyPond element is a rest.

See Also
isNote()
void CAMidiImport::noteOn ( bool  on,
int  channel,
int  pitch,
int  velocity,
int  time 
)
private

References _allChannelsEvents.

Referenced by importSheetImpl().

Here is the caller graph for this function:

const QString CAMidiImport::parseNextElement ( )
private

Returns the first element in input stream ended with one of the delimiters and shorten input stream for the element.

Todo:
Only one-character syntax delimiters are supported so far.
See Also
peekNextElement()

References DELIMITERS, and in().

Here is the call graph for this function:

const QString CAMidiImport::peekNextElement ( )
private

Returns the first element in input stream ended with one of the delimiters but don't shorten the stream.

See Also
parseNextElement()

References DELIMITERS, and in().

Here is the call graph for this function:

CAPlayableLength CAMidiImport::playableLengthFromLilyPond ( QString &  elt,
bool  parse = false 
)
private

Generates playable lentgth and number of dots from the note/rest string in LilyPond syntax. If the playable element doesn't include length, { CAPlayable::CAPlayableLength::Undefined, 0 } is returned. This function also shortens the given string for the playable length, if parse is True.

See Also
relativePitchFromString()

References CAPlayableLength::dotted(), CAPlayableLength::setDotted(), and CAPlayableLength::setMusicLength().

Here is the call graph for this function:

CALilyPondDepth CAMidiImport::popDepth ( )
inlineprivate

References _depth.

CAClef::CAPredefinedClefType CAMidiImport::predefinedClefTypeFromLilyPond ( const QString  constClef)
private

Genarates clef type from the LilyPond syntax for the given clef from format "clefType".

References CAClef::Alto, CAClef::Baritone, CAClef::Bass, CAClef::French, CAClef::Mezzosoprano, CAClef::Percussion, CAClef::Soprano, CAClef::Subbass, CAClef::Tablature, CAClef::Tenor, CAClef::Treble, and CAClef::Varbaritone.

void CAMidiImport::printQByteArray ( QByteArray  x)
private

Referenced by importSheetImpl().

Here is the caller graph for this function:

void CAMidiImport::pushDepth ( CALilyPondDepth  depth)
inlineprivate

References _depth.

void CAMidiImport::quantizeMidiFileEvents ( )
private

Quantisize the notes and rests, don't affect the duration of the music.

References _allChannelsEvents.

Referenced by importSheetImpl().

Here is the caller graph for this function:

const QString CAMidiImport::readableStatus ( )
virtual

Reimplemented from CAImport.

References curChar(), curLine(), and CAFile::status().

Here is the call graph for this function:

CADiatonicPitch CAMidiImport::relativePitchFromLilyPond ( QString &  constNName,
CADiatonicPitch  prevPitch,
bool  parse = false 
)
private

Generates the note pitch and number of accidentals from the note written in LilyPond syntax.

See Also
playableLengthFromLilyPond()

References CADiatonicPitch::noteName().

Here is the call graph for this function:

CARest::CARestType CAMidiImport::restTypeFromLilyPond ( QString &  elt,
bool  parse = false 
)
private

Genarates rest type from the LilyPond syntax for the given rest. This function also shortens the given string for the rest type, if parse is True.

References CARest::Hidden, and CARest::Normal.

void CAMidiImport::setCurVoice ( CAVoice voice)
inlineprivate

References _curVoice.

Referenced by writeMidiFileEventsToScore().

Here is the caller graph for this function:

CAMidiImport::CATime CAMidiImport::timeSigFromLilyPond ( QString  timeSig)
private

Returns the time signature beat and beats in beats/beat format.

void CAMidiImport::writeMidiChannelEventsToVoice ( int  channel,
CAStaff staff,
CAVoice voice 
)
private
void CAMidiImport::writeMidiFileEventsToScore ( CASheet sheet)
private

References _allChannelsEvents, CASheet::addContext(), CAStaff::addVoice(), setCurVoice(), CASheet::staffList(), CANote::StemNeutral, CAStaff::voiceList(), and writeMidiChannelEventsToVoice().

Referenced by importSheetImpl().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

QVector<QList<QList<CAMidiImportEvent*>*>*> CAMidiImport::_allChannelsEvents
private
int CAMidiImport::_curChar
private

Referenced by addError(), curChar(), and initMidiImport().

int CAMidiImport::_curLine
private

Referenced by addError(), curLine(), and initMidiImport().

CASlur* CAMidiImport::_curPhrasingSlur
private

Referenced by initMidiImport().

CASlur* CAMidiImport::_curSlur
private

Referenced by initMidiImport().

CAVoice* CAMidiImport::_curVoice
private

Referenced by curVoice(), and setCurVoice().

int CAMidiImport::_dataIndex
private
QStack<CALilyPondDepth> CAMidiImport::_depth
private

Referenced by curDepth(), popDepth(), and pushDepth().

CADocument* CAMidiImport::_document
private
QList<QString> CAMidiImport::_errors
private

Referenced by addError().

QList<CAMidiImportEvent*> CAMidiImport::_eventsX
private
int CAMidiImport::_microSecondsPerMidiQuarternote
private

Referenced by importSheetImpl(), and initMidiImport().

int CAMidiImport::_nextTrackIndex
private

Referenced by importSheetImpl().

bool CAMidiImport::_parseError
private
int CAMidiImport::_smtpOffset[next]
private

Referenced by importSheetImpl().

QList<QString> CAMidiImport::_warnings
private
const QRegExp CAMidiImport::DELIMITERS
staticprivate
Initial value:
=
QRegExp(
)

Combined WHITESPACE_DELIMITERS and SYNTAX_DELIMITERS.

Referenced by parseNextElement(), and peekNextElement().

const QRegExp CAMidiImport::SYNTAX_DELIMITERS = QRegExp("[<>{}]")
staticprivate

Delimiters which separate various music elements in LilyPond syntax, but are specific for LilyPond syntax. They are reported as its own element when parsing the next element.

See Also
nextElement(), parseNextElement()
const QRegExp CAMidiImport::WHITESPACE_DELIMITERS = QRegExp("[\\s]")
staticprivate

Delimiters which separate various music elements in LilyPond syntax. These are new lines, tabs, blanks etc.

See Also
nextElement(), parseNextElement()

The documentation for this class was generated from the following files: