Move stuff around
This commit is contained in:
parent
1ef6f01281
commit
55560f4f22
160
src/voc.rs
160
src/voc.rs
|
|
@ -160,16 +160,39 @@ impl VocFile {
|
|||
}
|
||||
}
|
||||
|
||||
type BlockT = Box<dyn Block>;
|
||||
|
||||
pub trait Block: std::fmt::Debug {
|
||||
fn to_bytes(&self) -> Vec<u8>;
|
||||
}
|
||||
|
||||
// Terminator
|
||||
|
||||
impl Block for Terminator {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
vec![self.block_type as u8]
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Terminator {
|
||||
block_type: BlockType,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Terminator {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Terminator")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Terminator {
|
||||
pub fn new() -> Self {
|
||||
Self { block_type: BlockType::Terminator }
|
||||
}
|
||||
}
|
||||
|
||||
// SoundData
|
||||
|
||||
impl Block for SoundData {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
let size_bytes: [u8; 4] = self.size.to_le_bytes();
|
||||
|
|
@ -190,78 +213,6 @@ impl Block for SoundData {
|
|||
}
|
||||
}
|
||||
|
||||
impl Block for SoundDataContinuation {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
let mut result: Vec<u8> = vec![self.block_type as u8];
|
||||
result.extend_from_slice(&self.data);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl Block for Silence {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
panic!("Not implemented");
|
||||
vec![self.block_type as u8]
|
||||
}
|
||||
}
|
||||
|
||||
impl Block for Marker {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
panic!("Not implemented");
|
||||
vec![self.block_type as u8]
|
||||
}
|
||||
}
|
||||
|
||||
impl Block for Text {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
let size_bytes: [u8; 4] = self.size.to_le_bytes();
|
||||
|
||||
let mut result: Vec<u8> = vec![
|
||||
self.block_type as u8,
|
||||
size_bytes[0],
|
||||
size_bytes[1],
|
||||
size_bytes[2],
|
||||
];
|
||||
|
||||
result.extend_from_slice(&self.data);
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl Block for RepeatStart {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
panic!("Not implemented");
|
||||
vec![self.block_type as u8]
|
||||
}
|
||||
}
|
||||
|
||||
impl Block for RepeatEnd {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
panic!("Not implemented");
|
||||
vec![self.block_type as u8]
|
||||
}
|
||||
}
|
||||
|
||||
type BlockT = Box<dyn Block>;
|
||||
|
||||
pub struct Terminator {
|
||||
block_type: BlockType,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Terminator {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Terminator")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Terminator {
|
||||
pub fn new() -> Self {
|
||||
Self { block_type: BlockType::Terminator }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SoundData {
|
||||
block_type: BlockType,
|
||||
pub size: i32,
|
||||
|
|
@ -292,6 +243,16 @@ impl SoundData {
|
|||
}
|
||||
}
|
||||
|
||||
// SoundDataContinuation
|
||||
|
||||
impl Block for SoundDataContinuation {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
let mut result: Vec<u8> = vec![self.block_type as u8];
|
||||
result.extend_from_slice(&self.data);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SoundDataContinuation {
|
||||
pub block_type: BlockType,
|
||||
pub size: i32,
|
||||
|
|
@ -316,6 +277,15 @@ impl SoundDataContinuation {
|
|||
}
|
||||
}
|
||||
|
||||
// Silence
|
||||
|
||||
impl Block for Silence {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
panic!("Not implemented");
|
||||
vec![self.block_type as u8]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Silence {
|
||||
pub block_type: BlockType,
|
||||
|
|
@ -324,6 +294,15 @@ pub struct Silence {
|
|||
pub length: i16,
|
||||
}
|
||||
|
||||
// Marker
|
||||
|
||||
impl Block for Marker {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
panic!("Not implemented");
|
||||
vec![self.block_type as u8]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Marker {
|
||||
block_type: BlockType,
|
||||
|
|
@ -331,6 +310,25 @@ pub struct Marker {
|
|||
value: i16,
|
||||
}
|
||||
|
||||
// Text
|
||||
|
||||
impl Block for Text {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
let size_bytes: [u8; 4] = self.size.to_le_bytes();
|
||||
|
||||
let mut result: Vec<u8> = vec![
|
||||
self.block_type as u8,
|
||||
size_bytes[0],
|
||||
size_bytes[1],
|
||||
size_bytes[2],
|
||||
];
|
||||
|
||||
result.extend_from_slice(&self.data);
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Text {
|
||||
pub block_type: BlockType,
|
||||
pub size: i32,
|
||||
|
|
@ -345,6 +343,15 @@ impl fmt::Debug for Text {
|
|||
}
|
||||
}
|
||||
|
||||
// RepeatStart
|
||||
|
||||
impl Block for RepeatStart {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
panic!("Not implemented");
|
||||
vec![self.block_type as u8]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RepeatStart {
|
||||
block_type: BlockType,
|
||||
|
|
@ -352,6 +359,15 @@ pub struct RepeatStart {
|
|||
repeat: i16,
|
||||
}
|
||||
|
||||
// RepeatEnd
|
||||
|
||||
impl Block for RepeatEnd {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
panic!("Not implemented");
|
||||
vec![self.block_type as u8]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RepeatEnd {
|
||||
block_type: BlockType,
|
||||
|
|
|
|||
Loading…
Reference in New Issue