Skip to content

Commit 06b2eb8

Browse files
Add MIDI source note editing methods
1 parent 72c4a67 commit 06b2eb8

File tree

8 files changed

+337
-0
lines changed

8 files changed

+337
-0
lines changed

src/audioCore/source/SourceInternalContainer.cpp

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,141 @@ bool SourceInternalContainer::isForked() const {
237237
return this->forked;
238238
}
239239

240+
int SourceInternalContainer::addNote(
241+
int track, double startTime, double endTime,
242+
uint8_t pitch, uint8_t vel, const juce::String& lyrics) {
243+
/** Check Type */
244+
if (this->type != SourceType::MIDI) { return -1; }
245+
246+
/** Init MIDI */
247+
if (!this->midiData) {
248+
this->initMidiData();
249+
}
250+
251+
/** Add Note */
252+
int result = this->midiData->addNote(
253+
track, startTime, endTime,
254+
pitch, vel, lyrics);
255+
256+
/** Set Flag */
257+
if (result >= 0) {
258+
this->changed();
259+
}
260+
261+
return result;
262+
}
263+
264+
int SourceInternalContainer::setNoteTime(
265+
int track, int index,
266+
double startTime, double endTime) {
267+
/** Check Type */
268+
if (this->type != SourceType::MIDI) { return -1; }
269+
270+
/** Init MIDI */
271+
if (!this->midiData) {
272+
this->initMidiData();
273+
}
274+
275+
/** Set Note Time */
276+
int result = this->midiData->setNoteTime(
277+
track, index, startTime, endTime);
278+
279+
/** Set Flag */
280+
if (result >= 0) {
281+
this->changed();
282+
}
283+
284+
return result;
285+
}
286+
287+
bool SourceInternalContainer::setNotePitch(
288+
int track, int index, uint8_t pitch) {
289+
/** Check Type */
290+
if (this->type != SourceType::MIDI) { return -1; }
291+
292+
/** Init MIDI */
293+
if (!this->midiData) {
294+
this->initMidiData();
295+
}
296+
297+
/** Set Note Pitch */
298+
bool result = this->midiData->setNotePitch(
299+
track, index, pitch);
300+
301+
/** Set Flag */
302+
if (result) {
303+
this->changed();
304+
}
305+
306+
return result;
307+
}
308+
309+
bool SourceInternalContainer::setNoteVelocity(
310+
int track, int index, uint8_t vel) {
311+
/** Check Type */
312+
if (this->type != SourceType::MIDI) { return -1; }
313+
314+
/** Init MIDI */
315+
if (!this->midiData) {
316+
this->initMidiData();
317+
}
318+
319+
/** Set Note Velocity */
320+
bool result = this->midiData->setNoteVelocity(
321+
track, index, vel);
322+
323+
/** Set Flag */
324+
if (result) {
325+
this->changed();
326+
}
327+
328+
return result;
329+
}
330+
331+
bool SourceInternalContainer::setNoteLyrics(
332+
int track, int index, const juce::String& lyrics) {
333+
/** Check Type */
334+
if (this->type != SourceType::MIDI) { return -1; }
335+
336+
/** Init MIDI */
337+
if (!this->midiData) {
338+
this->initMidiData();
339+
}
340+
341+
/** Set Note Lyrics */
342+
bool result = this->midiData->setNoteLyrics(
343+
track, index, lyrics);
344+
345+
/** Set Flag */
346+
if (result) {
347+
this->changed();
348+
}
349+
350+
return result;
351+
}
352+
353+
bool SourceInternalContainer::removeNote(
354+
int track, int index) {
355+
/** Check Type */
356+
if (this->type != SourceType::MIDI) { return -1; }
357+
358+
/** Init MIDI */
359+
if (!this->midiData) {
360+
this->initMidiData();
361+
}
362+
363+
/** Remove Note */
364+
bool result = this->midiData->removeNote(
365+
track, index);
366+
367+
/** Set Flag */
368+
if (result) {
369+
this->changed();
370+
}
371+
372+
return result;
373+
}
374+
240375
int SourceInternalContainer::getMIDITrackNum() const {
241376
if (!this->midiData) { return 0; }
242377
return this->midiData->getTrackNum();

src/audioCore/source/SourceInternalContainer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ class SourceInternalContainer {
5050

5151
bool isForked() const;
5252

53+
public:
54+
int addNote(int track, double startTime, double endTime,
55+
uint8_t pitch, uint8_t vel, const juce::String& lyrics = "");
56+
int setNoteTime(int track, int index,
57+
double startTime, double endTime);
58+
bool setNotePitch(int track, int index, uint8_t pitch);
59+
bool setNoteVelocity(int track, int index, uint8_t vel);
60+
bool setNoteLyrics(int track, int index, const juce::String& lyrics);
61+
bool removeNote(int track, int index);
62+
5363
public:
5464
int getMIDITrackNum() const;
5565
bool isMIDITrackEmpty(int track) const;

src/audioCore/source/SourceItem.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,81 @@ const SourceMIDITemp::Misc SourceItem::getMIDIMisc(int track, int index) const {
446446
return this->container->getMIDIMisc(track, index);
447447
}
448448

449+
int SourceItem::addNote(int track, double startTime, double endTime,
450+
uint8_t pitch, uint8_t vel, const juce::String& lyrics) {
451+
if (!this->container) { return -1; }
452+
453+
int result = this->container->addNote(
454+
track, startTime, endTime,
455+
pitch, vel, lyrics);
456+
457+
if (result >= 0) {
458+
this->invokeCallback();
459+
}
460+
return result;
461+
}
462+
463+
int SourceItem::setNoteTime(int track, int index,
464+
double startTime, double endTime) {
465+
if (!this->container) { return -1; }
466+
467+
int result = this->container->setNoteTime(
468+
track, index, startTime, endTime);
469+
470+
if (result >= 0) {
471+
this->invokeCallback();
472+
}
473+
return result;
474+
}
475+
476+
bool SourceItem::setNotePitch(int track, int index, uint8_t pitch) {
477+
if (!this->container) { return -1; }
478+
479+
bool result = this->container->setNotePitch(
480+
track, index, pitch);
481+
482+
if (result) {
483+
this->invokeCallback();
484+
}
485+
return result;
486+
}
487+
488+
bool SourceItem::setNoteVelocity(int track, int index, uint8_t vel) {
489+
if (!this->container) { return -1; }
490+
491+
bool result = this->container->setNoteVelocity(
492+
track, index, vel);
493+
494+
if (result) {
495+
this->invokeCallback();
496+
}
497+
return result;
498+
}
499+
500+
bool SourceItem::setNoteLyrics(int track, int index, const juce::String& lyrics) {
501+
if (!this->container) { return -1; }
502+
503+
bool result = this->container->setNoteLyrics(
504+
track, index, lyrics);
505+
506+
if (result) {
507+
this->invokeCallback();
508+
}
509+
return result;
510+
}
511+
512+
bool SourceItem::removeNote(int track, int index) {
513+
if (!this->container) { return -1; }
514+
515+
bool result = this->container->removeNote(
516+
track, index);
517+
518+
if (result) {
519+
this->invokeCallback();
520+
}
521+
return result;
522+
}
523+
449524
void SourceItem::updateAudioResampler() {
450525
/** Check Audio Data */
451526
if (!this->audioValid()) { return; }

src/audioCore/source/SourceItem.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ class SourceItem final {
8181
const SourceMIDITemp::Controller getMIDIController(int track, uint8_t number, int index) const;
8282
const SourceMIDITemp::Misc getMIDIMisc(int track, int index) const;
8383

84+
public:
85+
int addNote(int track, double startTime, double endTime,
86+
uint8_t pitch, uint8_t vel, const juce::String& lyrics = "");
87+
int setNoteTime(int track, int index,
88+
double startTime, double endTime);
89+
bool setNotePitch(int track, int index, uint8_t pitch);
90+
bool setNoteVelocity(int track, int index, uint8_t vel);
91+
bool setNoteLyrics(int track, int index, const juce::String& lyrics);
92+
bool removeNote(int track, int index);
93+
8494
private:
8595
const SourceType type;
8696
std::shared_ptr<SourceInternalContainer> container = nullptr;

src/audioCore/source/SourceMIDITemp.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,38 @@ void SourceMIDITemp::addMIDIMessages(
547547
this->updateIndexs(track);
548548
}
549549

550+
int SourceMIDITemp::addNote(int track, double startTime, double endTime,
551+
uint8_t pitch, uint8_t vel, const juce::String& lyrics) {
552+
/** TODO */
553+
return -1;
554+
}
555+
556+
int SourceMIDITemp::setNoteTime(int track, int index,
557+
double startTime, double endTime) {
558+
/** TODO */
559+
return -1;
560+
}
561+
562+
bool SourceMIDITemp::setNotePitch(int track, int index, uint8_t pitch) {
563+
/** TODO */
564+
return false;
565+
}
566+
567+
bool SourceMIDITemp::setNoteVelocity(int track, int index, uint8_t vel) {
568+
/** TODO */
569+
return false;
570+
}
571+
572+
bool SourceMIDITemp::setNoteLyrics(int track, int index, const juce::String& lyrics) {
573+
/** TODO */
574+
return false;
575+
}
576+
577+
bool SourceMIDITemp::removeNote(int track, int index) {
578+
/** TODO */
579+
return false;
580+
}
581+
550582
int SourceMIDITemp::binarySearchStart(
551583
const juce::OwnedArray<MIDIStruct>& eventsList, int low, int high, double time) {
552584

src/audioCore/source/SourceMIDITemp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ class SourceMIDITemp final {
8080
int track, const juce::MidiMessageSequence& list,
8181
NoteOnTemp& noteOnTemp, int& indexTemp, LyricsItem& lyricsTemp);
8282

83+
public:
84+
int addNote(int track, double startTime, double endTime,
85+
uint8_t pitch, uint8_t vel, const juce::String& lyrics = "");
86+
int setNoteTime(int track, int index,
87+
double startTime, double endTime);
88+
bool setNotePitch(int track, int index, uint8_t pitch);
89+
bool setNoteVelocity(int track, int index, uint8_t vel);
90+
bool setNoteLyrics(int track, int index, const juce::String& lyrics);
91+
bool removeNote(int track, int index);
92+
8393
private:
8494
juce::Array<juce::OwnedArray<MIDIStruct>> eventList;
8595
short timeFormat = 480;

src/audioCore/source/SourceManager.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,61 @@ const juce::Array<SourceMIDITemp::Misc> SourceManager::getMIDIMiscList(uint64_t
464464
return {};
465465
}
466466

467+
int SourceManager::addNote(uint64_t ref, int track, double startTime, double endTime,
468+
uint8_t pitch, uint8_t vel, const juce::String& lyrics) {
469+
juce::ScopedReadLock locker(audioLock::getSourceLock());
470+
if (auto ptr = this->getSourceFast(ref, SourceType::MIDI)) {
471+
return ptr->addNote(
472+
track, startTime, endTime, pitch, vel, lyrics);
473+
}
474+
return -1;
475+
}
476+
477+
int SourceManager::setNoteTime(uint64_t ref, int track, int index,
478+
double startTime, double endTime) {
479+
juce::ScopedReadLock locker(audioLock::getSourceLock());
480+
if (auto ptr = this->getSourceFast(ref, SourceType::MIDI)) {
481+
return ptr->setNoteTime(
482+
track, index, startTime, endTime);
483+
}
484+
return -1;
485+
}
486+
487+
bool SourceManager::setNotePitch(uint64_t ref, int track, int index, uint8_t pitch) {
488+
juce::ScopedReadLock locker(audioLock::getSourceLock());
489+
if (auto ptr = this->getSourceFast(ref, SourceType::MIDI)) {
490+
return ptr->setNotePitch(
491+
track, index, pitch);
492+
}
493+
return false;
494+
}
495+
496+
bool SourceManager::setNoteVelocity(uint64_t ref, int track, int index, uint8_t vel) {
497+
juce::ScopedReadLock locker(audioLock::getSourceLock());
498+
if (auto ptr = this->getSourceFast(ref, SourceType::MIDI)) {
499+
return ptr->setNoteVelocity(
500+
track, index, vel);
501+
}
502+
return false;
503+
}
504+
505+
bool SourceManager::setNoteLyrics(uint64_t ref, int track, int index, const juce::String& lyrics) {
506+
juce::ScopedReadLock locker(audioLock::getSourceLock());
507+
if (auto ptr = this->getSourceFast(ref, SourceType::MIDI)) {
508+
return ptr->setNoteLyrics(
509+
track, index, lyrics);
510+
}
511+
return false;
512+
}
513+
514+
bool SourceManager::removeNote(uint64_t ref, int track, int index) {
515+
juce::ScopedReadLock locker(audioLock::getSourceLock());
516+
if (auto ptr = this->getSourceFast(ref, SourceType::MIDI)) {
517+
return ptr->removeNote(track, index);
518+
}
519+
return false;
520+
}
521+
467522
void SourceManager::sampleRateChanged(double sampleRate, int blockSize) {
468523
juce::ScopedWriteLock locker(audioLock::getSourceLock());
469524

src/audioCore/source/SourceManager.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ class SourceManager final : private juce::DeletedAtShutdown {
7979
const juce::Array<SourceMIDITemp::Controller> getMIDIControllerList(uint64_t ref, int track, uint8_t number) const;
8080
const juce::Array<SourceMIDITemp::Misc> getMIDIMiscList(uint64_t ref, int track) const;
8181

82+
public:
83+
int addNote(uint64_t ref, int track, double startTime, double endTime,
84+
uint8_t pitch, uint8_t vel, const juce::String& lyrics = "");
85+
int setNoteTime(uint64_t ref, int track, int index,
86+
double startTime, double endTime);
87+
bool setNotePitch(uint64_t ref, int track, int index, uint8_t pitch);
88+
bool setNoteVelocity(uint64_t ref, int track, int index, uint8_t vel);
89+
bool setNoteLyrics(uint64_t ref, int track, int index, const juce::String& lyrics);
90+
bool removeNote(uint64_t ref, int track, int index);
91+
8292
public:
8393
void sampleRateChanged(double sampleRate, int blockSize);
8494

0 commit comments

Comments
 (0)