diff --git a/src/mediaComp/__init__.pyi b/src/mediaComp/__init__.pyi index c1a33ab..af40906 100644 --- a/src/mediaComp/__init__.pyi +++ b/src/mediaComp/__init__.pyi @@ -65,7 +65,7 @@ def writeFramesToDirectory(movie: "Movie", directory: str = ...) -> None: ... def samplesToSound(samples: any) -> "Sound": ... def makeSound(filename: str) -> "Sound": ... def makeEmptySound(numSamples: int, samplingRate: int = ..., filename: str = ...) -> "Sound": ... -def makeEmptySoundBySeconds(seconds: int, samplingRate: int) -> "Sound": ... +def makeEmptySoundBySeconds(seconds: int, samplingRate: int = ...) -> "Sound": ... def duplicateSound(sound: "Sound") -> "Sound": ... def getSamples(sound: "Sound") -> "Samples": ... def soundTool(sound: "Sound") -> None: ... diff --git a/src/mediaComp/core/image.py b/src/mediaComp/core/image.py index f124d48..e6a6079 100644 --- a/src/mediaComp/core/image.py +++ b/src/mediaComp/core/image.py @@ -178,7 +178,7 @@ def getPixelAt(picture, x, y) -> Pixel: print("getPixelAt(picture,x,y): y (= {}) is less than {} or bigger than the height (= {})".format(y, Picture._PictureIndexOffset, getHeight(picture) - 1 + Picture._PictureIndexOffset)) raise ValueError - return picture.getPixel(x - Picture._PictureIndexOffset, y - Picture._PictureIndexOffset) + return picture.getPixelAt(x - Picture._PictureIndexOffset, y - Picture._PictureIndexOffset) def setRed(pixel, value) -> None: diff --git a/src/mediaComp/core/sound.py b/src/mediaComp/core/sound.py index 4c8ade3..77d94d9 100644 --- a/src/mediaComp/core/sound.py +++ b/src/mediaComp/core/sound.py @@ -143,7 +143,7 @@ def setSampleValueAt(sound, index, value) -> None: if index > getNumSamples(sound) - 1 + Sound._SoundIndexOffset: print("You are trying to access the sample at index: " + str(index) + ", but the last valid index is at " + str(getNumSamples(sound) - 1 + Sound._SoundIndexOffset)) raise ValueError - sound.setSampleValue(index - Sound._SoundIndexOffset, int(value)) + sound.setSampleValueAt(index - Sound._SoundIndexOffset, int(value)) def getSampleValueAt(sound, index) -> int: @@ -156,7 +156,7 @@ def getSampleValueAt(sound, index) -> int: if index > getNumSamples(sound) - 1 + Sound._SoundIndexOffset: print("You are trying to access the sample at index: " + str(index) + ", but the last valid index is at " + str(getNumSamples(sound) - 1 + Sound._SoundIndexOffset)) raise ValueError - return sound.getSampleValue(index - Sound._SoundIndexOffset) + return sound.getSampleValueAt(index - Sound._SoundIndexOffset) def setSampleValue(sample, value) -> None: diff --git a/src/mediaComp/models/Picture.py b/src/mediaComp/models/Picture.py index 00f760b..bda7540 100644 --- a/src/mediaComp/models/Picture.py +++ b/src/mediaComp/models/Picture.py @@ -220,7 +220,7 @@ def setBasicPixel(self, x, y, rgb): col = Color(rgb[0], rgb[1], rgb[2]) self.getPixel(x,y).setColor(col) - def getPixel(self, x, y): + def getPixelAt(self, x, y): """Return the pixel at specified coordinates Parameters diff --git a/src/mediaComp/models/Sound.py b/src/mediaComp/models/Sound.py index f9b141b..805af7d 100644 --- a/src/mediaComp/models/Sound.py +++ b/src/mediaComp/models/Sound.py @@ -254,26 +254,8 @@ def getSamples(self): samples.append(SoundSample(self, i)) return samples - def getSampleValueAt(self, index): - """Get the sample at the passed index and handle any SoundExceptions - - Parameters - ---------- - index : int - the desired index - - Returns - ------- - int - the sample value - """ - try: - value = self.getSampleValue(index) - except: - raise(IndexError("The index {} is not valid for this sound".format(index))) - return value - def getSampleValue(self, frameNum): + def getSampleValueAt(self, index): """Sets the value of the sample at the indicated frame If this is a mono sound, obtains the single sample contained @@ -282,7 +264,7 @@ def getSampleValue(self, frameNum): Parameters ---------- - frameNum : int + index : int the index of the frame to access Returns @@ -290,7 +272,7 @@ def getSampleValue(self, frameNum): int integer representation of the bytes contained within frame """ - n = frameNum * self.sampleWidth * self.numChannels + n = index * self.sampleWidth * self.numChannels m = n + self.sampleWidth return int.from_bytes(self.buffer[n:m], byteorder='little', signed=True) @@ -309,7 +291,7 @@ def getLeftSample(self, frameNum): """ if not self.isStereo(): print("Sound is not stereo, cannot access left value") - return self.getSampleValue(frameNum) + return self.getSampleValueAt(frameNum) def getRightSample(self, frameNum): """Obtains the right sample contained at the specified frame @@ -398,22 +380,8 @@ def setFrame(self, frameNum, frame): for i in range(self.sampleWidth): self.buffer[frameNum * self.sampleWidth + i] = frame[i] - def setSampleValueAt(self, index, value): - """Method to set the sample value at the specified index - Parameters - ---------- - index : int - the index - value : int or float - the new value - """ - try: - self.setSampleValue(index, int(value)) - except: - raise(IndexError("The index {} is not valid for this sound".format(index))) - - def setSampleValue(self, frameNum, value): + def setSampleValueAt(self, index, value): """Sets the value of the sample found at the specified frame If this sound has more than one channel, then we default to setting @@ -422,12 +390,12 @@ def setSampleValue(self, frameNum, value): Parameters ---------- - frameNum : int + index : int the index of the frame where the sample should be changed value : int the new sample value """ - n = frameNum * self.sampleWidth * self.numChannels + n = index * self.sampleWidth * self.numChannels m = n + self.sampleWidth value = max(min(value, self.MAX_POS), self.MAX_NEG) self.buffer[n:m] = value.to_bytes(self.sampleWidth, @@ -447,7 +415,7 @@ def setLeftSample(self, frameNum, value): if not self.isStereo(): print("Sound is not stereo, cannot set left value") else: - self.setSampleValue(frameNum, value) + self.setSampleValueAt(frameNum, value) def setRightSample(self, frameNum, value): """Set the right sample value in a stereo sample