MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / Read

Method Read

Source/Sample.cpp:43–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43bool Sample::Read(const char* path, bool mono, ReadType readType)
44{
45 mReadPath = path;
46 ofStringReplace(mReadPath, GetPathSeparator(), "/");
47 std::vector<std::string> tokens = ofSplitString(mReadPath, "/");
48 mName = tokens[tokens.size() - 1];
49
50 juce::File file(ofToSamplePath(mReadPath));
51 delete mReader;
52 mReader = TheSynth->GetAudioFormatManager().createReaderFor(file);
53
54 if (mReader != nullptr)
55 {
56 mData.Resize((int)mReader->lengthInSamples);
57 if (mono)
58 mData.SetNumActiveChannels(1);
59 else
60 mData.SetNumActiveChannels(mReader->numChannels);
61 mData.Clear();
62
63 mNumSamples = (int)mReader->lengthInSamples;
64 mOffset = mNumSamples;
65 mOriginalSampleRate = mReader->sampleRate;
66 mSampleRateRatio = float(mOriginalSampleRate) / gSampleRate;
67
68 mReadBuffer = std::make_unique<juce::AudioSampleBuffer>();
69 mReadBuffer->setSize(mReader->numChannels, mNumSamples);
70
71 if (readType == ReadType::Sync)
72 {
73 mReader->read(mReadBuffer.get(), 0, mNumSamples, 0, true, true);
74 FinishRead();
75 }
76 else if (readType == ReadType::Async)
77 {
78 mSamplesLeftToRead = mNumSamples;
79 startTimer(100);
80 }
81
82 return true;
83 }
84 else
85 {
86 TheSynth->LogEvent("failed to load sample " + file.getFullPathName().toStdString(), kLogEventType_Error);
87 }
88
89 return false;
90}
91
92void Sample::FinishRead()
93{

Callers 15

FilesDroppedMethod · 0.45
FilesDroppedMethod · 0.45
FilesDroppedMethod · 0.45
LoadStateMethod · 0.45
FilesDroppedMethod · 0.45
LoadSampleMethod · 0.45
ButtonClickedMethod · 0.45
LoadKitMethod · 0.45
FilesDroppedMethod · 0.45
FloatSliderUpdatedMethod · 0.45
LoadSampleMethod · 0.45
FilesDroppedMethod · 0.45

Calls 9

ofStringReplaceFunction · 0.85
GetPathSeparatorFunction · 0.85
ofSplitStringFunction · 0.85
ofToSamplePathFunction · 0.85
sizeMethod · 0.80
SetNumActiveChannelsMethod · 0.80
LogEventMethod · 0.80
ResizeMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected