Skip to content

Commit

Permalink
Add audio player
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-tsurko committed Nov 3, 2024
1 parent 0867630 commit 24be073
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 130 deletions.
15 changes: 12 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ log = "0.4"
midi-player = "0.2.1"
quick-xml = "0.31.0"
rfd = "0.14.0"
rodio = { version = "0.19", features = ["symphonia-all"] }
# it's git for now, because the version supporting aiff have not released yet
rodio = { git = "https://github.com/RustAudio/rodio.git", features = [
"symphonia-all",
"symphonia-aiff",
"symphonia-alac",
] }
rustpython-pylib = { version = "0.4.0", features = ["freeze-stdlib"] }
rustpython-stdlib = "0.4.0"
rustpython-vm = { version = "0.4.0", features = ["freeze-stdlib"] }
Expand Down
8 changes: 4 additions & 4 deletions doc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
- [Copying and Removing PathInstances](chapter03/04-copying-and-removing-pathinstances.md)
- [Editing PathInstances](chapter03/05-editing-pathinstances.md)
- [Tutorial 4: Creating and Editing Textures](chapter04/01-tutorial-4-creating-and-editing-textures.md)
- [Editing ParameterObjects](chapter04/010-editing-parameterobjects.md)
- [Editing Rhythm ParameterObjects](chapter04/011-editing-rhythm-parameterobjects.md)
- [Editing Instruments and Altering EventMode](chapter04/012-editing-instruments-and-altering-eventmode.md)
- [Displaying Texture Parameter Values](chapter04/013-displaying-texture-parameter-values.md)
- [Introduction to Textures and ParameterObjects](chapter04/02-introduction-to-textures-and-parameterobjects.md)
- [Introduction Instrument Models](chapter04/03-introduction-instrument-models.md)
- [Selecting and Viewing TextureModules](chapter04/04-selecting-and-viewing-texturemodules.md)
Expand All @@ -43,6 +39,10 @@
- [Editing TextureInstance Attributes](chapter04/07-editing-textureinstance-attributes.md)
- [Muting Textures](chapter04/08-muting-textures.md)
- [Viewing and Searching ParameterObjects](chapter04/09-viewing-and-searching-parameterobjects.md)
- [Editing ParameterObjects](chapter04/010-editing-parameterobjects.md)
- [Editing Rhythm ParameterObjects](chapter04/011-editing-rhythm-parameterobjects.md)
- [Editing Instruments and Altering EventMode](chapter04/012-editing-instruments-and-altering-eventmode.md)
- [Displaying Texture Parameter Values](chapter04/013-displaying-texture-parameter-values.md)
- [Tutorial 5: Textures and Paths](chapter05/01-tutorial-5-textures-and-paths.md)
- [Path Linking and Pitch Formation Redundancy](chapter05/02-path-linking-and-pitch-formation-redundancy.md)
- [Creating a Path With a Duration Fraction](chapter05/03-creating-a-path-with-a-duration-fraction.md)
Expand Down
48 changes: 21 additions & 27 deletions pysrc/athenaCL/libATH/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -6758,54 +6758,48 @@ def __init__(self, ao, args="", **keywords):
self.processSwitch = 1 # display only
self.gatherSwitch = 1 # display only
self.cmdStr = "ELh"
self.audioPath = None
self.midiPath = None

def gather(self):
outComplete = self.ao.aoInfo["outComplete"]
if outComplete == []:
return lang.msgELcreateFirst

self.fmtFound = []
msg = []

# all outputs that produce an audio file
self.audioPath = self.ao.aoInfo["fpAudio"]
if "csoundData" in outComplete or "csoundScore" in outComplete:
if os.path.isfile(self.audioPath): # if file found
self.fmtFound.append(self.audioPath)
audioPath = self.ao.aoInfo["fpAudio"]
if os.path.isfile(audioPath): # if file found
self.audioPath = audioPath
else: # files was created but does not exists
msg.append(lang.msgELaudioMoved % self.audioPath)
msg.append(lang.msgELaudioMoved % audioPath)

# only midi file produces an output
self.midPath = self.ao.aoInfo["fpMidi"]
if "midiFile" in outComplete:
if os.path.isfile(self.midPath): # if file found
self.fmtFound.append(self.midPath)
midiPath = self.ao.aoInfo["fpMidi"]
if os.path.isfile(midiPath): # if file found
self.midiPath = midiPath
else:
msg.append(lang.msgELaudioMoved % self.midPath)
if self.fmtFound == []:
msg.append(lang.msgELaudioMoved % midiPath)

if not self.midiPath and not self.audioPath:
return "".join(msg)

def process(self):
# this file render prep should be done after EMr
# if os.name == 'mac': # must check that fp is in found
# if self.audioPath in self.fmtFound:
# prefDict = self.ao.external.getPrefGroup('external')
# audioTools.setMacAudioRsrc(prefDict['audioFormat'],
# self.audioPath, prefDict)
if os.name == "posix":
pass
else: # win or other
pass
pass

def display(self):
msg = []
prefDict = self.ao.external.getPrefGroup("external")
for hPath in self.fmtFound: # audio path
failFlag = osTools.openMedia(hPath, prefDict)
if failFlag == "failed":
msg.append(lang.msgELhearError % hPath)
else:
msg.append(lang.msgELhearInit % hPath)
if self.audioPath:
dialogExt.playAudio(self.audioPath)
msg.append("EL hear (Audio) %s\n" % self.audioPath)

if self.midiPath:
dialogExt.playMidi(self.midiPath)
msg.append("EL hear (MIDI) %s\n" % self.midiPath)

return "".join(msg)


Expand Down
10 changes: 9 additions & 1 deletion src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use iced::widget::{
use iced::{time, Element, Font, Subscription, Task};
use rfd::FileDialog;

use super::player::{self, GlobalState as GlobalPlayerState, State as PlayerState};
use super::player::{self, GlobalState as GlobalPlayerState, Track as PlayerState};
use crate::interpreter;

const TERM_WIDTH: u16 = 80;
Expand Down Expand Up @@ -150,6 +150,14 @@ pub fn update(state: &mut State, message: Message) -> Task<Message> {
position: 0.0,
}));
}
interpreter::Message::LoadAudio(path) => {
state.output.push(Output::Player(PlayerState {
is_playing: false,
path: path.into(),
id: player::PlayerId::Audio(state.output.len()),
position: 0.0,
}));
}
interpreter::Message::ScratchDir(value) => {
state.scratch_dir = value;
}
Expand Down
Loading

0 comments on commit 24be073

Please sign in to comment.